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

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

Implement bed booking algorithm (work in progress!).

  • Property svn:keywords set to Id
File size: 2.7 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.
24# This function is for demonstration and testing only.
25def getPaymentDetails(category, student):
26    d = {}
27    d['p_item'] = u''
28    d['amount'] = 0
29    d['error'] = u''
30    d['p_session'] = student['studycourse'].current_session
31    session = str(d['p_session'])
32    try:
33        academic_session = getSite()['configuration'][session]
34    except KeyError:
35        d['error'] = u'Session configuration object is not available.'
36        return d
37    d['surcharge_1'] = academic_session.surcharge_1
38    d['surcharge_2'] = academic_session.surcharge_2
39    d['surcharge_3'] = academic_session.surcharge_3
40    if category == 'schoolfee':
41        d['amount'] = academic_session.fee_1
42        d['p_item'] = student['studycourse'].certificate.code
43    elif category == 'clearance':
44        d['p_item'] = student['studycourse'].certificate.code
45        d['amount'] = academic_session.fee_2
46    elif category == 'bed_allocation':
47        d['p_item'] = getBedType(student)
48        d['amount'] = academic_session.booking_fee
49    return d
50
51# To be specified in customization packages.
52# This function is for demonstration and testing only.
53def getAccommodationDetails(student):
54    d = {}
55    d['error'] = u''
56    site_confoguration = getSite()['configuration']
57    d['booking_session'] = site_confoguration.accommodation_session
58    d['allowed_states'] = site_confoguration.accommodation_states
59    session = str(d['booking_session'])
60    # Determine bed type
61    studycourse = student['studycourse']
62    entry_session = studycourse.entry_session
63    current_level = studycourse.current_level
64    end_level = studycourse.certificate.end_level
65    if entry_session == getSite()['configuration'].accommodation_session:
66        bt = 'fr'
67    elif current_level >= end_level:
68        bt = 'fi'
69    else:
70        bt = 're'
71    if student.sex == 'f':
72        sex = 'female'
73    else:
74        sex = 'male'
75    special_handling = 'regular'
76    d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
77    return d
Note: See TracBrowser for help on using the repository browser.