source: main/waeup.kofa/branches/uli-rm-bootstrap/src/waeup/kofa/university/faculty.py @ 17942

Last change on this file since 17942 was 14511, checked in by Henrik Bettermann, 8 years ago

Add officer name fields do IDepartment and IFaculty. Plugins must be updated!

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.8 KB
Line 
1## $Id: faculty.py 14511 2017-02-07 08:33:05Z 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
22import zope.location.location
23from zope.component.interfaces import IFactory
24from zope.interface import implementedBy
25from zope.component import getUtility
26from zope.schema import getFields
27from waeup.kofa.interfaces import IKofaUtils, IKofaPluggable
28from waeup.kofa.utils.batching import VirtualExportJobContainer
29from waeup.kofa.university.interfaces import (
30    IFaculty, IDepartment)
31
32def longtitle(inst):
33    insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT
34    if inst.title_prefix == 'none':
35        return "%s (%s)" % (inst.title, inst.code)
36    return "%s %s (%s)" % (
37        insttypes_dict[inst.title_prefix],
38        inst.title, inst.code)
39
40class VirtualFacultyExportJobContainer(VirtualExportJobContainer):
41    """A virtual export job container for facultiess.
42    """
43
44class Faculty(grok.Container):
45    """A university faculty.
46    """
47    grok.implements(IFaculty)
48
49    local_roles = [
50        'waeup.local.DepartmentOfficer',
51        'waeup.local.DepartmentManager',
52        'waeup.local.ClearanceOfficer',
53        'waeup.local.UGClearanceOfficer',
54        'waeup.local.PGClearanceOfficer',
55        'waeup.local.CourseAdviser100',
56        'waeup.local.CourseAdviser200',
57        'waeup.local.CourseAdviser300',
58        'waeup.local.CourseAdviser400',
59        'waeup.local.CourseAdviser500',
60        'waeup.local.CourseAdviser600',
61        'waeup.local.CourseAdviser700',
62        'waeup.local.CourseAdviser800',
63        'waeup.local.LocalStudentsManager',
64        'waeup.local.LocalWorkflowManager',
65        ]
66
67    def __init__(self,
68                 title=u'Unnamed Faculty',
69                 title_prefix=u'faculty',
70                 code=u'NA',
71                 officer_1=None,
72                 officer_2=None,
73                 **kw):
74        super(Faculty, self).__init__(**kw)
75        self.title = title
76        self.title_prefix = title_prefix
77        self.code = code
78        self.officer_1 = officer_1
79        self.officer_2 = officer_2
80
81    def traverse(self, name):
82        """Deliver appropriate containers.
83        """
84        if name == 'exports':
85            # create a virtual exports container and return it
86            container = VirtualFacultyExportJobContainer()
87            zope.location.location.located(container, self, 'exports')
88            return container
89        return None
90
91    def addDepartment(self, department):
92        """Add a department to the faculty.
93        """
94        if not IDepartment.providedBy(department):
95            raise TypeError('Faculties contain only IDepartment instances')
96        self[department.code] = department
97
98    @property
99    def longtitle(self):
100        return longtitle(self)
101
102class FacultyFactory(grok.GlobalUtility):
103    """A factory for faculty containers.
104    """
105    grok.implements(IFactory)
106    grok.name(u'waeup.Faculty')
107    title = u"Create a new faculty.",
108    description = u"This factory instantiates new faculty instances."
109
110    def __call__(self, *args, **kw):
111        return Faculty()
112
113    def getInterfaces(self):
114        return implementedBy(Faculty)
115
116class FacultiesPlugin(grok.GlobalUtility):
117    """A plugin that updates faculties.
118    """
119
120    grok.implements(IKofaPluggable)
121    grok.name('faculties')
122
123    deprecated_attributes = []
124
125    def setup(self, site, name, logger):
126        return
127
128    def update(self, site, name, logger):
129        items = getFields(IFaculty).items()
130        for faculty in site['faculties'].values():
131             # Add new attributes
132            for i in items:
133                if not hasattr(faculty,i[0]):
134                    setattr(faculty,i[0],i[1].missing_value)
135                    logger.info(
136                        'FacultiesPlugin: %s attribute %s added.' % (
137                        faculty.code,i[0]))
138            # Remove deprecated attributes
139            for i in self.deprecated_attributes:
140                try:
141                    delattr(faculty,i)
142                    logger.info(
143                        'FacultiesPlugin: %s attribute %s deleted.' % (
144                        faculty.code,i))
145                except AttributeError:
146                    pass
147        return
Note: See TracBrowser for help on using the repository browser.