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

Last change on this file since 6999 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
RevLine 
[6651]1"""General helper functions for the student section.
2"""
[6920]3from grok import getSite
[6662]4from random import SystemRandom as r
[6915]5from waeup.sirp.interfaces import academic_sessions_vocab
[6651]6
[6749]7def generate_student_id(students,letter):
[6651]8    if letter == '?':
[6664]9        letter= r().choice('ABCDEFGHKLMNPQRSTUVWXY')
10    sid = u"%c%d" % (letter,r().randint(99999,1000000))
[6749]11    while sid in students.keys():
[6664]12        sid = u"%c%d" % (letter,r().randint(99999,1000000))
[6662]13    return sid
[6742]14
15def set_returning_data(student):
16    student['studycourse'].current_level += 100
17    student['studycourse'].current_session += 1
18    verdict = student['studycourse'].current_verdict
[6804]19    student['studycourse'].current_verdict = '0'
[6742]20    student['studycourse'].previous_verdict = verdict
21    return
[6876]22
[6920]23# To be specified in customization packages.
24# This function is for demonstration and testing only.
[6876]25def getPaymentDetails(category, student):
[6994]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'])
[6920]32    try:
33        academic_session = getSite()['configuration'][session]
34    except KeyError:
[6994]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
[6920]40    if category == 'schoolfee':
[6994]41        d['amount'] = academic_session.fee_1
42        d['p_item'] = student['studycourse'].certificate.code
[6929]43    elif category == 'clearance':
[6994]44        d['p_item'] = student['studycourse'].certificate.code
45        d['amount'] = academic_session.fee_2
46    elif category == 'bed_allocation':
[6996]47        d['p_item'] = getBedType(student)
[6994]48        d['amount'] = academic_session.booking_fee
49    return d
[6992]50
51# To be specified in customization packages.
52# This function is for demonstration and testing only.
53def getAccommodationDetails(student):
[6994]54    d = {}
55    d['error'] = u''
[6993]56    site_confoguration = getSite()['configuration']
[6994]57    d['booking_session'] = site_confoguration.accommodation_session
58    d['allowed_states'] = site_confoguration.accommodation_states
59    session = str(d['booking_session'])
[6996]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)
[6994]77    return d
Note: See TracBrowser for help on using the repository browser.