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

Last change on this file since 6125 was 6125, checked in by Henrik Bettermann, 13 years ago
  • Add Faculty class attribute local_roles which is a list of local role dictionaries. These are local roles allowed in the Faculty context.
  • Property svn:eol-style set to native
File size: 1.8 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
11local_roles = [
12    {'name':'waeup.local.DepartmentOfficer','title':'Department Officer'},
13    ]
14
15class Faculty(grok.Container):
16    """A university faculty.
17    """
18    grok.implements(IFaculty, IFacultyAdd)
19
20    def __init__(self,
21                 title=u'Unnamed Faculty',
22                 title_prefix=u'faculty',
23                 code=u'NA', **kw):
24        super(Faculty, self).__init__(**kw)
25        self.title = title
26        self.title_prefix = title_prefix
27        self.code = code
28
29    def addDepartment(self, department):
30        """Add a department to the faculty.
31        """
32        if not IDepartment.providedBy(department):
33            raise TypeError('Faculties contain only IDepartment instances')
34        self[department.code] = department
35
36    def clear(self):
37        """Remove all departments from faculty.
38        """
39        keys = self.keys()
40        for key in keys:
41            del self[key]
42
43    def longtitle(self):
44        try:
45            result = "%s %s (%s)" % (
46                inst_types.getTerm(
47                    self.title_prefix).title,
48                self.title, self.code)
49        except:
50            result = "%s (%s)" % (self.title, self.code)
51        return result
52       
53class FacultyFactory(grok.GlobalUtility):
54    """A factory for faculty containers.
55    """
56    grok.implements(IFactory)
57    grok.name(u'waeup.Faculty')
58    title = u"Create a new faculty.",
59    description = u"This factory instantiates new faculty instances."
60
61    def __call__(self, *args, **kw):
62        return Faculty()
63
64    def getInterfaces(self):
65        return implementedBy(Faculty)
Note: See TracBrowser for help on using the repository browser.