source: main/waeup.sirp/trunk/src/waeup/sirp/university/department.py @ 7177

Last change on this file since 7177 was 7137, checked in by Henrik Bettermann, 13 years ago

Set value Id for property svn:keywords in all Python files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1"""University departments.
2"""
3import grok
4from zope.component import createObject
5from zope.component.interfaces import IFactory
6from zope.interface import implementedBy
7from waeup.sirp.university.interfaces import IDepartment, IDepartmentAdd
8from waeup.sirp.university.vocabularies import inst_types
9
10class Department(grok.Container):
11    """A university department.
12    """
13    grok.implements(IDepartment, IDepartmentAdd)
14
15    @property       # Make this method read_only and looking like an attr.
16    def local_roles(cls):
17        return ['waeup.local.DepartmentOfficer',
18                'waeup.local.ClearanceOfficer',]
19
20    # A simple counter for ids.
21    next_id = 0L
22
23    def __init__(self,
24                 title=u'Unnamed Department',
25                 title_prefix=u'department',
26                 code=u"NA", **kw):
27        super(Department, self).__init__(**kw)
28        self.title = title
29        self.title_prefix = title_prefix
30        self.code = code
31        self.courses = createObject(u'waeup.CourseContainer')
32        self.courses.__parent__ = self
33        self.courses.__name__ = 'courses'
34        self.certificates = createObject(u'waeup.CertificateContainer')
35        self.certificates.__parent__ = self
36        self.certificates.__name__ = 'certificates'
37
38    def traverse(self, name):
39        """Deliver appropriate containers, if someone wants to go to courses
40        or departments.
41        """
42        if name == 'courses':
43            return self.courses
44        elif name == 'certificates':
45            return self.certificates
46        return None
47
48    def longtitle(self):
49        return "%s %s (%s)" % (
50            inst_types.getTerm(self.title_prefix).title,
51            self.title, self.code)
52
53
54class DepartmentFactory(grok.GlobalUtility):
55    """A factory for department containers.
56    """
57    grok.implements(IFactory)
58    grok.name(u'waeup.Department')
59    title = u"Create a new department.",
60    description = u"This factory instantiates new department instances."
61
62    def __call__(self, *args, **kw):
63        return Department(*args, **kw)
64
65    def getInterfaces(self):
66        """Get interfaces of objects provided by this factory.
67        """
68        return implementedBy(Department)
Note: See TracBrowser for help on using the repository browser.