source: main/waeup.kofa/trunk/src/waeup/kofa/university/faculty.py @ 10635

Last change on this file since 10635 was 10561, checked in by Henrik Bettermann, 11 years ago

If no prefix is selected do not prepend a whitespace.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1## $Id: faculty.py 10561 2013-08-29 15:11:14Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""Faculty components.
19"""
20
21import grok
22from zope.component.interfaces import IFactory
23from zope.interface import implementedBy
24from zope.component import getUtility
25from waeup.kofa.interfaces import IKofaUtils
26from waeup.kofa.university.interfaces import (
27    IFaculty, IFacultyAdd, IDepartment)
28
29def longtitle(inst):
30    insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT
31    if inst.title_prefix == 'none':
32        return "%s (%s)" % (inst.title, inst.code)
33    return "%s %s (%s)" % (
34        insttypes_dict[inst.title_prefix],
35        inst.title, inst.code)
36
37class Faculty(grok.Container):
38    """A university faculty.
39    """
40    grok.implements(IFaculty, IFacultyAdd)
41
42    local_roles = [
43        'waeup.local.DepartmentOfficer',
44        'waeup.local.DepartmentManager',
45        'waeup.local.ClearanceOfficer',
46        'waeup.local.UGClearanceOfficer',
47        'waeup.local.PGClearanceOfficer',
48        'waeup.local.CourseAdviser100',
49        'waeup.local.CourseAdviser200',
50        'waeup.local.CourseAdviser300',
51        'waeup.local.CourseAdviser400',
52        'waeup.local.CourseAdviser500',
53        'waeup.local.CourseAdviser600',
54        'waeup.local.CourseAdviser700',
55        'waeup.local.CourseAdviser800',
56        ]
57
58    def __init__(self,
59                 title=u'Unnamed Faculty',
60                 title_prefix=u'faculty',
61                 code=u'NA', **kw):
62        super(Faculty, self).__init__(**kw)
63        self.title = title
64        self.title_prefix = title_prefix
65        self.code = code
66
67    def addDepartment(self, department):
68        """Add a department to the faculty.
69        """
70        if not IDepartment.providedBy(department):
71            raise TypeError('Faculties contain only IDepartment instances')
72        self[department.code] = department
73
74    def longtitle(self):
75        return longtitle(self)
76
77class FacultyFactory(grok.GlobalUtility):
78    """A factory for faculty containers.
79    """
80    grok.implements(IFactory)
81    grok.name(u'waeup.Faculty')
82    title = u"Create a new faculty.",
83    description = u"This factory instantiates new faculty instances."
84
85    def __call__(self, *args, **kw):
86        return Faculty()
87
88    def getInterfaces(self):
89        return implementedBy(Faculty)
Note: See TracBrowser for help on using the repository browser.