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

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

Dedicated officers should be able to login as student with a temporary password set by the system. This is the first part of its implementation.

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