source: main/waeup.kofa/trunk/src/waeup/kofa/applicants/interfaces.py @ 13228

Last change on this file since 13228 was 13218, checked in by Henrik Bettermann, 9 years ago

Add UI components to purge applicants containers.

  • Property svn:keywords set to Id
File size: 18.6 KB
Line 
1## $Id: interfaces.py 13218 2015-08-24 08:44:35Z 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"""Interfaces of the university application package.
19"""
20from datetime import datetime
21from grokcore.content.interfaces import IContainer
22from zc.sourcefactory.contextual import BasicContextualSourceFactory
23from zope import schema
24from zope.component import queryUtility, getUtility
25from zope.catalog.interfaces import ICatalog
26from zope.interface import Interface, Attribute, implements, directlyProvides
27from zope.schema.interfaces import (
28    ValidationError, ISource, IContextSourceBinder)
29from waeup.kofa.schema import TextLineChoice, FormattedDate
30from waeup.kofa.interfaces import (
31    IKofaObject, validate_email,
32    SimpleKofaVocabulary)
33from waeup.kofa.interfaces import MessageFactory as _
34from waeup.kofa.payments.interfaces import IOnlinePayment
35from waeup.kofa.schema import PhoneNumber
36from waeup.kofa.students.vocabularies import GenderSource, RegNumberSource
37from waeup.kofa.university.vocabularies import (
38    AppCatSource, CertificateSource, SpecialApplicationSource)
39
40#: Maximum upload size for applicant passport photographs (in bytes)
41MAX_UPLOAD_SIZE = 1024 * 20
42
43_marker = object() # a marker different from None
44
45def year_range():
46    curr_year = datetime.now().year
47    return range(curr_year - 2, curr_year + 5)
48
49class RegNumInSource(ValidationError):
50    """Registration number exists already
51    """
52    # The docstring of ValidationErrors is used as error description
53    # by zope.formlib.
54    pass
55
56class ApplicantRegNumberSource(RegNumberSource):
57    """A source that accepts any reg number if not used already by a
58    different applicant.
59    """
60    cat_name = 'applicants_catalog'
61    field_name = 'reg_number'
62    validation_error = RegNumInSource
63    comp_field = 'applicant_id'
64
65def contextual_reg_num_source(context):
66    source = ApplicantRegNumberSource(context)
67    return source
68directlyProvides(contextual_reg_num_source, IContextSourceBinder)
69
70
71class AppCatCertificateSource(CertificateSource):
72    """An application certificate source delivers all certificates
73    which belong to a certain application_category.
74
75    This source is meant to be used with Applicants.
76
77    The application category must match the application category of
78    the context parent, normally an applicants container.
79    """
80    def contains(self, context, value):
81        context_appcat = getattr(getattr(
82            context, '__parent__', None), 'application_category', _marker)
83        if context_appcat is _marker:
84            # If the context (applicant) has no application category,
85            # then it might be not part of a container (yet), for
86            # instance during imports. We consider this correct.
87            return True
88        if value.application_category == context_appcat:
89            return True
90        return False
91
92    def getValues(self, context):
93        appcat = getattr(getattr(context, '__parent__', None),
94                         'application_category', None)
95        catalog = getUtility(ICatalog, name='certificates_catalog')
96        result = catalog.searchResults(
97            application_category=(appcat,appcat))
98        resultlist = getUtility(
99            IApplicantsUtils).sortCertificates(context, result)
100        return resultlist
101
102    def getTitle(self, context, value):
103        return getUtility(
104            IApplicantsUtils).getCertTitle(context, value)
105
106class ApplicationTypeSource(BasicContextualSourceFactory):
107    """An application type source delivers screening types defined in the
108    portal.
109    """
110    def getValues(self, context):
111        appcats_dict = getUtility(
112            IApplicantsUtils).APP_TYPES_DICT
113        return sorted(appcats_dict.keys())
114
115    def getToken(self, context, value):
116        return value
117
118    def getTitle(self, context, value):
119        appcats_dict = getUtility(
120            IApplicantsUtils).APP_TYPES_DICT
121        return appcats_dict[value][0]
122
123# Maybe FUTMinna still needs this ...
124#class ApplicationPinSource(BasicContextualSourceFactory):
125#    """An application pin source delivers PIN prefixes for application
126#    defined in the portal.
127#    """
128#    def getValues(self, context):
129#        apppins_dict = getUtility(
130#            IApplicantsUtils).APP_TYPES_DICT
131#        return sorted(appcats_dict.keys())
132#
133#    def getToken(self, context, value):
134#        return value
135#
136#    def getTitle(self, context, value):
137#        apppins_dict = getUtility(
138#            IApplicantsUtils).APP_TYPES_DICT
139#        return u"%s (%s)" % (
140#            apppins_dict[value][1],self.apppins_dict[value][0])
141
142application_modes_vocab = SimpleKofaVocabulary(
143    (_('Create Application Records'), 'create'),
144    (_('Update Application Records'), 'update'),
145    )
146
147class IApplicantsUtils(Interface):
148    """A collection of methods which are subject to customization.
149    """
150    APP_TYPES_DICT = Attribute('dict of application types')
151
152    def setPaymentDetails(container, payment):
153        """Set the payment data of an applicant.
154        """
155
156    def getApplicantsStatistics(container):
157        """Count applicants in containers.
158        """
159
160    def filterCertificates(context, resultset):
161        """Filter and sort certificates for AppCatCertificateSource.
162        """
163
164    def getCertTitle(context, value):
165        """Compose the titles in AppCatCertificateSource.
166        """
167
168class IApplicantsRoot(IKofaObject, IContainer):
169    """A container for applicants containers.
170    """
171    description_dict = Attribute('Language translation dictionary with values in HTML format')
172    local_roles = Attribute('List of local role names')
173    logger_name = Attribute('Name of the logger')
174    logger_filename = Attribute('Name of the logger file')
175
176    description = schema.Text(
177        title = _(u'Human readable description in HTML format'),
178        required = False,
179        default = u'''This text can been seen by anonymous users.
180Here we put multi-lingual general information about the application procedure.
181>>de<<
182Dieser Text kann von anonymen Benutzern gelesen werden.
183Hier koennen mehrsprachige Informationen fuer Antragsteller hinterlegt werden.'''
184        )
185
186class IApplicantsContainer(IKofaObject):
187    """An applicants container contains applicants.
188    """
189    statistics = Attribute('Applicant counts')
190    expired = Attribute('True if application has started but not ended')
191
192    description_dict = Attribute('Language translation dictionary with values in HTML format')
193    local_roles = Attribute('List of local role names')
194
195
196    code = schema.TextLine(
197        title = _(u'Code'),
198        required = True,
199        readonly = True,
200        )
201
202    title = schema.TextLine(
203        title = _(u'Title'),
204        required = True,
205        readonly = False,
206        )
207
208    prefix = schema.Choice(
209        title = _(u'Application Target'),
210        required = True,
211        source = ApplicationTypeSource(),
212        readonly = True,
213        )
214
215    year = schema.Choice(
216        title = _(u'Year of Entrance'),
217        required = True,
218        values = year_range(),
219        readonly = True,
220        )
221
222    mode = schema.Choice(
223        title = _(u'Application Mode'),
224        vocabulary = application_modes_vocab,
225        required = True,
226        )
227
228    # Maybe FUTMinna still needs this ...
229    #ac_prefix = schema.Choice(
230    #    title = u'Activation code prefix',
231    #    required = True,
232    #    default = None,
233    #    source = ApplicationPinSource(),
234    #    )
235
236    application_category = schema.Choice(
237        title = _(u'Category for the grouping of certificates'),
238        required = True,
239        source = AppCatSource(),
240        )
241
242    description = schema.Text(
243        title = _(u'Human readable description in HTML format'),
244        required = False,
245        default = u'''This text can been seen by anonymous users.
246Here we put multi-lingual information about the study courses provided, the application procedure and deadlines.
247>>de<<
248Dieser Text kann von anonymen Benutzern gelesen werden.
249Hier koennen mehrsprachige Informationen fuer Antragsteller hinterlegt werden.'''
250        )
251
252    startdate = schema.Datetime(
253        title = _(u'Application Start Date'),
254        required = False,
255        description = _('Example: ') + u'2011-12-01 18:30:00+01:00',
256        )
257
258    enddate = schema.Datetime(
259        title = _(u'Application Closing Date'),
260        required = False,
261        description = _('Example: ') + u'2011-12-31 23:59:59+01:00',
262        )
263
264    strict_deadline = schema.Bool(
265        title = _(u'Forbid additions after deadline (enddate)'),
266        required = False,
267        default = True,
268        )
269
270    application_fee = schema.Float(
271        title = _(u'Application Fee'),
272        default = 0.0,
273        required = False,
274        )
275
276    application_slip_notice = schema.Text(
277        title = _(u'Human readable notice on application slip in HTML format'),
278        required = False,
279        )
280
281
282    hidden= schema.Bool(
283        title = _(u'Hide container'),
284        required = False,
285        default = False,
286        )
287
288    def addApplicant(applicant):
289        """Add an applicant.
290        """
291
292    def writeLogMessage(view, comment):
293        """Add an INFO message to applicants.log.
294        """
295
296    def traverse(name):
297        """Deliver appropriate containers.
298        """
299
300class IApplicantsContainerAdd(IApplicantsContainer):
301    """An applicants container contains university applicants.
302    """
303    prefix = schema.Choice(
304        title = _(u'Application Target'),
305        required = True,
306        source = ApplicationTypeSource(),
307        readonly = False,
308        )
309
310    year = schema.Choice(
311        title = _(u'Year of Entrance'),
312        required = True,
313        values = year_range(),
314        readonly = False,
315        )
316
317IApplicantsContainerAdd[
318    'prefix'].order =  IApplicantsContainer['prefix'].order
319IApplicantsContainerAdd[
320    'year'].order =  IApplicantsContainer['year'].order
321
322class IApplicantBaseData(IKofaObject):
323    """This is a base interface of an applicant with no field
324    required. For use with processors, forms, etc., please use one of
325    the derived interfaces below, which set more fields to required
326    state, depending on use-case.
327    """
328    state = Attribute('Application state of an applicant')
329    history = Attribute('Object history, a list of messages')
330    display_fullname = Attribute('The fullname of an applicant')
331    application_number = Attribute('The key under which the record is stored')
332    container_code = Attribute('Code of the parent container plus additional information if record is used or not')
333    translated_state = Attribute('Real name of the application state')
334    special = Attribute('True if special application')
335
336    application_date = Attribute('UTC datetime of submission, used for export only')
337    password = Attribute('Encrypted password of an applicant')
338
339
340    suspended = schema.Bool(
341        title = _(u'Account suspended'),
342        default = False,
343        required = False,
344        )
345
346    applicant_id = schema.TextLine(
347        title = _(u'Applicant Id'),
348        required = False,
349        readonly = False,
350        )
351
352    reg_number = TextLineChoice(
353        title = _(u'Registration Number'),
354        readonly = False,
355        required = True,
356        source = contextual_reg_num_source,
357        )
358
359    firstname = schema.TextLine(
360        title = _(u'First Name'),
361        required = True,
362        )
363
364    middlename = schema.TextLine(
365        title = _(u'Middle Name'),
366        required = False,
367        )
368
369    lastname = schema.TextLine(
370        title = _(u'Last Name (Surname)'),
371        required = True,
372        )
373
374    date_of_birth = FormattedDate(
375        title = _(u'Date of Birth'),
376        required = False,
377        show_year = True,
378        )
379
380    sex = schema.Choice(
381        title = _(u'Sex'),
382        source = GenderSource(),
383        required = True,
384        )
385
386    email = schema.ASCIILine(
387        title = _(u'Email Address'),
388        required = False,
389        constraint=validate_email,
390        )
391
392    phone = PhoneNumber(
393        title = _(u'Phone'),
394        description = u'',
395        required = False,
396        )
397
398    course1 = schema.Choice(
399        title = _(u'1st Choice Course of Study'),
400        source = AppCatCertificateSource(),
401        required = True,
402        )
403
404    course2 = schema.Choice(
405        title = _(u'2nd Choice Course of Study'),
406        source = AppCatCertificateSource(),
407        required = False,
408        )
409
410    #school_grades = schema.List(
411    #    title = _(u'School Grades'),
412    #    value_type = ResultEntryField(),
413    #    required = False,
414    #    default = [],
415    #    )
416
417    notice = schema.Text(
418        title = _(u'Notice'),
419        required = False,
420        )
421    student_id = schema.TextLine(
422        title = _(u'Student Id'),
423        required = False,
424        readonly = False,
425        )
426    course_admitted = schema.Choice(
427        title = _(u'Admitted Course of Study'),
428        source = CertificateSource(),
429        required = False,
430        )
431    locked = schema.Bool(
432        title = _(u'Form locked'),
433        default = False,
434        required = False,
435        )
436
437    special_application = schema.Choice(
438        title = _(u'Special Application'),
439        source = SpecialApplicationSource(),
440        required = False,
441        )
442
443class IApplicant(IApplicantBaseData):
444    """This is basically the applicant base data. Here we repeat the
445    fields from base data if we have to set the `required` attribute
446    to True (which is the default).
447    """
448
449    def writeLogMessage(view, comment):
450        """Add an INFO message to applicants.log.
451        """
452
453    def createStudent():
454        """Create a student object from applicant data and copy
455        passport image and application slip.
456        """
457
458class ISpecialApplicant(IKofaObject):
459    """This reduced interface is for former students or students who are not
460    users of the portal but have to pay supplementary fees.
461    This interface is used in browser components only. Thus we can't add
462    fields here to the regular IApplicant interface here. We can
463    only 'customize' fields.
464    """
465
466    suspended = schema.Bool(
467        title = _(u'Account suspended'),
468        default = False,
469        required = False,
470        )
471
472    locked = schema.Bool(
473        title = _(u'Form locked'),
474        default = False,
475        required = False,
476        )
477
478    applicant_id = schema.TextLine(
479        title = _(u'Applicant Id'),
480        required = False,
481        readonly = False,
482        )
483
484    firstname = schema.TextLine(
485        title = _(u'First Name'),
486        required = True,
487        )
488
489    middlename = schema.TextLine(
490        title = _(u'Middle Name'),
491        required = False,
492        )
493
494    lastname = schema.TextLine(
495        title = _(u'Last Name (Surname)'),
496        required = True,
497        )
498
499    reg_number = TextLineChoice(
500        title = _(u'Identification Number'),
501        description = u'Enter either registration or matriculation number.',
502        readonly = False,
503        required = True,
504        source = contextual_reg_num_source,
505        )
506
507    date_of_birth = FormattedDate(
508        title = _(u'Date of Birth'),
509        required = False,
510        #date_format = u'%d/%m/%Y', # Use grok-instance-wide default
511        show_year = True,
512        )
513
514    email = schema.ASCIILine(
515        title = _(u'Email Address'),
516        required = True,
517        constraint=validate_email,
518        )
519
520    phone = PhoneNumber(
521        title = _(u'Phone'),
522        description = u'',
523        required = False,
524        )
525
526    special_application = schema.Choice(
527        title = _(u'Special Application'),
528        source = SpecialApplicationSource(),
529        required = True,
530        )
531
532class IApplicantEdit(IApplicant):
533    """This is an applicant interface for editing.
534
535    Here we can repeat the fields from base data and set the
536    `required` and `readonly` attributes to True to further restrict
537    the data access. Or we can allow only certain certificates to be
538    selected by choosing the appropriate source.
539
540    We cannot omit fields here. This has to be done in the
541    respective form page.
542    """
543
544    email = schema.ASCIILine(
545        title = _(u'Email Address'),
546        required = True,
547        constraint=validate_email,
548        )
549
550    course1 = schema.Choice(
551        title = _(u'1st Choice Course of Study'),
552        source = AppCatCertificateSource(),
553        required = True,
554        )
555
556    course2 = schema.Choice(
557        title = _(u'2nd Choice Course of Study'),
558        source = AppCatCertificateSource(),
559        required = False,
560        )
561
562    course_admitted = schema.Choice(
563        title = _(u'Admitted Course of Study'),
564        source = CertificateSource(),
565        required = False,
566        readonly = True,
567        )
568
569    notice = schema.Text(
570        title = _(u'Notice'),
571        required = False,
572        readonly = True,
573        )
574
575IApplicantEdit['email'].order = IApplicantEdit['sex'].order
576
577class IApplicantUpdateByRegNo(IApplicant):
578    """Skip regular reg_number validation if reg_number is used for finding
579    the applicant object.
580    """
581    reg_number = schema.TextLine(
582        title = u'Registration Number',
583        required = False,
584        )
585
586class IApplicantRegisterUpdate(IApplicant):
587    """This is a representation of an applicant for first-time registration.
588    This interface is used when applicants use the registration page to
589    update their records.
590    """
591    reg_number = schema.TextLine(
592        title = u'Registration Number',
593        required = True,
594        )
595
596    #firstname = schema.TextLine(
597    #    title = _(u'First Name'),
598    #    required = True,
599    #    )
600
601    lastname = schema.TextLine(
602        title = _(u'Last Name (Surname)'),
603        required = True,
604        )
605
606    email = schema.ASCIILine(
607        title = _(u'Email Address'),
608        required = True,
609        constraint=validate_email,
610        )
611
612class IApplicantOnlinePayment(IOnlinePayment):
613    """An applicant payment via payment gateways.
614    """
615
616    def doAfterApplicantPayment():
617        """Process applicant after payment was made.
618        """
619
620    def doAfterApplicantPaymentApproval():
621        """Process applicant after payment was approved.
622        """
623
624    def approveApplicantPayment():
625        """Approve payment and process applicant.
626        """
Note: See TracBrowser for help on using the repository browser.