1 | """General helper functions for the student section. |
---|
2 | """ |
---|
3 | from grok import getSite |
---|
4 | from random import SystemRandom as r |
---|
5 | from waeup.sirp.interfaces import academic_sessions_vocab |
---|
6 | |
---|
7 | def 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 | |
---|
15 | def 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. |
---|
26 | def 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. |
---|
55 | def 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. |
---|
85 | def selectBed(available_beds): |
---|
86 | return available_beds[0] |
---|