source: main/waeup.sirp/trunk/src/waeup/sirp/university/faculty.py @ 6940

Last change on this file since 6940 was 6811, checked in by uli, 13 years ago

Enable setting a clearance officer for a faculty.

  • Property svn:eol-style set to native
File size: 1.9 KB
RevLine 
[4789]1"""Faculty components.
2"""
3
[3526]4import grok
[4789]5from zope.component.interfaces import IFactory
6from zope.interface import implementedBy
[5953]7from waeup.sirp.university.interfaces import (
8    IFaculty, IFacultyAdd, IDepartment)
[6145]9from waeup.sirp.university.vocabularies import inst_types
[3526]10
[4789]11class Faculty(grok.Container):
12    """A university faculty.
13    """
[5953]14    grok.implements(IFaculty, IFacultyAdd)
[3526]15
[6145]16    @property       # Make this method read_only and looking like an attr.
17    def local_roles(cls):
[6811]18        return ['waeup.local.DepartmentOfficer',
19                'waeup.local.ClearanceOffice',]
[6145]20
[4789]21    def __init__(self,
22                 title=u'Unnamed Faculty',
23                 title_prefix=u'faculty',
24                 code=u'NA', **kw):
[3526]25        super(Faculty, self).__init__(**kw)
[4789]26        self.title = title
27        self.title_prefix = title_prefix
28        self.code = code
[3526]29
[4789]30    def addDepartment(self, department):
31        """Add a department to the faculty.
32        """
33        if not IDepartment.providedBy(department):
34            raise TypeError('Faculties contain only IDepartment instances')
35        self[department.code] = department
[3526]36
[4789]37    def clear(self):
38        """Remove all departments from faculty.
39        """
40        keys = self.keys()
41        for key in keys:
42            del self[key]
[3526]43
[5988]44    def longtitle(self):
[5994]45        try:
46            result = "%s %s (%s)" % (
47                inst_types.getTerm(
48                    self.title_prefix).title,
49                self.title, self.code)
50        except:
51            result = "%s (%s)" % (self.title, self.code)
52        return result
[6145]53
[4789]54class FacultyFactory(grok.GlobalUtility):
55    """A factory for faculty containers.
56    """
57    grok.implements(IFactory)
58    grok.name(u'waeup.Faculty')
59    title = u"Create a new faculty.",
60    description = u"This factory instantiates new faculty instances."
61
62    def __call__(self, *args, **kw):
63        return Faculty()
64
65    def getInterfaces(self):
66        return implementedBy(Faculty)
Note: See TracBrowser for help on using the repository browser.