1 | import grok |
---|
2 | from zope import schema |
---|
3 | from zope.interface import Attribute, invariant, Invalid |
---|
4 | from waeup.kofa.interfaces import (IKofaObject, IKofaContainer, validate_email) |
---|
5 | from waeup.kofa.university.interfaces import ICertificate |
---|
6 | from waeup.kofa.university.certificatescontainer import CertificatesContainer |
---|
7 | from waeup.kofa.university.faculty import ( |
---|
8 | Faculty, FacultyFactory) |
---|
9 | from waeup.kofa.university.department import ( |
---|
10 | Department, DepartmentFactory) |
---|
11 | from waeup.kofa.university.certificate import ( |
---|
12 | Certificate, CertificateFactory) |
---|
13 | from waeup.kofa.university.vocabularies import ( |
---|
14 | course_levels, |
---|
15 | CourseSource, |
---|
16 | StudyModeSource, |
---|
17 | AppCatSource, |
---|
18 | InstTypeSource, |
---|
19 | SemesterSource, |
---|
20 | ) |
---|
21 | |
---|
22 | |
---|
23 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
24 | |
---|
25 | |
---|
26 | class IFaculty(IKofaContainer): |
---|
27 | """Representation of a university faculty. |
---|
28 | """ |
---|
29 | |
---|
30 | code = schema.TextLine( |
---|
31 | title = _(u'Code'), |
---|
32 | default = u'NA', |
---|
33 | required = True, |
---|
34 | ) |
---|
35 | |
---|
36 | title = schema.TextLine( |
---|
37 | title = _(u'Name of faculty'), |
---|
38 | default = u'Unnamed', |
---|
39 | required = True, |
---|
40 | ) |
---|
41 | |
---|
42 | title_prefix = schema.Choice( |
---|
43 | title = _(u'Name prefix'), |
---|
44 | default = u'faculty', |
---|
45 | source = InstTypeSource(), |
---|
46 | required = True, |
---|
47 | ) |
---|
48 | |
---|
49 | address = schema.Text( |
---|
50 | title = _(u'Permanent Address'), |
---|
51 | required = False, |
---|
52 | ) |
---|
53 | |
---|
54 | email = schema.ASCIILine( |
---|
55 | title = _(u'Email'), |
---|
56 | required = False, |
---|
57 | constraint=validate_email, |
---|
58 | ) |
---|
59 | |
---|
60 | class CustomFaculty(Faculty): |
---|
61 | """A university faculty. |
---|
62 | """ |
---|
63 | grok.implements(IFaculty) |
---|
64 | |
---|
65 | local_roles = [ |
---|
66 | 'waeup.local.DepartmentOfficer', |
---|
67 | 'waeup.local.DepartmentManager', |
---|
68 | ] |
---|
69 | |
---|
70 | def __init__(self, |
---|
71 | title=u'Unnamed Faculty', |
---|
72 | title_prefix=u'faculty', |
---|
73 | address=None, |
---|
74 | email=None, |
---|
75 | code=u'NA', **kw): |
---|
76 | super(Faculty, self).__init__(**kw) |
---|
77 | self.title = title |
---|
78 | self.title_prefix = title_prefix |
---|
79 | self.code = code |
---|
80 | self.address = address |
---|
81 | self.email = email |
---|
82 | |
---|
83 | class CustomFacultyFactory(FacultyFactory): |
---|
84 | """A factory for faculty containers. |
---|
85 | """ |
---|
86 | |
---|
87 | def __call__(self, *args, **kw): |
---|
88 | return CustomFaculty() |
---|
89 | |
---|
90 | def getInterfaces(self): |
---|
91 | return implementedBy(CustomFaculty) |
---|
92 | |
---|
93 | class IDepartment(IKofaObject): |
---|
94 | """Representation of a department. |
---|
95 | """ |
---|
96 | code = schema.TextLine( |
---|
97 | title = _(u'Code'), |
---|
98 | default = u'NA', |
---|
99 | required = True, |
---|
100 | ) |
---|
101 | |
---|
102 | title = schema.TextLine( |
---|
103 | title = _(u'Name of department'), |
---|
104 | default = u'Unnamed', |
---|
105 | required = True, |
---|
106 | ) |
---|
107 | |
---|
108 | title_prefix = schema.Choice( |
---|
109 | title = _(u'Name prefix'), |
---|
110 | source = InstTypeSource(), |
---|
111 | default = u'department', |
---|
112 | required = True, |
---|
113 | ) |
---|
114 | |
---|
115 | address = schema.Text( |
---|
116 | title = _(u'Permanent Address'), |
---|
117 | required = False, |
---|
118 | ) |
---|
119 | |
---|
120 | email = schema.ASCIILine( |
---|
121 | title = _(u'Email'), |
---|
122 | required = False, |
---|
123 | constraint=validate_email, |
---|
124 | ) |
---|
125 | |
---|
126 | certificates = Attribute("A container for certificates.") |
---|
127 | |
---|
128 | class CustomDepartment(Department): |
---|
129 | """A university department. |
---|
130 | """ |
---|
131 | grok.implements(IDepartment) |
---|
132 | |
---|
133 | local_roles = [ |
---|
134 | 'waeup.local.ApplicationsManager', |
---|
135 | 'waeup.local.DepartmentOfficer', |
---|
136 | 'waeup.local.DepartmentManager', |
---|
137 | ] |
---|
138 | |
---|
139 | def __init__(self, |
---|
140 | title=u'Unnamed Department', |
---|
141 | title_prefix=u'department', |
---|
142 | address=None, |
---|
143 | email=None, |
---|
144 | code=u"NA", **kw): |
---|
145 | super(Department, self).__init__(**kw) |
---|
146 | self.title = title |
---|
147 | self.title_prefix = title_prefix |
---|
148 | self.code = code |
---|
149 | self.certificates = CertificatesContainer() |
---|
150 | self.certificates.__parent__ = self |
---|
151 | self.certificates.__name__ = 'certificates' |
---|
152 | self.score_editing_disabled = False |
---|
153 | self.address = address |
---|
154 | self.email = email |
---|
155 | |
---|
156 | class CustomDepartmentFactory(DepartmentFactory): |
---|
157 | """A factory for department containers. |
---|
158 | """ |
---|
159 | |
---|
160 | def __call__(self, *args, **kw): |
---|
161 | return CustomDepartment(*args, **kw) |
---|
162 | |
---|
163 | def getInterfaces(self): |
---|
164 | """Get interfaces of objects provided by this factory. |
---|
165 | """ |
---|
166 | return implementedBy(CustomDepartment) |
---|
167 | |
---|
168 | class CustomCertificate(Certificate): |
---|
169 | """A certificate. |
---|
170 | """ |
---|
171 | grok.implements(ICertificate) |
---|
172 | |
---|
173 | local_roles = [ |
---|
174 | 'waeup.local.DepartmentOfficer', |
---|
175 | ] |
---|
176 | |
---|
177 | class CustomCertificateFactory(CertificateFactory): |
---|
178 | """A factory for certificates. |
---|
179 | """ |
---|
180 | |
---|
181 | def __call__(self, *args, **kw): |
---|
182 | return CustomCertificate(*args, **kw) |
---|
183 | |
---|
184 | def getInterfaces(self): |
---|
185 | return implementedBy(CustomCertificate) |
---|