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

Last change on this file since 8062 was 8052, checked in by Henrik Bettermann, 13 years ago

Merge IApplicantProcessData and IApplicantBaseData.

All attributes and fields of an applicant must be exportable.

  • Property svn:keywords set to Id
File size: 15.8 KB
Line 
1## $Id: interfaces.py 8052 2012-04-06 15:27:12Z 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 grokcore.content.interfaces import IContainer
21from zc.sourcefactory.basic import BasicSourceFactory
22from zc.sourcefactory.contextual import BasicContextualSourceFactory
23from zope import schema
24from zope.component import getUtilitiesFor, 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
30from waeup.kofa.interfaces import (
31    IKofaObject, year_range, validate_email, academic_sessions_vocab,
32    SimpleKofaVocabulary)
33from waeup.kofa.interfaces import MessageFactory as _
34from waeup.kofa.payments.interfaces import IOnlinePayment
35from waeup.kofa.schoolgrades import ResultEntryField
36from waeup.kofa.students.vocabularies import (
37    lgas_vocab, GenderSource)
38from waeup.kofa.university.vocabularies import (
39    course_levels, AppCatSource, CertificateSource)
40
41#: Maximum upload size for applicant passport photographs (in bytes)
42MAX_UPLOAD_SIZE = 1024 * 20
43
44class RegNumInSource(ValidationError):
45    """Registration number exists already
46    """
47    # The docstring of ValidationErrors is used as error description
48    # by zope.formlib.
49    pass
50
51class RegNumberSource(object):
52    implements(ISource)
53    cat_name = 'applicants_catalog'
54    field_name = 'reg_number'
55    validation_error = RegNumInSource
56    def __init__(self, context):
57        self.context = context
58        return
59
60    def __contains__(self, value):
61        cat = queryUtility(ICatalog, self.cat_name)
62        if cat is None:
63            return True
64        kw = {self.field_name: (value, value)}
65        results = cat.searchResults(**kw)
66        for entry in results:
67            if entry.applicant_id != self.context.applicant_id:
68                # XXX: sources should simply return False.
69                #      But then we get some stupid error message in forms
70                #      when validation fails.
71                raise self.validation_error(value)
72                #return False
73        return True
74
75def contextual_reg_num_source(context):
76    source = RegNumberSource(context)
77    return source
78directlyProvides(contextual_reg_num_source, IContextSourceBinder)
79
80
81class AppCatCertificateSource(CertificateSource):
82    """An application certificate source delivers all courses which belong to
83    a certain application_category.
84    """
85    def getValues(self, context):
86        # appliction category not available when certificate was deleted.
87        # shouldn't that info be part of applicant info instead?
88        # when we cannot determine the appcat, we will display all courses.
89        appcat = getattr(getattr(context, '__parent__', None),
90                         'application_category', None)
91        catalog = getUtility(ICatalog, name='certificates_catalog')
92        result = catalog.searchResults(
93            application_category=(appcat,appcat))
94        result = sorted(result, key=lambda value: value.code)
95        curr_course = context.course1
96        if curr_course is not None and curr_course not in result:
97            # display also current course even if it is not catalogued
98            # (any more)
99            result = [curr_course,] + result
100        return result
101
102class ApplicationTypeSource(BasicContextualSourceFactory):
103    """An application type source delivers screening types defined in the
104    portal.
105    """
106    def getValues(self, context):
107        appcats_dict = getUtility(
108            IApplicantsUtils).APP_TYPES_DICT
109        return sorted(appcats_dict.keys())
110
111    def getToken(self, context, value):
112        return value
113
114    def getTitle(self, context, value):
115        appcats_dict = getUtility(
116            IApplicantsUtils).APP_TYPES_DICT
117        return appcats_dict[value][0]
118
119# Maybe Uniben still needs this ...
120#class ApplicationPinSource(BasicContextualSourceFactory):
121#    """An application pin source delivers PIN prefixes for application
122#    defined in the portal.
123#    """
124#    def getValues(self, context):
125#        apppins_dict = getUtility(
126#            IApplicantsUtils).APP_TYPES_DICT
127#        return sorted(appcats_dict.keys())
128#
129#    def getToken(self, context, value):
130#        return value
131#
132#    def getTitle(self, context, value):
133#        apppins_dict = getUtility(
134#            IApplicantsUtils).APP_TYPES_DICT
135#        return u"%s (%s)" % (
136#            apppins_dict[value][1],self.apppins_dict[value][0])
137
138application_modes_vocab = SimpleKofaVocabulary(
139    (_('Create Application Records'), 'create'),
140    (_('Update Application Records'), 'update'),
141    )
142
143class IApplicantsUtils(Interface):
144    """A collection of methods which are subject to customization.
145    """
146
147    APP_TYPES_DICT = Attribute(' dict of application types')
148
149class IApplicantsRoot(IKofaObject, IContainer):
150    """A container for university applicants containers.
151    """
152    pass
153
154class IApplicantsContainer(IKofaObject):
155    """An applicants container contains university applicants.
156
157    """
158
159    code = schema.TextLine(
160        title = _(u'Code'),
161        required = True,
162        readonly = True,
163        )
164
165    title = schema.TextLine(
166        title = _(u'Title'),
167        required = True,
168        readonly = True,
169        )
170
171    prefix = schema.Choice(
172        title = _(u'Application Target'),
173        required = True,
174        source = ApplicationTypeSource(),
175        readonly = True,
176        )
177
178    year = schema.Choice(
179        title = _(u'Year of Entrance'),
180        required = True,
181        values = year_range(),
182        readonly = True,
183        )
184
185    mode = schema.Choice(
186        title = _(u'Application Mode'),
187        vocabulary = application_modes_vocab,
188        required = True,
189        )
190
191    entry_level = schema.Choice(
192        title = _(u'Entry Level'),
193        vocabulary = course_levels,
194        required = True,
195        )
196
197    # Maybe Uniben still needs this ...
198    #ac_prefix = schema.Choice(
199    #    title = u'Activation code prefix',
200    #    required = True,
201    #    default = None,
202    #    source = ApplicationPinSource(),
203    #    )
204
205    application_category = schema.Choice(
206        title = _(u'Category for the grouping of certificates'),
207        required = True,
208        source = AppCatSource(),
209        )
210
211    description = schema.Text(
212        title = _(u'Human readable description in reST format'),
213        required = False,
214        default = u'''This text can been seen by anonymous users.
215Here we put multi-lingual information about the study courses provided, the application procedure and deadlines.
216>>de<<
217Dieser Text kann von anonymen Benutzern gelesen werden.
218Hier koennen mehrsprachige Informationen fuer Antragsteller hinterlegt werden.'''
219        )
220
221    description_dict = Attribute(
222        """Content as language dictionary with values in HTML format.""")
223
224    startdate = schema.Date(
225        title = _(u'Application Start Date'),
226        required = False,
227        )
228
229    enddate = schema.Date(
230        title = _(u'Application Closing Date'),
231        required = False,
232        )
233
234    strict_deadline = schema.Bool(
235        title = _(u'Forbid additions after deadline (enddate)'),
236        required = False,
237        default = True,
238        )
239
240    def archive(id=None):
241        """Create on-dist archive of applicants stored in this term.
242
243        If id is `None`, all applicants are archived.
244
245        If id contains a single id string, only the respective
246        applicants are archived.
247
248        If id contains a list of id strings all of the respective
249        applicants types are saved to disk.
250        """
251
252    def clear(id=None, archive=True):
253        """Remove applicants of type given by 'id'.
254
255        Optionally archive the applicants.
256
257        If id is `None`, all applicants are archived.
258
259        If id contains a single id string, only the respective
260        applicants are archived.
261
262        If id contains a list of id strings all of the respective
263        applicant types are saved to disk.
264
265        If `archive` is ``False`` none of the archive-handling is done
266        and respective applicants are simply removed from the
267        database.
268        """
269
270class IApplicantsContainerAdd(IApplicantsContainer):
271    """An applicants container contains university applicants.
272    """
273    prefix = schema.Choice(
274        title = _(u'Application Target'),
275        required = True,
276        source = ApplicationTypeSource(),
277        readonly = False,
278        )
279
280    year = schema.Choice(
281        title = _(u'Year of Entrance'),
282        required = True,
283        values = year_range(),
284        readonly = False,
285        )
286
287IApplicantsContainerAdd[
288    'prefix'].order =  IApplicantsContainer['prefix'].order
289IApplicantsContainerAdd[
290    'year'].order =  IApplicantsContainer['year'].order
291
292class IApplicantBaseData(IKofaObject):
293    """The data for an applicant.
294
295    This is a base interface with no field
296    required. For use with processors, forms, etc., please use one of
297    the derived interfaces below, which set more fields to required
298    state, depending on use-case.
299
300    This base interface is also implemented by the
301    :class:`waeup.kofa.students.StudentApplication` class in the
302    students package. Thus, these are the data which are saved after
303    admission.
304    """
305
306    history = Attribute('Object history, a list of messages')
307    state = Attribute('The application state of an applicant')
308    display_fullname = Attribute('The fullname of an applicant')
309    application_date = Attribute('Date of submission, used for export only')
310    password = Attribute('Encrypted password of a applicant')
311    application_number = Attribute('The key under which the record is stored')
312
313    applicant_id = schema.TextLine(
314        title = _(u'Applicant Id'),
315        required = False,
316        readonly = False,
317        )
318    reg_number = TextLineChoice(
319        title = _(u'Registration Number'),
320        readonly = False,
321        required = True,
322        source = contextual_reg_num_source,
323        )
324    #access_code = schema.TextLine(
325    #    title = u'Activation Code',
326    #    required = False,
327    #    readonly = True,
328    #    )
329    firstname = schema.TextLine(
330        title = _(u'First Name'),
331        required = True,
332        )
333    middlename = schema.TextLine(
334        title = _(u'Middle Name'),
335        required = False,
336        )
337    lastname = schema.TextLine(
338        title = _(u'Last Name (Surname)'),
339        required = True,
340        )
341    date_of_birth = schema.Date(
342        title = _(u'Date of Birth'),
343        required = True,
344        )
345    lga = schema.Choice(
346        source = lgas_vocab,
347        title = _(u'State/LGA'),
348        default = 'foreigner',
349        required = False,
350        )
351    sex = schema.Choice(
352        title = _(u'Sex'),
353        source = GenderSource(),
354        required = True,
355        )
356    email = schema.ASCIILine(
357        title = _(u'Email Address'),
358        required = False,
359        constraint=validate_email,
360        )
361    phone = schema.TextLine(
362        title = _(u'Phone'),
363        description = u'',
364        required = False,
365        )
366    course1 = schema.Choice(
367        title = _(u'1st Choice Course of Study'),
368        source = CertificateSource(),
369        required = True,
370        )
371    course2 = schema.Choice(
372        title = _(u'2nd Choice Course of Study'),
373        source = CertificateSource(),
374        required = False,
375        )
376    #school_grades = schema.List(
377    #    title = _(u'School Grades'),
378    #    value_type = ResultEntryField(),
379    #    required = False,
380    #    default = [],
381    #    )
382
383    notice = schema.Text(
384        title = _(u'Notice'),
385        required = False,
386        )
387    screening_venue = schema.TextLine(
388        title = _(u'Screening Venue'),
389        required = False,
390        )
391    screening_score = schema.Int(
392        title = _(u'Screening Score'),
393        required = False,
394        )
395    course_admitted = schema.Choice(
396        title = _(u'Admitted Course of Study'),
397        source = CertificateSource(),
398        required = False,
399        )
400    student_id = schema.TextLine(
401        title = _(u'Student Id'),
402        required = False,
403        readonly = False,
404        )
405    locked = schema.Bool(
406        title = _(u'Form locked'),
407        default = False,
408        )
409
410class IApplicant(IApplicantBaseData):
411    """An applicant.
412
413    This is basically the applicant base data. Here we repeat the
414    fields from base data if we have to set the `required` attribute
415    to True (which is the default).
416    """
417
418    def loggerInfo(ob_class, comment):
419        """Adds an INFO message to the log file
420        """
421
422    def createStudent():
423        """Create a student object from applicatnt data
424        and copy applicant object.
425        """
426
427class IApplicantEdit(IApplicant):
428    """An applicant interface for editing.
429
430    Here we can repeat the fields from base data and set the
431    `required` and `readonly` attributes to True to further restrict
432    the data access. Or we can allow only certain certificates to be
433    selected by choosing the appropriate source.
434
435    We cannot omit fields here. This has to be done in the
436    respective form page.
437    """
438
439    course1 = schema.Choice(
440        title = _(u'1st Choice Course of Study'),
441        source = AppCatCertificateSource(),
442        required = True,
443        )
444    course2 = schema.Choice(
445        title = _(u'2nd Choice Course of Study'),
446        source = AppCatCertificateSource(),
447        required = False,
448        )
449    screening_score = schema.Int(
450        title = _(u'Screening Score'),
451        required = False,
452        readonly = True,
453        )
454    screening_venue = schema.TextLine(
455        title = _(u'Screening Venue'),
456        required = False,
457        readonly = True,
458        )
459    course_admitted = schema.Choice(
460        title = _(u'Admitted Course of Study'),
461        source = CertificateSource(),
462        required = False,
463        readonly = True,
464        )
465    notice = schema.Text(
466        title = _(u'Notice'),
467        required = False,
468        readonly = True,
469        )
470
471class IApplicantUpdateByRegNo(IApplicant):
472    """Representation of an applicant.
473
474    Skip regular reg_number validation if reg_number is used for finding
475    the applicant object.
476    """
477    reg_number = schema.TextLine(
478        title = u'Registration Number',
479        required = False,
480        )
481
482class IApplicantRegisterUpdate(IApplicant):
483    """Representation of an applicant for first-time registration.
484
485    This interface is used when apllicants use the registration page to
486    update their records.
487    """
488    reg_number = schema.TextLine(
489        title = u'Registration Number',
490        required = True,
491        )
492
493    firstname = schema.TextLine(
494        title = _(u'First Name'),
495        required = True,
496        )
497
498    email = schema.ASCIILine(
499        title = _(u'Email Address'),
500        required = True,
501        constraint=validate_email,
502        )
503
504class IApplicantOnlinePayment(IOnlinePayment):
505    """An applicant payment via payment gateways.
506
507    """
508    p_year = schema.Choice(
509        title = _(u'Payment Session'),
510        source = academic_sessions_vocab,
511        required = False,
512        )
513
514IApplicantOnlinePayment['p_year'].order = IApplicantOnlinePayment[
515    'p_year'].order
516
Note: See TracBrowser for help on using the repository browser.