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
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)
[5988]9from waeup.sirp.university.vocabularies import inst_types   
[3526]10
[6125]11local_roles = [
12    {'name':'waeup.local.DepartmentOfficer','title':'Department Officer'},
13    ]
14
[4789]15class Faculty(grok.Container):
16    """A university faculty.
17    """
[5953]18    grok.implements(IFaculty, IFacultyAdd)
[3526]19
[4789]20    def __init__(self,
21                 title=u'Unnamed Faculty',
22                 title_prefix=u'faculty',
23                 code=u'NA', **kw):
[3526]24        super(Faculty, self).__init__(**kw)
[4789]25        self.title = title
26        self.title_prefix = title_prefix
27        self.code = code
[3526]28
[4789]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
[3526]35
[4789]36    def clear(self):
37        """Remove all departments from faculty.
38        """
39        keys = self.keys()
40        for key in keys:
41            del self[key]
[3526]42
[5988]43    def longtitle(self):
[5994]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
[4789]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.