source: main/waeup.sirp/trunk/src/waeup/sirp/university/interfaces.py @ 5952

Last change on this file since 5952 was 5951, checked in by Henrik Bettermann, 14 years ago

Implement 'Add' interfaces for Faculties, Departments, Courses and Certificates. The add methods are broken for the views which use these interfaces for form field generation. I don't know why.

File size: 7.2 KB
Line 
1"""Interfaces of academics specific objects.
2"""
3from zc.sourcefactory.basic import BasicSourceFactory
4from zope import schema
5try:
6    from zope.catalog.interfaces import ICatalog
7except ImportError:
8    # BBB
9    from zope.app.catalog.interfaces import ICatalog
10from zope.component import getUtility
11from zope.interface import Attribute
12from waeup.sirp.interfaces import (IWAeUPObject, IWAeUPContainer,
13                                   SimpleWAeUPVocabulary)
14
15class CourseSource(BasicSourceFactory):
16    """A course source delivers all courses inside the portal by looking
17       up a catalog.
18    """
19    def getValues(self):
20        catalog = getUtility(ICatalog, name='courses_catalog')
21        return list(catalog.searchResults(code=('', 'z*')))
22
23    def getToken(self, value):
24        return value.code
25       
26    def getTitle(self, value):
27        return "%s - %s" % (value.code, value.title[:64])
28
29class IFaculty(IWAeUPContainer):
30    """Representation of a university faculty.
31    """
32    code = schema.TextLine(
33        title = u'Code',
34        description = u'Abbreviated code of the faculty',
35        default = u'NA',
36        required = True,
37        readonly = True,
38        )
39
40    title = schema.TextLine(
41        title = u'Name of Faculty',
42        default = u'Unnamed',
43        required = True,
44        )
45
46    title_prefix = schema.TextLine(
47        title = u'Title prefix',
48        default = u'faculty',
49        required = True,
50        )
51       
52class IFacultyAdd(IFaculty):
53    """Representation of a university faculty.
54    """
55    code = schema.TextLine(
56        title = u'Code',
57        description = u'Abbreviated code of the faculty',
58        default = u'NA',
59        required = True,
60        readonly = False,
61        )
62                 
63IFacultyAdd['code'].order =  IFaculty['code'].order           
64   
65class IFacultyContainer(IWAeUPContainer):
66    """A container for faculties.
67    """
68    def addFaculty(faculty):
69        """Add an IFactulty object.
70
71        Returns the key, under which the object was stored.
72        """
73class IDepartment(IWAeUPObject):
74    """Representation of a department.
75    """
76    code = schema.TextLine(
77        title = u'Code',
78        default = u'NA',
79        description = u'Abbreviated code of the department',
80        required = True,
81        readonly = True,
82        )
83
84    title = schema.TextLine(
85        title = u'Name of Department',
86        default = u'Unnamed',
87        required = True,
88        )
89
90    title_prefix = schema.TextLine(
91        title = u'Title prefix',
92        default = u'department',
93        required = True,
94        )
95
96    courses = Attribute("A container for courses.")
97    certificates = Attribute("A container for certificates.")
98
99class IDepartmentAdd(IDepartment):
100    """Representation of a university department.
101    """
102    code = schema.TextLine(
103        title = u'Code',
104        default = u'NA',
105        description = u'Abbreviated code of the department',
106        required = True,
107        readonly = False,
108        )
109                 
110IDepartmentAdd['code'].order =  IDepartment['code'].order         
111
112class ICourseContainer(IWAeUPContainer):
113    """A container for faculties.
114    """
115    def addCourse(faculty):
116        """Add an ICourse object.
117
118        Returns the key, under which the object was stored.
119        """
120
121class ICourse(IWAeUPObject):
122    """Representation of a course.
123    """
124    code = schema.TextLine(
125        title = u'Code',
126        default = u'NA',
127        description = u'Abbreviated code of the course',
128        required = True,
129        readonly = True,
130        )
131
132    title = schema.TextLine(
133        title = u'Title of course',
134        default = u'Unnamed',
135        required = True,
136        )
137
138    credits = schema.Int(
139        title = u'Credits',
140        default = 0,
141        required = False,
142        )
143   
144    passmark = schema.Int(
145        title = u'Passmark',
146        default = 40,
147        required = False,
148        )
149
150    semester = schema.Choice(
151        title = u'Semester/Term',
152        default = 0,
153        vocabulary = SimpleWAeUPVocabulary(
154            ('N/A', 0), ('First Semester', 1),
155            ('Second Semester', 2), ('Combined', 3)),
156        required = True,
157        )
158
159class ICourseAdd(ICourse):
160    """Representation of a course.
161    """
162    code = schema.TextLine(
163        title = u'Code',
164        default = u'NA',
165        description = u'Abbreviated code of the course',
166        required = True,
167        readonly = False,
168        )
169       
170ICourseAdd['code'].order =  ICourse['code'].order         
171
172class ICertificate(IWAeUPObject):
173    """Representation of a certificate.
174    """
175    code = schema.TextLine(
176        title = u'Code',
177        default = u'NA',
178        description = u'Abbreviated code of the certificate.',
179        required = True,
180        readonly = True,
181        )
182
183    #review_state = schema.Choice(
184    #    title = u'Review State',
185    #    default = 'unchecked',
186    #    values = ['unchecked', 'checked']
187    #    )
188
189    title = schema.TextLine(
190        title = u'Title',
191        default = u'Unnamed',
192        required = True,
193        )
194
195    study_mode = schema.TextLine(
196        title = u'Study Mode',
197        default = u'ug_ft',
198        required = True,
199        )
200
201    start_level = schema.TextLine(
202        title = u'Start Level',
203        default = u'100',
204        required = True,
205        )
206   
207    end_level = schema.TextLine(
208        title = u'End Level',
209        default = u'500',
210        required = True,
211        )
212   
213    application_category = schema.TextLine(
214        title = u'Application Category',
215        default = u'basic',
216        required = False,
217        )   
218
219class ICertificateAdd(ICertificate):
220    """Representation of a certificate.
221    """
222    code = schema.TextLine(
223        title = u'Code',
224        default = u'NA',
225        description = u'Abbreviated code of the certificate.',
226        required = True,
227        readonly = False,
228        )
229       
230ICertificateAdd['code'].order =  ICertificate['code'].order         
231   
232class ICertificateContainer(IWAeUPContainer):
233    """A container for certificates.
234    """
235    def addCertificate(faculty):
236        """Add an ICertificate object.
237
238        Returns the key, under which the object was stored.
239        """
240
241class ICertificateCourse(IWAeUPObject):
242    """A certificatecourse is a course referenced by a certificate, which
243       provides some own attributes.
244    """
245    course = schema.Choice(
246        title = u'Course referenced',
247        source = CourseSource(),
248        readonly = True,
249        )
250   
251    level = schema.Int(
252        title = u'Level',
253        required = True,
254        default = 100,
255        readonly = False,
256        )
257
258    core_or_elective = schema.Bool(
259        title = u'Is mandatory course (not elective)',
260        required = True,
261        default = True,
262        )
263
264    def getCourseCode():
265        """Return the code of the referenced course.
266
267        This is needed for cataloging.
268        """
269       
270       
271class ICertificateCourseAdd(ICertificateCourse):
272    """A certificatecourse is a course referenced by a certificate, which
273       provides some own attributes.
274    """
275    course = schema.Choice(
276        title = u'Course to be referenced',
277        source = CourseSource(),
278        readonly = False,
279        )
280                 
281ICertificateCourseAdd['course'].order =  ICertificateCourse['course'].order                 
Note: See TracBrowser for help on using the repository browser.