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 ICustomFaculty(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(ICustomFaculty) |
---|
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 ICustomDepartment(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 | |
---|
129 | class CustomDepartment(Department): |
---|
130 | """A university department. |
---|
131 | """ |
---|
132 | grok.implements(ICustomDepartment) |
---|
133 | |
---|
134 | local_roles = [ |
---|
135 | 'waeup.local.ApplicationsManager', |
---|
136 | 'waeup.local.DepartmentOfficer', |
---|
137 | 'waeup.local.DepartmentManager', |
---|
138 | ] |
---|
139 | |
---|
140 | def __init__(self, |
---|
141 | title=u'Unnamed Department', |
---|
142 | title_prefix=u'department', |
---|
143 | address=None, |
---|
144 | email=None, |
---|
145 | code=u"NA", **kw): |
---|
146 | super(Department, self).__init__(**kw) |
---|
147 | self.title = title |
---|
148 | self.title_prefix = title_prefix |
---|
149 | self.code = code |
---|
150 | self.certificates = CertificatesContainer() |
---|
151 | self.certificates.__parent__ = self |
---|
152 | self.certificates.__name__ = 'certificates' |
---|
153 | self.score_editing_disabled = False |
---|
154 | self.address = address |
---|
155 | self.email = email |
---|
156 | |
---|
157 | class CustomDepartmentFactory(DepartmentFactory): |
---|
158 | """A factory for department containers. |
---|
159 | """ |
---|
160 | |
---|
161 | def __call__(self, *args, **kw): |
---|
162 | return CustomDepartment(*args, **kw) |
---|
163 | |
---|
164 | def getInterfaces(self): |
---|
165 | """Get interfaces of objects provided by this factory. |
---|
166 | """ |
---|
167 | return implementedBy(CustomDepartment) |
---|
168 | |
---|
169 | class CustomCertificate(Certificate): |
---|
170 | """A certificate. |
---|
171 | """ |
---|
172 | grok.implements(ICertificate) |
---|
173 | |
---|
174 | local_roles = [ |
---|
175 | 'waeup.local.DepartmentOfficer', |
---|
176 | ] |
---|
177 | |
---|
178 | class CustomCertificateFactory(CertificateFactory): |
---|
179 | """A factory for certificates. |
---|
180 | """ |
---|
181 | |
---|
182 | def __call__(self, *args, **kw): |
---|
183 | return CustomCertificate(*args, **kw) |
---|
184 | |
---|
185 | def getInterfaces(self): |
---|
186 | return implementedBy(CustomCertificate) |
---|