source: main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py @ 7017

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

Prepare selection of bed for customization.

  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1"""General helper functions for the student section.
2"""
3from grok import getSite
4from random import SystemRandom as r
5from waeup.sirp.interfaces import academic_sessions_vocab
6
7def generate_student_id(students,letter):
8    if letter == '?':
9        letter= r().choice('ABCDEFGHKLMNPQRSTUVWXY')
10    sid = u"%c%d" % (letter,r().randint(99999,1000000))
11    while sid in students.keys():
12        sid = u"%c%d" % (letter,r().randint(99999,1000000))
13    return sid
14
15def set_returning_data(student):
16    student['studycourse'].current_level += 100
17    student['studycourse'].current_session += 1
18    verdict = student['studycourse'].current_verdict
19    student['studycourse'].current_verdict = '0'
20    student['studycourse'].previous_verdict = verdict
21    return
22
23# To be specified in customization packages, see also view which
24# calls the function.
25# This function is for demonstration and testing only.
26def getPaymentDetails(category, student):
27    d = {}
28    d['p_item'] = u''
29    d['amount'] = 0
30    d['error'] = u''
31    d['p_session'] = student['studycourse'].current_session
32    session = str(d['p_session'])
33    try:
34        academic_session = getSite()['configuration'][session]
35    except KeyError:
36        d['error'] = u'Session configuration object is not available.'
37        return d
38    d['surcharge_1'] = academic_session.surcharge_1
39    d['surcharge_2'] = academic_session.surcharge_2
40    d['surcharge_3'] = academic_session.surcharge_3
41    if category == 'schoolfee':
42        d['amount'] = academic_session.fee_1
43        d['p_item'] = student['studycourse'].certificate.code
44    elif category == 'clearance':
45        d['p_item'] = student['studycourse'].certificate.code
46        d['amount'] = academic_session.fee_2
47    elif category == 'bed_allocation':
48        d['p_item'] = getAccommodationDetails(student)['bt']
49        d['amount'] = academic_session.booking_fee
50    return d
51
52# To be specified in customization packages, see also view which
53# calls the function.
54# This function is for demonstration and testing only.
55def getAccommodationDetails(student):
56    d = {}
57    d['error'] = u''
58    site_confoguration = getSite()['configuration']
59    d['booking_session'] = site_confoguration.accommodation_session
60    d['allowed_states'] = site_confoguration.accommodation_states
61    session = str(d['booking_session'])
62    # Determine bed type
63    studycourse = student['studycourse']
64    entry_session = studycourse.entry_session
65    current_level = studycourse.current_level
66    end_level = studycourse.certificate.end_level
67    if entry_session == getSite()['configuration'].accommodation_session:
68        bt = 'fr'
69    elif current_level >= end_level:
70        bt = 'fi'
71    else:
72        bt = 're'
73    if student.sex == 'f':
74        sex = 'female'
75    else:
76        sex = 'male'
77    special_handling = 'regular'
78    d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
79    return d
80
81# To be specified in customization packages, see also view which
82# calls the function.
83# I the standard configuration we select the first bed found,
84# but can also randomize the selection if we like.
85def selectBed(available_beds):
86    return available_beds[0]
Note: See TracBrowser for help on using the repository browser.