source: main/waeup.sirp/trunk/src/waeup/sirp/applicants/vocabularies.py @ 7344

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

Do not store a reference to a certificate but a dictionary with the code, title, department title and faculty title of certificates. In this way we can preserve the information even if the certificate has been removed.

The assignment of dynamic roles is not necessary in the application section. We can assign local roles in applicants containers. That's sufficient.

  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1## $Id: vocabularies.py 7341 2011-12-14 13:38:59Z 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"""Vocabularies and sources for the application section.
19"""
20from zope.component import getUtility
21from zope.catalog.interfaces import ICatalog
22from waeup.sirp.interfaces import SimpleSIRPVocabulary
23from zc.sourcefactory.contextual import BasicContextualSourceFactory
24
25#: Types of applications we support.
26APPLICATION_TYPES = (
27    ('General Studies', 'app','APP'),
28    ('Pre-NCE Programme', 'prence','PRE'),
29    ('Post UME Screening Test', 'pume','PUME'),
30    ('Post UDE Screening', 'pude','PUDE'),
31    ('Part Time Degree in Education', 'sandwich','SAND'),
32    ('Part-Time Degree Programmes', 'pt','PTP'),
33    ('Diploma Programmes', 'dp','DPP'),
34    ('PCE Screening', 'pce','PCE'),
35    ('Certificate Programmes', 'ct','CTP'),
36    ('Common Entry Screening Test', 'cest','CEST'),
37    )
38
39#: A :class:`waeup.sirp.interfaces.SimpleSIRPVocabulary` of supported
40#: application or screening types.
41application_types_vocab = SimpleSIRPVocabulary(
42    *[(x[0],x[1]) for x in APPLICATION_TYPES])
43application_pins_vocab = SimpleSIRPVocabulary(
44    *[(u"%s (%s)" % (x[2],x[0]),x[2]) for x in APPLICATION_TYPES])
45
46class CertificateTitleSource(BasicContextualSourceFactory):
47    """A certificate title source delivers all certificates titles provided
48    in the portal.
49    """
50    def getValues(self, context):
51        catalog = getUtility(ICatalog, name='certificates_catalog')
52        certs = list(catalog.searchResults(code=('', 'z*')))
53        certs = [dict(
54            code = i.code,
55            title = i.title,
56            dep = i.__parent__.__parent__.longtitle(),
57            fac = i.__parent__.__parent__.__parent__.longtitle()
58            ) for i in certs]
59        return sorted(certs, key=lambda value: value['code'])
60
61    def getToken(self, context, value):
62        return value['code']
63
64    def getTitle(self, context, value):
65        return "%s - %s" % (value['code'], value['title'][:64])
66
67class AppCatCertificateTitleSource(CertificateTitleSource):
68    """An application certificate source delivers all course titles which belong to
69    a certain application_category.
70    """
71    def getValues(self, context):
72        appcat = context.__parent__.application_category
73        catalog = getUtility(ICatalog, name='certificates_catalog')
74        certs = list(catalog.searchResults(code=('', 'z*'),
75            application_category=(appcat,appcat)))
76        certs = [dict(
77            code = i.code,
78            title = i.title,
79            dep = i.__parent__.__parent__.longtitle(),
80            fac = i.__parent__.__parent__.__parent__.longtitle()
81            ) for i in certs]
82        return sorted(certs, key=lambda value: value['code'])
83
84
Note: See TracBrowser for help on using the repository browser.