source: main/waeup.sirp/branches/ulif-extimgstore/src/waeup/sirp/university/faculty.py @ 7033

Last change on this file since 7033 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
Line 
1"""Faculty components.
2"""
3
4import grok
5from zope.component.interfaces import IFactory
6from zope.interface import implementedBy
7from waeup.sirp.university.interfaces import (
8    IFaculty, IFacultyAdd, IDepartment)
9from waeup.sirp.university.vocabularies import inst_types
10
11class Faculty(grok.Container):
12    """A university faculty.
13    """
14    grok.implements(IFaculty, IFacultyAdd)
15
16    @property       # Make this method read_only and looking like an attr.
17    def local_roles(cls):
18        return ['waeup.local.DepartmentOfficer',
19                'waeup.local.ClearanceOffice',]
20
21    def __init__(self,
22                 title=u'Unnamed Faculty',
23                 title_prefix=u'faculty',
24                 code=u'NA', **kw):
25        super(Faculty, self).__init__(**kw)
26        self.title = title
27        self.title_prefix = title_prefix
28        self.code = code
29
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
36
37    def clear(self):
38        """Remove all departments from faculty.
39        """
40        keys = self.keys()
41        for key in keys:
42            del self[key]
43
44    def longtitle(self):
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
53
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.