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

Last change on this file since 17958 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
RevLine 
[7195]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##
[4789]18"""Faculty components.
19"""
20
[3526]21import grok
[12632]22import zope.location.location
[4789]23from zope.component.interfaces import IFactory
24from zope.interface import implementedBy
[7681]25from zope.component import getUtility
[14511]26from zope.schema import getFields
27from waeup.kofa.interfaces import IKofaUtils, IKofaPluggable
[12632]28from waeup.kofa.utils.batching import VirtualExportJobContainer
[7811]29from waeup.kofa.university.interfaces import (
[10684]30    IFaculty, IDepartment)
[3526]31
[10561]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
[12632]40class VirtualFacultyExportJobContainer(VirtualExportJobContainer):
41    """A virtual export job container for facultiess.
42    """
43
[4789]44class Faculty(grok.Container):
45    """A university faculty.
46    """
[10684]47    grok.implements(IFaculty)
[3526]48
[8993]49    local_roles = [
[10279]50        'waeup.local.DepartmentOfficer',
[8993]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',
[10064]61        'waeup.local.CourseAdviser700',
62        'waeup.local.CourseAdviser800',
[10639]63        'waeup.local.LocalStudentsManager',
64        'waeup.local.LocalWorkflowManager',
[15163]65        'waeup.local.TranscriptOfficer',
66        'waeup.local.TranscriptSignee',
[8993]67        ]
[6145]68
[4789]69    def __init__(self,
70                 title=u'Unnamed Faculty',
71                 title_prefix=u'faculty',
[14511]72                 code=u'NA',
73                 officer_1=None,
74                 officer_2=None,
75                 **kw):
[3526]76        super(Faculty, self).__init__(**kw)
[4789]77        self.title = title
78        self.title_prefix = title_prefix
79        self.code = code
[14511]80        self.officer_1 = officer_1
81        self.officer_2 = officer_2
[3526]82
[12632]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
[4789]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
[3526]99
[10650]100    @property
[5988]101    def longtitle(self):
[10561]102        return longtitle(self)
[6145]103
[4789]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)
[14511]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.