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

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

In contrast to the comment of the last revision: We need to store validation_date and validated_by also in Kofa. They have to be set by the workflow transition events. They must not be editable (but importable and exportable).

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