[845] | 1 | ## Script (Python) "getStudyCourseInfo" |
---|
[723] | 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=student=None |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
[805] | 10 | # $Id: getStudyCourseInfo.py 2876 2007-12-07 13:55:43Z joachim $ |
---|
[723] | 11 | """ |
---|
| 12 | return Info about the Students StudyCourse |
---|
| 13 | """ |
---|
[2876] | 14 | import DateTime |
---|
[2855] | 15 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
[1783] | 16 | |
---|
| 17 | mtool = context.portal_membership |
---|
| 18 | if mtool.isAnonymousUser(): |
---|
| 19 | return None |
---|
| 20 | |
---|
[1494] | 21 | try: |
---|
| 22 | from Products.zdb import set_trace |
---|
| 23 | except: |
---|
| 24 | def set_trace(): |
---|
| 25 | pass |
---|
[2876] | 26 | import logging |
---|
| 27 | logger = logging.getLogger('Skins.getStudyCourseInfo') |
---|
[1494] | 28 | |
---|
[723] | 29 | request = context.REQUEST |
---|
| 30 | |
---|
[1490] | 31 | wftool = context.portal_workflow |
---|
[723] | 32 | path_info = request.get('PATH_INFO').split('/') |
---|
| 33 | |
---|
| 34 | info = {} |
---|
[1380] | 35 | info['is_so'] = context.isSectionOfficer() |
---|
[1650] | 36 | info['action'] = "%s" % context.absolute_url() |
---|
[723] | 37 | info['choosen_ids'] = request.get('ids',[]) |
---|
[1380] | 38 | course = info['doc'] = context.getContent() |
---|
| 39 | student_id = context.getStudentId() |
---|
[2876] | 40 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
| 41 | if not student_record: |
---|
[1380] | 42 | return None |
---|
[2876] | 43 | info['student'] = student_record |
---|
| 44 | cert_id = student_record.course |
---|
| 45 | # logger.info("before search") |
---|
| 46 | # starttime = DateTime.DateTime().timeTime() |
---|
| 47 | # res = context.portal_catalog_real.evalAdvancedQuery(Eq('id', cert_id)) # & |
---|
| 48 | # Eq('portal_type', "Certificate")) |
---|
| 49 | # logger.info("searchtime %f" % (DateTime.DateTime().timeTime() - starttime)) |
---|
| 50 | # if True: |
---|
| 51 | # #info['cert_id'] = cert_id |
---|
| 52 | # # brain = res[0] |
---|
| 53 | # # ci['title'] = brain.Title |
---|
| 54 | # # pl = brain.getPath().split('/') |
---|
| 55 | # # ci['faculty'] = pl[-4] |
---|
| 56 | # # ci['department'] = pl[-3] |
---|
| 57 | # ci['study_course'] = student_record.course |
---|
| 58 | # ci['faculty'] = student_record.faculty |
---|
| 59 | # ci['department'] = student_record.department |
---|
| 60 | # info['course_doc'] = ci |
---|
| 61 | # else: |
---|
| 62 | # info['cert_id'] = 'N/A' |
---|
| 63 | # ci['study_course'] = 'N/A' |
---|
| 64 | # ci['title'] = 'N/A' |
---|
| 65 | # ci['faculty'] = 'N/A' |
---|
| 66 | # ci['department'] = 'N/A' |
---|
| 67 | # info['course_doc'] = ci |
---|
[1380] | 68 | ci = {} |
---|
[2876] | 69 | ci['study_course'] = student_record.course |
---|
| 70 | ci['faculty'] = student_record.faculty |
---|
| 71 | ci['department'] = student_record.department |
---|
| 72 | info['course_doc'] = ci |
---|
[2010] | 73 | |
---|
[723] | 74 | items = [] |
---|
[2483] | 75 | |
---|
| 76 | if hasattr(course,'current_verdict'): |
---|
| 77 | try: |
---|
| 78 | info['verdict'] = context.portal_vocabularies.verdicts.get(course.current_verdict).upper() |
---|
| 79 | except: |
---|
| 80 | info['verdict'] = course.current_verdict |
---|
| 81 | else: |
---|
| 82 | info['verdict'] = '' |
---|
| 83 | |
---|
| 84 | if hasattr(course,'previous_verdict'): |
---|
| 85 | try: |
---|
| 86 | previous_verdict = course.previous_verdict |
---|
| 87 | info['previous_verdict'] = context.portal_vocabularies.verdicts.get(course.previous_verdict).upper() |
---|
| 88 | except: |
---|
| 89 | info['previous_verdict'] = course.previous_verdict |
---|
| 90 | else: |
---|
| 91 | info['previous_verdict'] = '' |
---|
| 92 | previous_verdict = '' |
---|
| 93 | |
---|
| 94 | |
---|
[2876] | 95 | current_level = student_record.level |
---|
[1492] | 96 | levels = context.objectIds() |
---|
| 97 | review_state = wftool.getInfoFor(context,'review_state',None) |
---|
[2876] | 98 | student_review_state = student_record.review_state |
---|
[2752] | 99 | #if review_state != 'content_addable' and student_review_state == 'school_fee_paid': #and context.isStudent(): |
---|
| 100 | # wftool.doActionFor(context,'close_for_edit') |
---|
[2674] | 101 | |
---|
[2664] | 102 | has_paid = student_review_state == 'school_fee_paid' |
---|
| 103 | |
---|
| 104 | may_register = has_paid and\ |
---|
| 105 | current_level not in levels and\ |
---|
| 106 | (previous_verdict in ('A','B','C','F','J','L','M') or\ |
---|
[2674] | 107 | current_level == '100' or\ |
---|
[2876] | 108 | (student_record.mode.startswith('de') and current_level == '200')) |
---|
[2678] | 109 | |
---|
[2674] | 110 | missing_data = has_paid and\ |
---|
| 111 | current_level not in levels and\ |
---|
[2876] | 112 | not (previous_verdict or student_record.level) and\ |
---|
[2674] | 113 | not (current_level == '100' or\ |
---|
[2876] | 114 | (student_record.mode.startswith('de') and current_level == '200')) |
---|
[2664] | 115 | |
---|
[2674] | 116 | info['missing_data'] = missing_data |
---|
[1492] | 117 | levels.sort() |
---|
| 118 | info['create_level'] = None |
---|
[2640] | 119 | student_levels_voc = context.portal_vocabularies.student_levels |
---|
[2678] | 120 | if may_register: |
---|
[1492] | 121 | info['create_level'] = current_level |
---|
[2640] | 122 | info['create_level_str'] = student_levels_voc.get(current_level) |
---|
[1492] | 123 | for l in levels: |
---|
| 124 | row = {} |
---|
| 125 | row['id'] = l |
---|
[2640] | 126 | #row['title'] = "Level %s" % l |
---|
| 127 | row['title'] = student_levels_voc.get(l) |
---|
[1492] | 128 | row['url'] = "%s/%s" % (context.absolute_url(),l) |
---|
| 129 | items.append(row) |
---|
[1380] | 130 | |
---|
[723] | 131 | info['items'] = items |
---|
[1504] | 132 | |
---|
[2483] | 133 | |
---|
| 134 | |
---|
[723] | 135 | return info |
---|
[1504] | 136 | |
---|