"""General helper functions for the student section. """ from grok import getSite from random import SystemRandom as r from waeup.sirp.interfaces import academic_sessions_vocab def generate_student_id(students,letter): if letter == '?': letter= r().choice('ABCDEFGHKLMNPQRSTUVWXY') sid = u"%c%d" % (letter,r().randint(99999,1000000)) while sid in students.keys(): sid = u"%c%d" % (letter,r().randint(99999,1000000)) return sid def set_returning_data(student): student['studycourse'].current_level += 100 student['studycourse'].current_session += 1 verdict = student['studycourse'].current_verdict student['studycourse'].current_verdict = '0' student['studycourse'].previous_verdict = verdict return # To be specified in customization packages, see also view which # calls the function. # This function is for demonstration and testing only. def getPaymentDetails(category, student): d = {} d['p_item'] = u'' d['amount'] = 0 d['error'] = u'' d['p_session'] = student['studycourse'].current_session session = str(d['p_session']) try: academic_session = getSite()['configuration'][session] except KeyError: d['error'] = u'Session configuration object is not available.' return d d['surcharge_1'] = academic_session.surcharge_1 d['surcharge_2'] = academic_session.surcharge_2 d['surcharge_3'] = academic_session.surcharge_3 if category == 'schoolfee': d['amount'] = academic_session.fee_1 d['p_item'] = student['studycourse'].certificate.code elif category == 'clearance': d['p_item'] = student['studycourse'].certificate.code d['amount'] = academic_session.fee_2 elif category == 'bed_allocation': d['p_item'] = getAccommodationDetails(student)['bt'] d['amount'] = academic_session.booking_fee return d # To be specified in customization packages, see also view which # calls the function. # This function is for demonstration and testing only. def getAccommodationDetails(student): d = {} d['error'] = u'' site_confoguration = getSite()['configuration'] d['booking_session'] = site_confoguration.accommodation_session d['allowed_states'] = site_confoguration.accommodation_states session = str(d['booking_session']) # Determine bed type studycourse = student['studycourse'] entry_session = studycourse.entry_session current_level = studycourse.current_level end_level = studycourse.certificate.end_level if entry_session == getSite()['configuration'].accommodation_session: bt = 'fr' elif current_level >= end_level: bt = 'fi' else: bt = 're' if student.sex == 'f': sex = 'female' else: sex = 'male' special_handling = 'regular' d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt) return d # To be specified in customization packages, see also view which # calls the function. # I the standard configuration we select the first bed found, # but can also randomize the selection if we like. def selectBed(available_beds): return available_beds[0]