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

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

Export number of tickets contained in a StudentStudyLevel? container.

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