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

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

Remove trash.

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