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

Last change on this file since 15189 was 15163, checked in by Henrik Bettermann, 6 years ago

Merge with /main/waeup.kofa/branches/henrik-transcript-workflow:15127-15162

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.9 KB
Line 
1## $Id: faculty.py 15163 2018-09-23 05:05:04Z 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        'waeup.local.TranscriptOfficer',
66        'waeup.local.TranscriptSignee',
67        ]
68
69    def __init__(self,
70                 title=u'Unnamed Faculty',
71                 title_prefix=u'faculty',
72                 code=u'NA',
73                 officer_1=None,
74                 officer_2=None,
75                 **kw):
76        super(Faculty, self).__init__(**kw)
77        self.title = title
78        self.title_prefix = title_prefix
79        self.code = code
80        self.officer_1 = officer_1
81        self.officer_2 = officer_2
82
83    def traverse(self, name):
84        """Deliver appropriate containers.
85        """
86        if name == 'exports':
87            # create a virtual exports container and return it
88            container = VirtualFacultyExportJobContainer()
89            zope.location.location.located(container, self, 'exports')
90            return container
91        return None
92
93    def addDepartment(self, department):
94        """Add a department to the faculty.
95        """
96        if not IDepartment.providedBy(department):
97            raise TypeError('Faculties contain only IDepartment instances')
98        self[department.code] = department
99
100    @property
101    def longtitle(self):
102        return longtitle(self)
103
104class FacultyFactory(grok.GlobalUtility):
105    """A factory for faculty containers.
106    """
107    grok.implements(IFactory)
108    grok.name(u'waeup.Faculty')
109    title = u"Create a new faculty.",
110    description = u"This factory instantiates new faculty instances."
111
112    def __call__(self, *args, **kw):
113        return Faculty()
114
115    def getInterfaces(self):
116        return implementedBy(Faculty)
117
118class FacultiesPlugin(grok.GlobalUtility):
119    """A plugin that updates faculties.
120    """
121
122    grok.implements(IKofaPluggable)
123    grok.name('faculties')
124
125    deprecated_attributes = []
126
127    def setup(self, site, name, logger):
128        return
129
130    def update(self, site, name, logger):
131        items = getFields(IFaculty).items()
132        for faculty in site['faculties'].values():
133             # Add new attributes
134            for i in items:
135                if not hasattr(faculty,i[0]):
136                    setattr(faculty,i[0],i[1].missing_value)
137                    logger.info(
138                        'FacultiesPlugin: %s attribute %s added.' % (
139                        faculty.code,i[0]))
140            # Remove deprecated attributes
141            for i in self.deprecated_attributes:
142                try:
143                    delattr(faculty,i)
144                    logger.info(
145                        'FacultiesPlugin: %s attribute %s deleted.' % (
146                        faculty.code,i))
147                except AttributeError:
148                    pass
149        return
Note: See TracBrowser for help on using the repository browser.