source: main/waeup.kofa/branches/uli-async-update/src/waeup/kofa/university/department.py @ 10322

Last change on this file since 10322 was 9169, checked in by uli, 12 years ago

Merge changes from trunk, r8786-HEAD

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1## $Id: department.py 9169 2012-09-10 11:05:07Z uli $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""University departments.
19"""
20import grok
21from zope.component.interfaces import IFactory
22from zope.interface import implementedBy
23from zope.component import getUtility
24from waeup.kofa.university.coursescontainer import CoursesContainer
25from waeup.kofa.university.certificatescontainer import CertificatesContainer
26from waeup.kofa.interfaces import IKofaUtils
27from waeup.kofa.university.interfaces import IDepartment, IDepartmentAdd
28
29class Department(grok.Container):
30    """A university department.
31    """
32    grok.implements(IDepartment, IDepartmentAdd)
33
34    local_roles = [
35        'waeup.local.DepartmentManager',
36        'waeup.local.ClearanceOfficer',
37        'waeup.local.UGClearanceOfficer',
38        'waeup.local.PGClearanceOfficer',
39        'waeup.local.CourseAdviser100',
40        'waeup.local.CourseAdviser200',
41        'waeup.local.CourseAdviser300',
42        'waeup.local.CourseAdviser400',
43        'waeup.local.CourseAdviser500',
44        'waeup.local.CourseAdviser600',
45        ]
46
47    # A simple counter for ids.
48    next_id = 0L
49
50    def __init__(self,
51                 title=u'Unnamed Department',
52                 title_prefix=u'department',
53                 code=u"NA", **kw):
54        super(Department, self).__init__(**kw)
55        self.title = title
56        self.title_prefix = title_prefix
57        self.code = code
58        self.courses = CoursesContainer()
59        self.courses.__parent__ = self
60        self.courses.__name__ = 'courses'
61        self.certificates = CertificatesContainer()
62        self.certificates.__parent__ = self
63        self.certificates.__name__ = 'certificates'
64
65    def traverse(self, name):
66        """Deliver appropriate containers, if someone wants to go to courses
67        or departments.
68        """
69        if name == 'courses':
70            return self.courses
71        elif name == 'certificates':
72            return self.certificates
73        return None
74
75    def longtitle(self):
76        insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT
77        return "%s %s (%s)" % (
78            insttypes_dict[self.title_prefix],
79            self.title, self.code)
80
81
82class DepartmentFactory(grok.GlobalUtility):
83    """A factory for department containers.
84    """
85    grok.implements(IFactory)
86    grok.name(u'waeup.Department')
87    title = u"Create a new department.",
88    description = u"This factory instantiates new department instances."
89
90    def __call__(self, *args, **kw):
91        return Department(*args, **kw)
92
93    def getInterfaces(self):
94        """Get interfaces of objects provided by this factory.
95        """
96        return implementedBy(Department)
Note: See TracBrowser for help on using the repository browser.