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

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

clr_code and adm_code (actually all field meant for reimport) must not be readonly.

  • Property svn:keywords set to Id
File size: 14.9 KB
Line 
1## $Id: interfaces.py 8977 2012-07-12 05:50:42Z 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    student_id = schema.TextLine(
160        title = _(u'Student Id'),
161        required = False,
162        )
163
164    firstname = schema.TextLine(
165        title = _(u'First Name'),
166        required = True,
167        )
168
169    middlename = schema.TextLine(
170        title = _(u'Middle Name'),
171        required = False,
172        )
173
174    lastname = schema.TextLine(
175        title = _(u'Last Name (Surname)'),
176        required = True,
177        )
178
179    sex = schema.Choice(
180        title = _(u'Sex'),
181        source = GenderSource(),
182        required = True,
183        )
184
185    reg_number = TextLineChoice(
186        title = _(u'Registration Number'),
187        required = True,
188        readonly = False,
189        source = contextual_reg_num_source,
190        )
191
192    matric_number = TextLineChoice(
193        title = _(u'Matriculation Number'),
194        required = False,
195        readonly = False,
196        source = contextual_mat_num_source,
197        )
198
199    adm_code = schema.TextLine(
200        title = _(u'PWD Activation Code'),
201        required = False,
202        readonly = False,
203        )
204
205    email = schema.ASCIILine(
206        title = _(u'Email'),
207        required = False,
208        constraint=validate_email,
209        )
210    phone = PhoneNumber(
211        title = _(u'Phone'),
212        description = u'',
213        required = False,
214        )
215
216class IUGStudentClearance(IKofaObject):
217    """Representation of undergraduate student clearance data.
218
219    """
220    date_of_birth = FormattedDate(
221        title = _(u'Date of Birth'),
222        required = True,
223        show_year = True,
224        )
225
226    clearance_locked = schema.Bool(
227        title = _(u'Clearance form locked'),
228        default = False,
229        )
230
231    clr_code = schema.TextLine(
232        title = _(u'CLR Activation Code'),
233        required = False,
234        readonly = False,
235        )
236
237    nationality = schema.Choice(
238        vocabulary = nats_vocab,
239        title = _(u'Nationality'),
240        required = False,
241        )
242
243class IPGStudentClearance(IUGStudentClearance):
244    """Representation of postgraduate student clearance data.
245
246    """
247    employer = schema.TextLine(
248        title = _(u'Employer'),
249        required = False,
250        readonly = False,
251        )
252
253class IStudentPersonal(IKofaObject):
254    """Representation of student personal data.
255
256    """
257    perm_address = schema.Text(
258        title = _(u'Permanent Address'),
259        required = False,
260        )
261
262class IStudent(IStudentBase,IUGStudentClearance,IPGStudentClearance,
263    IStudentPersonal):
264    """Representation of a student.
265
266    """
267
268class IStudentUpdateByRegNo(IStudent):
269    """Representation of a student. Skip regular reg_number validation.
270
271    """
272    reg_number = schema.TextLine(
273        title = _(u'Registration Number'),
274        required = False,
275        )
276
277class IStudentUpdateByMatricNo(IStudent):
278    """Representation of a student. Skip regular matric_number validation.
279
280    """
281    matric_number = schema.TextLine(
282        title = _(u'Matriculation Number'),
283        required = False,
284        )
285
286class IStudentRequestPW(IStudent):
287    """Representation of an student for first-time password request.
288
289    This interface is used when students use the requestpw page to
290    login for the the first time.
291    """
292    number = schema.TextLine(
293        title = _(u'Registr. or Matric. Number'),
294        required = True,
295        )
296
297    firstname = schema.TextLine(
298        title = _(u'First Name'),
299        required = True,
300        )
301
302    email = schema.ASCIILine(
303        title = _(u'Email Address'),
304        required = True,
305        constraint=validate_email,
306        )
307
308class IStudentStudyCourse(IKofaObject):
309    """A container for student study levels.
310
311    """
312    certificate = schema.Choice(
313        title = _(u'Certificate'),
314        source = CertificateSource(),
315        required = False,
316        )
317
318    entry_mode = schema.Choice(
319        title = _(u'Entry Mode'),
320        source = StudyModeSource(),
321        required = True,
322        readonly = False,
323        )
324
325    entry_session = schema.Choice(
326        title = _(u'Entry Session'),
327        source = academic_sessions_vocab,
328        #default = datetime.now().year,
329        required = True,
330        readonly = False,
331        )
332
333    current_session = schema.Choice(
334        title = _(u'Current Session'),
335        source = academic_sessions_vocab,
336        required = True,
337        readonly = False,
338        )
339
340    current_level = schema.Choice(
341        title = _(u'Current Level'),
342        source = StudyLevelSource(),
343        required = False,
344        readonly = False,
345        )
346
347    current_verdict = schema.Choice(
348        title = _(u'Current Verdict'),
349        source = VerdictSource(),
350        default = '0',
351        required = False,
352        )
353
354    previous_verdict = schema.Choice(
355        title = _(u'Previous Verdict'),
356        source = VerdictSource(),
357        default = '0',
358        required = False,
359        )
360
361class IStudentVerdictUpdate(IKofaObject):
362    """A interface for verdict imports.
363
364    """
365
366    current_verdict = schema.Choice(
367        title = _(u'Current Verdict'),
368        source = VerdictSource(),
369        required = True,
370        )
371
372    current_session = schema.Choice(
373        title = _(u'Current Session'),
374        source = academic_sessions_vocab,
375        required = True,
376        )
377
378    current_level = schema.Choice(
379        title = _(u'Current Level'),
380        source = StudyLevelSource(),
381        required = True,
382        )
383
384class IStudentStudyLevel(IKofaObject):
385    """A container for course tickets.
386
387    """
388    level = Attribute('The level code')
389    validation_date = Attribute('The date of validation')
390    validated_by = Attribute('User Id of course adviser')
391
392    level_session = schema.Choice(
393        title = _(u'Session'),
394        source = academic_sessions_vocab,
395        required = True,
396        )
397
398    level_verdict = schema.Choice(
399        title = _(u'Verdict'),
400        source = VerdictSource(),
401        default = '0',
402        required = False,
403        )
404
405    def addCourseTicket(ticket, course):
406        """Add a course ticket object.
407        """
408
409class ICourseTicket(IKofaObject):
410    """A course ticket.
411
412    """
413    code = Attribute('code of the original course')
414    title = Attribute('title of the original course')
415    credits = Attribute('credits of the original course')
416    passmark = Attribute('passmark of the original course')
417    semester = Attribute('semester of the original course')
418    fcode = Attribute('faculty code of the original course')
419    dcode = Attribute('department code of the original course')
420
421    mandatory = schema.Bool(
422        title = _(u'Mandatory'),
423        default = False,
424        required = False,
425        readonly = False,
426        )
427
428    score = schema.Int(
429        title = _(u'Score'),
430        default = 0,
431        required = False,
432        readonly = False,
433        )
434
435    automatic = schema.Bool(
436        title = _(u'Automatical Creation'),
437        default = False,
438        required = False,
439        readonly = True,
440        )
441
442    carry_over = schema.Bool(
443        title = _(u'Carry-over Course'),
444        default = False,
445        required = False,
446        readonly = False,
447        )
448
449    def getLevel():
450        """Returns the id of the level the ticket has been added to.
451        """
452
453    def getLevelSession():
454        """Returns the session of the level the ticket has been added to.
455        """
456
457class ICourseTicketAdd(ICourseTicket):
458    """An interface for adding course tickets.
459
460    """
461    course = schema.Choice(
462        title = _(u'Course'),
463        source = CourseSource(),
464        readonly = False,
465        )
466
467class IStudentAccommodation(IKofaObject):
468    """A container for student accommodation objects.
469
470    """
471
472class IBedTicket(IKofaObject):
473    """A ticket for accommodation booking.
474
475    """
476    bed = Attribute('The bed object.')
477
478    bed_coordinates = schema.TextLine(
479        title = _(u'Bed Coordinates'),
480        required = False,
481        readonly = False,
482        )
483
484    bed_type = schema.TextLine(
485        title = _(u'Bed Type'),
486        required = False,
487        readonly = False,
488        )
489
490    booking_session = schema.Choice(
491        title = _(u'Session'),
492        source = academic_sessions_vocab,
493        required = True,
494        readonly = True,
495        )
496
497    booking_date = schema.Datetime(
498        title = _(u'Booking Date'),
499        required = False,
500        readonly = True,
501        )
502
503    booking_code = schema.TextLine(
504        title = _(u'Booking Activation Code'),
505        required = False,
506        readonly = True,
507        )
508
509    def getSessionString():
510        """Returns the title of academic_sessions_vocab term.
511
512        """
513
514class IStudentPaymentsContainer(IPaymentsContainer):
515    """A container for student payment objects.
516
517    """
518
519class IStudentOnlinePayment(IOnlinePayment):
520    """A student payment via payment gateways.
521
522    """
523
524    p_level = schema.Int(
525        title = _(u'Payment Level'),
526        required = False,
527        readonly = True,
528        )
529
530    def doAfterStudentPayment():
531        """Process student after payment was made.
532
533        """
534
535    def doAfterStudentPaymentApproval():
536        """Process student after payment was approved.
537
538        """
539
540    def approveStudentPayment():
541        """Approve payment and process student.
542
543        """
544
545IStudentOnlinePayment['p_level'].order = IStudentOnlinePayment[
546    'p_session'].order
547
548class ICSVStudentExporter(ICSVExporter):
549    """A regular ICSVExporter that additionally supports exporting
550      data from a given student object.
551    """
552
553    def export_student(student, filepath=None):
554        """Export data for a given student.
555        """
Note: See TracBrowser for help on using the repository browser.