source: main/waeup.sirp/trunk/src/waeup/sirp/students/vocabularies.py @ 6783

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

Remove trash.

Rename entry_session_vocab and other academic session related things because of the ambiguity of the term 'session'. We should always use one of the following terms: entry session, current session or academic session.

  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1"""Vocabularies and sources for the student section.
2"""
3from datetime import datetime
4from zope.component import getUtility
5from zope.catalog.interfaces import ICatalog
6from zc.sourcefactory.basic import BasicSourceFactory
7from zc.sourcefactory.contextual import BasicContextualSourceFactory
8from waeup.sirp.interfaces import SimpleWAeUPVocabulary
9from waeup.sirp.students.lgas import LGAS
10from waeup.sirp.university.vocabularies import course_levels
11
12def year_range():
13    curr_year = datetime.now().year
14    return range(curr_year - 2, curr_year + 5)
15
16def academic_sessions():
17    curr_year = datetime.now().year
18    year_range = range(curr_year - 10, curr_year + 2)
19    return [('%s/%s' % (year,year+1), year) for year in year_range]
20
21academic_sessions_vocab = SimpleWAeUPVocabulary(*academic_sessions())
22
23lgas_vocab = SimpleWAeUPVocabulary(
24    *sorted([(x[1],x[0]) for x in LGAS]))
25
26def study_levels(studycourse):
27    try:
28        start_level = int(studycourse.certificate.start_level)
29        end_level = int(studycourse.certificate.end_level)
30        levels = [level for level in range(start_level,end_level+200,10)
31                   if level % 100 < 30 and level < end_level + 120]
32        return levels
33    except AttributeError:
34        return []
35   
36class StudyLevelSource(BasicContextualSourceFactory):
37    """The StudyLevelSource is based on and extends the
38    course_levels vocabulary defined in the university package.
39    Repeating study levels are denoted by increments of 10, the
40    first spillover level by the certificate's end level plus 100
41    and the second spillover level by the end level plus 110.
42    """
43    def getValues(self, context):
44        return study_levels(context)
45
46    def getToken(self, context, value):
47        return str(value)
48
49    def getTitle(self, context, value):
50        end_level = int(context.certificate.end_level)
51        level,repeat = divmod(value, 100)
52        level = level * 100
53        repeat = repeat//10
54        title = course_levels.by_value[level].title
55        if level > end_level and repeat:
56            title = course_levels.by_value[level-100].title
57            title = "%s 2nd spillover" % title
58        elif level > end_level:
59            title = course_levels.by_value[level-100].title
60            title = "%s spillover" % title
61        elif repeat:
62            title = "%s on %d. probation" % (title, repeat)
63        return title
64
65verdicts = SimpleWAeUPVocabulary(
66    ('Not set',''),
67    ('Successful student','A'),
68    ('Student with carryover courses','B'),
69    ('Student on probation','C'),
70    ('Student who were previously on probation','E'),
71    ('Medical case','F'),
72    ('Absent from examination','G'),
73    ('Withheld results','H'),
74    ('Expelled/rusticated/suspended student','I'),
75    ('Temporary withdrawn from the university','J'),
76    ('Unregistered student','K'),
77    ('Referred student','L'),
78    ('Reinstatement','M'),
79    ('Student on transfer','N'),
80    ('NCE-III repeater','O'),
81    ('New 300 level student','X'),
82    ('No previous verdict','Y'),
83    ('Successful student (provisional)','Z'),
84    ('First Class','A1'),
85    ('Second Class Upper','A2'),
86    ('Second Class Lower','A3'),
87    ('Third Class','A4'),
88    ('Pass','A5'),
89    ('Distinction','A6'),
90    ('Credit','A7'),
91    ('Merit','A8'),
92    )
93
94
95class CertificateSource(BasicContextualSourceFactory):
96    """A certificate source delivers all certificates provided
97    in the portal.
98    """
99    def getValues(self, context):
100        catalog = getUtility(ICatalog, name='certificates_catalog')
101        return sorted(list(
102                catalog.searchResults(
103                    code=('', 'z*'))),
104                    key=lambda value: value.code)
105
106    def getToken(self, context, value):
107        return value.code
108
109    def getTitle(self, context, value):
110        return "%s - %s" % (value.code, value.title[:64])
111
112
113class GenderSource(BasicSourceFactory):
114    """A gender source delivers basically a mapping
115       ``{'m': 'Male', 'f': 'Female'}``
116
117       Using a source, we make sure that the tokens (which are
118       stored/expected for instance from CSV files) are something one
119       can expect and not cryptic IntIDs.
120    """
121    def getValues(self):
122        return ['m', 'f']
123
124    def getToken(self, value):
125        return value[0].lower()
126
127    def getTitle(self, value):
128        if value == 'm':
129            return 'Male'
130        if value == 'f':
131            return 'Female'
Note: See TracBrowser for help on using the repository browser.