source: main/waeup.kofa/trunk/src/waeup/kofa/university/department.py @ 10634

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

Disable score editing on department manage page.

Add tests.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1## $Id: department.py 10634 2013-09-21 08:27:47Z 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"""University departments.
19"""
20import grok
21import zope.location.location
22from zope.component.interfaces import IFactory
23from zope.interface import implementedBy
24from zope.component import getUtility
25from waeup.kofa.university.faculty import longtitle
26from waeup.kofa.university.coursescontainer import CoursesContainer
27from waeup.kofa.university.certificatescontainer import CertificatesContainer
28from waeup.kofa.utils.batching import VirtualExportJobContainer
29from waeup.kofa.interfaces import IKofaUtils
30from waeup.kofa.utils.helpers import attrs_to_fields
31from waeup.kofa.university.interfaces import IDepartment, IDepartmentAdd
32
33class VirtualDepartmentExportJobContainer(VirtualExportJobContainer):
34    """A virtual export job container for departments.
35    """
36
37class Department(grok.Container):
38    """A university department.
39    """
40    grok.implements(IDepartment, IDepartmentAdd)
41
42    local_roles = [
43        'waeup.local.ApplicationsManager',
44        'waeup.local.DepartmentOfficer',
45        'waeup.local.DepartmentManager',
46        'waeup.local.ClearanceOfficer',
47        'waeup.local.UGClearanceOfficer',
48        'waeup.local.PGClearanceOfficer',
49        'waeup.local.CourseAdviser100',
50        'waeup.local.CourseAdviser200',
51        'waeup.local.CourseAdviser300',
52        'waeup.local.CourseAdviser400',
53        'waeup.local.CourseAdviser500',
54        'waeup.local.CourseAdviser600',
55        'waeup.local.CourseAdviser700',
56        'waeup.local.CourseAdviser800',
57        ]
58
59    def __init__(self,
60                 title=u'Unnamed Department',
61                 title_prefix=u'department',
62                 code=u"NA", **kw):
63        super(Department, self).__init__(**kw)
64        self.title = title
65        self.title_prefix = title_prefix
66        self.code = code
67        self.courses = CoursesContainer()
68        self.courses.__parent__ = self
69        self.courses.__name__ = 'courses'
70        self.certificates = CertificatesContainer()
71        self.certificates.__parent__ = self
72        self.certificates.__name__ = 'certificates'
73
74    def traverse(self, name):
75        """Deliver appropriate containers, if someone wants to go to courses
76        or departments.
77        """
78        if name == 'courses':
79            return self.courses
80        elif name == 'certificates':
81            return self.certificates
82        elif name == 'exports':
83            # create a virtual exports container and return it
84            container = VirtualDepartmentExportJobContainer()
85            zope.location.location.located(container, self, 'exports')
86            return container
87        return None
88
89    def longtitle(self):
90        return longtitle(self)
91
92# Set all attributes of Department required in IDepartment as field
93# properties. Doing this, we do not have to set initial attributes
94# ourselves and as a bonus we get free validation when an attribute is
95# set.
96Department = attrs_to_fields(Department)
97
98class DepartmentFactory(grok.GlobalUtility):
99    """A factory for department containers.
100    """
101    grok.implements(IFactory)
102    grok.name(u'waeup.Department')
103    title = u"Create a new department.",
104    description = u"This factory instantiates new department instances."
105
106    def __call__(self, *args, **kw):
107        return Department(*args, **kw)
108
109    def getInterfaces(self):
110        """Get interfaces of objects provided by this factory.
111        """
112        return implementedBy(Department)
Note: See TracBrowser for help on using the repository browser.