[6651] | 1 | """General helper functions for the student section. |
---|
| 2 | """ |
---|
[6920] | 3 | from grok import getSite |
---|
[6662] | 4 | from random import SystemRandom as r |
---|
[6915] | 5 | from waeup.sirp.interfaces import academic_sessions_vocab |
---|
[6651] | 6 | |
---|
[6749] | 7 | def 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 | |
---|
| 15 | def 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 | |
---|
[7004] | 23 | # To be specified in customization packages, see also view which |
---|
| 24 | # calls the function. |
---|
[6920] | 25 | # This function is for demonstration and testing only. |
---|
[6876] | 26 | def getPaymentDetails(category, student): |
---|
[6994] | 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']) |
---|
[6920] | 33 | try: |
---|
| 34 | academic_session = getSite()['configuration'][session] |
---|
| 35 | except KeyError: |
---|
[6994] | 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 |
---|
[6920] | 41 | if category == 'schoolfee': |
---|
[6994] | 42 | d['amount'] = academic_session.fee_1 |
---|
| 43 | d['p_item'] = student['studycourse'].certificate.code |
---|
[6929] | 44 | elif category == 'clearance': |
---|
[6994] | 45 | d['p_item'] = student['studycourse'].certificate.code |
---|
| 46 | d['amount'] = academic_session.fee_2 |
---|
| 47 | elif category == 'bed_allocation': |
---|
[7004] | 48 | d['p_item'] = getAccommodationDetails(student)['bt'] |
---|
[6994] | 49 | d['amount'] = academic_session.booking_fee |
---|
| 50 | return d |
---|
[6992] | 51 | |
---|
[7004] | 52 | # To be specified in customization packages, see also view which |
---|
| 53 | # calls the function. |
---|
[6992] | 54 | # This function is for demonstration and testing only. |
---|
| 55 | def getAccommodationDetails(student): |
---|
[6994] | 56 | d = {} |
---|
| 57 | d['error'] = u'' |
---|
[6993] | 58 | site_confoguration = getSite()['configuration'] |
---|
[6994] | 59 | d['booking_session'] = site_confoguration.accommodation_session |
---|
| 60 | d['allowed_states'] = site_confoguration.accommodation_states |
---|
| 61 | session = str(d['booking_session']) |
---|
[6996] | 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) |
---|
[6994] | 79 | return d |
---|
[7004] | 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] |
---|