source: main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py @ 9110

Last change on this file since 9110 was 9035, checked in by Henrik Bettermann, 12 years ago

Some boolean values must not be required.

  • Property svn:keywords set to Id
File size: 15.0 KB
Line 
1## $Id: interfaces.py 9035 2012-07-21 09:39:06Z 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#from datetime import datetime
19from zope.component import getUtility
20from zope.interface import Attribute, Interface
21from zope import schema
22from zc.sourcefactory.contextual import BasicContextualSourceFactory
23from waeup.kofa.interfaces import (
24    IKofaObject, academic_sessions_vocab, validate_email, ICSVExporter)
25from waeup.kofa.interfaces import MessageFactory as _
26from waeup.kofa.schema import TextLineChoice, FormattedDate, PhoneNumber
27from waeup.kofa.students.vocabularies import (
28    StudyLevelSource, contextual_reg_num_source, contextual_mat_num_source,
29    GenderSource, nats_vocab,
30    )
31from waeup.kofa.payments.interfaces import (
32    IPaymentsContainer, IOnlinePayment)
33from waeup.kofa.university.vocabularies import (
34    CourseSource, StudyModeSource, CertificateSource)
35
36# VerdictSource can't be placed into the vocabularies module because it
37# requires importing IStudentsUtils which then leads to circular imports.
38class VerdictSource(BasicContextualSourceFactory):
39    """A verdicts source delivers all verdicts provided
40    in the portal.
41    """
42    def getValues(self, context):
43        verdicts_dict = getUtility(IStudentsUtils).VERDICTS_DICT
44        return sorted(verdicts_dict.keys())
45
46    def getToken(self, context, value):
47        return value
48
49    def getTitle(self, context, value):
50        verdicts_dict = getUtility(IStudentsUtils).VERDICTS_DICT
51        if value != '0':
52            return verdicts_dict[value] + ' (%s)' % value
53        return verdicts_dict[value]
54
55
56class IStudentsUtils(Interface):
57    """A collection of methods which are subject to customization.
58
59    """
60    def setReturningData(student):
61        """ This method defines what happens after school fee payment
62        depending on the student's senate verdict.
63
64        In the base configuration current level is always increased
65        by 100 no matter which verdict has been assigned.
66        """
67
68    def setPaymentDetails(category, student):
69        """Create Payment object and set the payment data of a student for
70        the payment category specified.
71
72        """
73
74    def getAccommodation_details(student):
75        """Determine the accommodation dates of a student.
76
77        """
78
79    def selectBed(available_beds):
80        """Select a bed from a list of available beds.
81
82        In the standard configuration we select the first bed found,
83        but can also randomize the selection if we like.
84        """
85
86    def renderPDF(view, subject='', filename='slip.pdf',):
87        """Render pdf slips for various pages.
88
89        """
90
91class IStudentsContainer(IKofaObject):
92    """A students container contains university students.
93
94    """
95    def addStudent(student):
96        """Add an IStudent object and subcontainers.
97
98        """
99
100    def archive(id=None):
101        """Create on-dist archive of students.
102
103        If id is `None`, all students are archived.
104
105        If id contains a single id string, only the respective
106        students are archived.
107
108        If id contains a list of id strings all of the respective
109        students types are saved to disk.
110        """
111
112    def clear(id=None, archive=True):
113        """Remove students of type given by 'id'.
114
115        Optionally archive the students.
116
117        If id is `None`, all students are archived.
118
119        If id contains a single id string, only the respective
120        students are archived.
121
122        If id contains a list of id strings all of the respective
123        student types are saved to disk.
124
125        If `archive` is ``False`` none of the archive-handling is done
126        and respective students are simply removed from the
127        database.
128        """
129
130    unique_student_id = Attribute("""A unique student id.""")
131
132class IStudentNavigation(IKofaObject):
133    """Interface needed for student navigation, logging, etc.
134
135    """
136    student = Attribute('Student object of context.')
137
138    def writeLogMessage(view, message):
139        """Write a view specific log message into students.log.
140
141        """
142
143class IStudentBase(IKofaObject):
144    """Representation of student base data.
145
146    """
147    history = Attribute('Object history, a list of messages')
148    state = Attribute('Returns the registration state of a student')
149    password = Attribute('Encrypted password of a student')
150    certcode = Attribute('The certificate code of any chosen study course')
151    depcode = Attribute('The department code of any chosen study course')
152    faccode = Attribute('The faculty code of any chosen study course')
153    current_session = Attribute('The current session of the student')
154    current_mode = Attribute('The current mode of the student')
155    fullname = Attribute('All name parts separated by hyphens')
156    display_fullname = Attribute('The fullname of an applicant')
157    is_postgrad = Attribute('True if postgraduate student')
158
159    suspended = schema.Bool(
160        title = _(u'Account suspended'),
161        default = False,
162        required = False,
163        )
164
165    student_id = schema.TextLine(
166        title = _(u'Student Id'),
167        required = False,
168        )
169
170    firstname = schema.TextLine(
171        title = _(u'First Name'),
172        required = True,
173        )
174
175    middlename = schema.TextLine(
176        title = _(u'Middle Name'),
177        required = False,
178        )
179
180    lastname = schema.TextLine(
181        title = _(u'Last Name (Surname)'),
182        required = True,
183        )
184
185    sex = schema.Choice(
186        title = _(u'Sex'),
187        source = GenderSource(),
188        required = True,
189        )
190
191    reg_number = TextLineChoice(
192        title = _(u'Registration Number'),
193        required = True,
194        readonly = False,
195        source = contextual_reg_num_source,
196        )
197
198    matric_number = TextLineChoice(
199        title = _(u'Matriculation Number'),
200        required = False,
201        readonly = False,
202        source = contextual_mat_num_source,
203        )
204
205    adm_code = schema.TextLine(
206        title = _(u'PWD Activation Code'),
207        required = False,
208        readonly = False,
209        )
210
211    email = schema.ASCIILine(
212        title = _(u'Email'),
213        required = False,
214        constraint=validate_email,
215        )
216    phone = PhoneNumber(
217        title = _(u'Phone'),
218        description = u'',
219        required = False,
220        )
221
222class IUGStudentClearance(IKofaObject):
223    """Representation of undergraduate student clearance data.
224
225    """
226    date_of_birth = FormattedDate(
227        title = _(u'Date of Birth'),
228        required = True,
229        show_year = True,
230        )
231
232    clearance_locked = schema.Bool(
233        title = _(u'Clearance form locked'),
234        default = False,
235        required = False,
236        )
237
238    clr_code = schema.TextLine(
239        title = _(u'CLR Activation Code'),
240        required = False,
241        readonly = False,
242        )
243
244    nationality = schema.Choice(
245        vocabulary = nats_vocab,
246        title = _(u'Nationality'),
247        required = False,
248        )
249
250class IPGStudentClearance(IUGStudentClearance):
251    """Representation of postgraduate student clearance data.
252
253    """
254    employer = schema.TextLine(
255        title = _(u'Employer'),
256        required = False,
257        readonly = False,
258        )
259
260class IStudentPersonal(IKofaObject):
261    """Representation of student personal data.
262
263    """
264    perm_address = schema.Text(
265        title = _(u'Permanent Address'),
266        required = False,
267        )
268
269class IStudent(IStudentBase,IUGStudentClearance,IPGStudentClearance,
270    IStudentPersonal):
271    """Representation of a student.
272
273    """
274
275class IStudentUpdateByRegNo(IStudent):
276    """Representation of a student. Skip regular reg_number validation.
277
278    """
279    reg_number = schema.TextLine(
280        title = _(u'Registration Number'),
281        required = False,
282        )
283
284class IStudentUpdateByMatricNo(IStudent):
285    """Representation of a student. Skip regular matric_number validation.
286
287    """
288    matric_number = schema.TextLine(
289        title = _(u'Matriculation Number'),
290        required = False,
291        )
292
293class IStudentRequestPW(IStudent):
294    """Representation of an student for first-time password request.
295
296    This interface is used when students use the requestpw page to
297    login for the the first time.
298    """
299    number = schema.TextLine(
300        title = _(u'Registr. or Matric. Number'),
301        required = True,
302        )
303
304    firstname = schema.TextLine(
305        title = _(u'First Name'),
306        required = True,
307        )
308
309    email = schema.ASCIILine(
310        title = _(u'Email Address'),
311        required = True,
312        constraint=validate_email,
313        )
314
315class IStudentStudyCourse(IKofaObject):
316    """A container for student study levels.
317
318    """
319    certificate = schema.Choice(
320        title = _(u'Certificate'),
321        source = CertificateSource(),
322        required = False,
323        )
324
325    entry_mode = schema.Choice(
326        title = _(u'Entry Mode'),
327        source = StudyModeSource(),
328        required = True,
329        readonly = False,
330        )
331
332    entry_session = schema.Choice(
333        title = _(u'Entry Session'),
334        source = academic_sessions_vocab,
335        #default = datetime.now().year,
336        required = True,
337        readonly = False,
338        )
339
340    current_session = schema.Choice(
341        title = _(u'Current Session'),
342        source = academic_sessions_vocab,
343        required = True,
344        readonly = False,
345        )
346
347    current_level = schema.Choice(
348        title = _(u'Current Level'),
349        source = StudyLevelSource(),
350        required = False,
351        readonly = False,
352        )
353
354    current_verdict = schema.Choice(
355        title = _(u'Current Verdict'),
356        source = VerdictSource(),
357        default = '0',
358        required = False,
359        )
360
361    previous_verdict = schema.Choice(
362        title = _(u'Previous Verdict'),
363        source = VerdictSource(),
364        default = '0',
365        required = False,
366        )
367
368class IStudentVerdictUpdate(IKofaObject):
369    """A interface for verdict imports.
370
371    """
372
373    current_verdict = schema.Choice(
374        title = _(u'Current Verdict'),
375        source = VerdictSource(),
376        required = True,
377        )
378
379    current_session = schema.Choice(
380        title = _(u'Current Session'),
381        source = academic_sessions_vocab,
382        required = True,
383        )
384
385    current_level = schema.Choice(
386        title = _(u'Current Level'),
387        source = StudyLevelSource(),
388        required = True,
389        )
390
391class IStudentStudyLevel(IKofaObject):
392    """A container for course tickets.
393
394    """
395    level = Attribute('The level code')
396    validation_date = Attribute('The date of validation')
397    validated_by = Attribute('User Id of course adviser')
398
399    level_session = schema.Choice(
400        title = _(u'Session'),
401        source = academic_sessions_vocab,
402        required = True,
403        )
404
405    level_verdict = schema.Choice(
406        title = _(u'Verdict'),
407        source = VerdictSource(),
408        default = '0',
409        required = False,
410        )
411
412    def addCourseTicket(ticket, course):
413        """Add a course ticket object.
414        """
415
416class ICourseTicket(IKofaObject):
417    """A course ticket.
418
419    """
420    code = Attribute('code of the original course')
421    title = Attribute('title of the original course')
422    credits = Attribute('credits of the original course')
423    passmark = Attribute('passmark of the original course')
424    semester = Attribute('semester of the original course')
425    fcode = Attribute('faculty code of the original course')
426    dcode = Attribute('department code of the original course')
427
428    mandatory = schema.Bool(
429        title = _(u'Mandatory'),
430        default = False,
431        required = False,
432        readonly = False,
433        )
434
435    score = schema.Int(
436        title = _(u'Score'),
437        default = 0,
438        required = False,
439        readonly = False,
440        )
441
442    automatic = schema.Bool(
443        title = _(u'Automatical Creation'),
444        default = False,
445        required = False,
446        readonly = True,
447        )
448
449    carry_over = schema.Bool(
450        title = _(u'Carry-over Course'),
451        default = False,
452        required = False,
453        readonly = False,
454        )
455
456    def getLevel():
457        """Returns the id of the level the ticket has been added to.
458        """
459
460    def getLevelSession():
461        """Returns the session of the level the ticket has been added to.
462        """
463
464class ICourseTicketAdd(ICourseTicket):
465    """An interface for adding course tickets.
466
467    """
468    course = schema.Choice(
469        title = _(u'Course'),
470        source = CourseSource(),
471        readonly = False,
472        )
473
474class IStudentAccommodation(IKofaObject):
475    """A container for student accommodation objects.
476
477    """
478
479class IBedTicket(IKofaObject):
480    """A ticket for accommodation booking.
481
482    """
483    bed = Attribute('The bed object.')
484
485    bed_coordinates = schema.TextLine(
486        title = _(u'Bed Coordinates'),
487        required = False,
488        readonly = False,
489        )
490
491    bed_type = schema.TextLine(
492        title = _(u'Bed Type'),
493        required = False,
494        readonly = False,
495        )
496
497    booking_session = schema.Choice(
498        title = _(u'Session'),
499        source = academic_sessions_vocab,
500        required = True,
501        readonly = True,
502        )
503
504    booking_date = schema.Datetime(
505        title = _(u'Booking Date'),
506        required = False,
507        readonly = True,
508        )
509
510    booking_code = schema.TextLine(
511        title = _(u'Booking Activation Code'),
512        required = False,
513        readonly = True,
514        )
515
516    def getSessionString():
517        """Returns the title of academic_sessions_vocab term.
518
519        """
520
521class IStudentPaymentsContainer(IPaymentsContainer):
522    """A container for student payment objects.
523
524    """
525
526class IStudentOnlinePayment(IOnlinePayment):
527    """A student payment via payment gateways.
528
529    """
530
531    p_level = schema.Int(
532        title = _(u'Payment Level'),
533        required = False,
534        readonly = True,
535        )
536
537    def doAfterStudentPayment():
538        """Process student after payment was made.
539
540        """
541
542    def doAfterStudentPaymentApproval():
543        """Process student after payment was approved.
544
545        """
546
547    def approveStudentPayment():
548        """Approve payment and process student.
549
550        """
551
552IStudentOnlinePayment['p_level'].order = IStudentOnlinePayment[
553    'p_session'].order
554
555class ICSVStudentExporter(ICSVExporter):
556    """A regular ICSVExporter that additionally supports exporting
557      data from a given student object.
558    """
559
560    def export_student(student, filepath=None):
561        """Export data for a given student.
562        """
Note: See TracBrowser for help on using the repository browser.