Changeset 14605 for main/waeup.kofa/trunk/src/waeup/kofa/students/reports/session_results_presentation.py
- Timestamp:
- 7 Mar 2017, 06:51:42 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/session_results_presentation.py
r14601 r14605 33 33 from waeup.kofa.students.reports.student_statistics import ( 34 34 StudentStatisticsReportPDFView) 35 36 37 class ISessionResultsPresentation(ILevelReport):38 39 """ Same interface as for level session results presentation.40 """41 42 def excluded(level_obj):43 """Some universities may add further conditions to exclude44 students from reports. These conditions can be customized in45 this function.46 """47 return False48 49 def get_students(faccode, depcode, certcode, session, level=None):50 """Get students in a certain department, studying a certain programmen51 who registered courses in a certain session at a certain level.52 53 Returns a list of lists of student data tuples.54 """55 site = grok.getSite()56 cat = queryUtility(ICatalog, name="students_catalog")57 if certcode == 'all':58 certcode = None59 result = cat.searchResults(60 depcode = (depcode, depcode), faccode = (faccode, faccode),61 certcode = (certcode, certcode)62 )63 students_utils = getUtility(IStudentsUtils)64 table = list()65 for i in range(len(students_utils.gpa_boundaries)+1):66 # The last list is reserved for students with more than one67 # level in the same session.68 table.append([])69 for stud in result:70 if stud.state == GRADUATED:71 continue72 line = (stud.student_id,73 stud.matric_number,74 stud.display_fullname,75 )76 if level != 0:77 if not stud['studycourse'].has_key(str(level)):78 continue79 level_obj = stud['studycourse'][str(level)]80 if level_obj.level_session != session:81 continue82 if excluded(level_obj):83 continue84 else:85 itemcount = 086 for item in stud['studycourse'].values():87 if item.level_session == session:88 level_obj = item89 itemcount += 190 if itemcount == 0:91 # No level registered in this session92 continue93 if itemcount > 1:94 # Error: more than one level registered in this session95 table[len(students_utils.gpa_boundaries)].append(line)96 continue97 gpaclass = students_utils.getDegreeClassNumber(level_obj)98 table[gpaclass].append(line)99 for i in range(len(students_utils.gpa_boundaries)+1):100 if len(table[i]):101 table[i] = sorted([value for value in table[i]],102 key=lambda value: value[2])103 return table104 105 35 from reportlab.lib import colors 106 36 from reportlab.lib.styles import getSampleStyleSheet … … 127 57 ('ALIGN', (3,1), (-1,-1), 'RIGHT'), 128 58 ] 59 60 class ISessionResultsPresentation(ILevelReport): 61 """ Same interface as for level session results presentation. 62 """ 129 63 130 64 @implementer(ISessionResultsPresentation) … … 141 75 142 76 note = None 77 78 def _excluded(self, level_obj): 79 """Some universities may add further conditions to exclude 80 students from reports. These conditions can be customized in 81 this function. 82 """ 83 return False 84 85 def _get_students(self, faccode, depcode, certcode, session, level=None): 86 """Get students in a certain department, studying a certain programmen 87 who registered courses in a certain session at a certain level. 88 89 Returns a list of lists of student data tuples. 90 """ 91 site = grok.getSite() 92 cat = queryUtility(ICatalog, name="students_catalog") 93 if certcode == 'all': 94 certcode = None 95 result = cat.searchResults( 96 depcode = (depcode, depcode), faccode = (faccode, faccode), 97 certcode = (certcode, certcode) 98 ) 99 students_utils = getUtility(IStudentsUtils) 100 table = list() 101 for i in range(len(students_utils.gpa_boundaries)+1): 102 # The last list is reserved for students with more than one 103 # level in the same session. 104 table.append([]) 105 for stud in result: 106 if stud.state == GRADUATED: 107 continue 108 line = (stud.student_id, 109 stud.matric_number, 110 stud.display_fullname, 111 ) 112 if level != 0: 113 if not stud['studycourse'].has_key(str(level)): 114 continue 115 level_obj = stud['studycourse'][str(level)] 116 if level_obj.level_session != session: 117 continue 118 if self._excluded(level_obj): 119 continue 120 else: 121 itemcount = 0 122 for item in stud['studycourse'].values(): 123 if item.level_session == session: 124 level_obj = item 125 itemcount += 1 126 if itemcount == 0: 127 # No level registered in this session 128 continue 129 if itemcount > 1: 130 # Error: more than one level registered in this session 131 table[len(students_utils.gpa_boundaries)].append(line) 132 continue 133 gpaclass = students_utils.getDegreeClassNumber(level_obj) 134 table[gpaclass].append(line) 135 for i in range(len(students_utils.gpa_boundaries)+1): 136 if len(table[i]): 137 table[i] = sorted([value for value in table[i]], 138 key=lambda value: value[2]) 139 return table 143 140 144 141 def __init__(self, faccode, depcode, certcode, session, level, … … 180 177 self.creation_dt_string = self.creation_dt.astimezone( 181 178 getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z") 182 self.data = get_students(faccode, depcode, certcode, session, level)179 self.data = self._get_students(faccode, depcode, certcode, session, level) 183 180 184 181 def create_pdf(self, job_id):
Note: See TracChangeset for help on using the changeset viewer.