Changeset 14423 for main/waeup.kofa/trunk/src
- Timestamp:
- 21 Jan 2017, 13:45:59 (8 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students/reports
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/browser_templates/levelreportgeneratorpage.pt
r13366 r14423 7 7 </p> 8 8 <br /> 9 <label for="session" i18n:translate="">Department</label> 10 <select name="faccode_depcode" class="form-control half"> 11 <span tal:repeat="items view/faccode_depcodes" tal:omit-tag=""> 9 10 <label for="session" i18n:translate="">Certificate</label> 11 <input id="filterbox" class="kofa-filterbox form-control half" 12 placeholder="Enter search text, then select item below." 13 type="text" i18n:translate=""/> 14 <br /> 15 <select id="filteredselect" name="faccode_depcode_certcode" 16 class="form-control half" size=5> 17 <span tal:repeat="items view/faccode_depcode_certcode" 18 tal:omit-tag=""> 12 19 <option 13 20 tal:define="name python: items[1]; title python: items[0]" … … 19 26 <br /> 20 27 <label for="session">Academic Session</label> 21 <div class="input"> 22 <select name="session" class="form-control half"> 23 <span tal:repeat="items view/sessions" tal:omit-tag=""> 24 <option 25 tal:define="name python: items[1]; title python: items[0]" 26 tal:attributes="value name"> 27 <span tal:replace="title">TITLE</span> 28 </option> 29 </span> 30 </select> 31 </div> 28 <select name="session" class="form-control half"> 29 <span tal:repeat="items view/sessions" tal:omit-tag=""> 30 <option 31 tal:define="name python: items[1]; title python: items[0]" 32 tal:attributes="value name"> 33 <span tal:replace="title">TITLE</span> 34 </option> 35 </span> 36 </select> 32 37 <br /> 33 38 <label for="session">Level</label> -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/level_report.py
r14414 r14423 38 38 faccode = Attribute('Faculty to report') 39 39 depcode = Attribute('Department to report') 40 certcode = Attribute('Certificate to report') 40 41 creation_dt_string = Attribute('Human readable report creation datetime') 41 42 42 def get_students(faccode, depcode, session, level):43 """Get students in a certain department who registered courses44 in a certain session at a certain level.43 def get_students(faccode, depcode, certcode, session, level): 44 """Get students in a certain department, studying a certain programmen 45 who registered courses in a certain session at a certain level. 45 46 46 47 Returns a list of student data tuples. … … 48 49 site = grok.getSite() 49 50 cat = queryUtility(ICatalog, name="students_catalog") 51 if certcode == 'all': 52 certcode = None 50 53 result = cat.searchResults( 51 depcode = (depcode, depcode), faccode = (faccode, faccode) 54 depcode = (depcode, depcode), faccode = (faccode, faccode), 55 certcode = (certcode, certcode) 52 56 ) 53 57 table = [] … … 171 175 faccode = None 172 176 depcode = None 177 certcode = None 173 178 174 179 note = None 175 180 176 def __init__(self, faccode, depcode, session, level, author='System'): 181 def __init__(self, faccode, depcode, certcode, session, level, 182 author='System'): 177 183 super(LevelReport, self).__init__( 178 args=[faccode, depcode, session, level], kwargs={'author':author}) 184 args=[faccode, depcode, certcode, session, level], 185 kwargs={'author':author}) 179 186 site = grok.getSite() 180 187 self.studylevelsource = StudyLevelSource().factory … … 187 194 self.faccode = faccode 188 195 self.depcode = depcode 196 self.certcode = certcode 189 197 self.factitle = site['faculties'][faccode].longtitle 190 198 self.deptitle = site['faculties'][faccode][depcode].longtitle 199 if self.certcode == 'all': 200 self.certtitle = translate( 201 _('All Certificates'), 'waeup.kofa', 202 target_language=self.portal_language) 203 else: 204 self.certtitle = site['faculties'][faccode][ 205 depcode].certificates[certcode].longtitle 191 206 self.author = author 192 207 self.creation_dt_string = self.creation_dt.astimezone( 193 208 getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z") 194 self.data = get_students(faccode, depcode, session, level)209 self.data = get_students(faccode, depcode, certcode, session, level) 195 210 196 211 def create_pdf(self, job_id): … … 206 221 pdf_data += [Paragraph( 207 222 translate( 208 '${a}<br />${b}<br /> Session: ${c}<br />Level: ${d}',209 mapping = {'a':self. factitle,223 '${a}<br />${b}<br />${c}<br /><br />Session: ${d}<br />Level: ${e}', 224 mapping = {'a':self.certtitle, 210 225 'b':self.deptitle, 211 'c':self.session, 212 'd':self.level, 226 'c':self.factitle, 227 'd':self.session, 228 'e':self.level, 213 229 }), 214 230 STYLE["Normal"]), … … 227 243 pdf = creator.create_pdf( 228 244 pdf_data, None, doc_title, self.author, 229 doc_title + ' - %s/%s - %s - %s -' % ( 230 self.faccode, self.depcode, self.levelcode, self.sessioncode), 245 doc_title + ' - %s/%s/%s - %s - %s -' % ( 246 self.faccode, self.depcode, self.certcode, 247 self.levelcode, self.sessioncode), 231 248 note = self.note 232 249 ) … … 239 256 grok.name('level_report') 240 257 241 def generate(self, site, faccode=None, depcode=None, 258 def generate(self, site, faccode=None, depcode=None, certcode=None, 242 259 session=None, level=None, author=None): 243 260 result = LevelReport(faccode=faccode, depcode=depcode, 261 certcode=certcode, 244 262 session=session, level=level, author=author) 245 263 return result … … 270 288 return None 271 289 272 def update(self, CREATE=None, faccode_depcode =None,290 def update(self, CREATE=None, faccode_depcode_certcode=None, 273 291 session=None, level=None): 274 292 self.parent_url = self.url(self.context.__parent__) 275 293 self._set_session_values() 276 294 self._set_level_values() 277 self._set_faccode_depcode_values() 278 if CREATE and session: 295 self._set_faccode_depcode_certcode_values() 296 if not faccode_depcode_certcode: 297 self.flash(_('No certificate selected.'), type="warning") 298 return 299 if CREATE: 279 300 # create a new report job for students by session 280 faccode = faccode_depcode.split('_')[0] 281 depcode = faccode_depcode.split('_')[1] 301 faccode = faccode_depcode_certcode.split('_')[0] 302 depcode = faccode_depcode_certcode.split('_')[1] 303 certcode = faccode_depcode_certcode.split('_')[2] 282 304 container = self.context.__parent__ 283 305 user_id = self.request.principal.id … … 290 312 level=level, 291 313 faccode=faccode, 292 depcode=depcode) 314 depcode=depcode, 315 certcode=certcode) 293 316 self.flash(_('New report is being created in background')) 294 317 job_id = container.start_report_job( … … 296 319 ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 297 320 grok.getSite().logger.info( 298 '%s - report %s created: %s (faculty=%s, department=%s, session=%s, level=%s)' % ( 299 ob_class, job_id, self.context.title, faccode, depcode, session, level)) 321 '%s - report %s created: %s (faculty=%s, department=%s, certificate=%s, session=%s, level=%s)' % ( 322 ob_class, job_id, self.context.title, faccode, depcode, 323 certcode, session, level)) 300 324 self.redirect(self.parent_url) 301 325 return … … 322 346 return 323 347 324 def _set_faccode_depcode_ values(self):325 faccode_depcode s= []348 def _set_faccode_depcode_certcode_values(self): 349 faccode_depcode_certcode = [] 326 350 faculties = grok.getSite()['faculties'] 327 351 for fac in faculties.values(): 328 352 for dep in fac.values(): 329 faccode_depcodes.append( 330 ('%s (%s)' %(dep.longtitle, fac.longtitle), 331 '%s_%s' %(fac.code, dep.code))) 332 self.faccode_depcodes = sorted( 333 faccode_depcodes, key=lambda value: value[0]) 353 faccode_depcode_certcode.append( 354 ('All certificates -- %s, %s)' 355 %(dep.longtitle, fac.longtitle), 356 '%s_%s_all' 357 %(fac.code, dep.code))) 358 for cert in dep.certificates.values(): 359 faccode_depcode_certcode.append( 360 ('%s -- %s, %s)' 361 %(cert.longtitle, dep.longtitle, fac.longtitle), 362 '%s_%s_%s' 363 %(fac.code, dep.code, cert.code))) 364 self.faccode_depcode_certcode = sorted( 365 faccode_depcode_certcode, key=lambda value: value[0]) 334 366 return 335 367 … … 342 374 343 375 def _filename(self): 344 return 'LevelReport_%s_%s_%s_%s_%s .pdf' % (345 self.context.faccode, self.context.depcode, 376 return 'LevelReport_%s_%s_%s_%s_%s_%s.pdf' % ( 377 self.context.faccode, self.context.depcode, self.context.certcode, 346 378 self.context.sessioncode, self.context.levelcode, 347 379 self.context.creation_dt_string) -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/session_results_presentation.py
r14418 r14423 40 40 """ 41 41 42 def get_students(faccode, depcode, session, level=None):43 """Get students in a certain department who registered courses44 in a certain session at a certain level.42 def get_students(faccode, depcode, certcode, session, level=None): 43 """Get students in a certain department, studying a certain programmen 44 who registered courses in a certain session at a certain level. 45 45 46 46 Returns a list of lists of student data tuples. … … 48 48 site = grok.getSite() 49 49 cat = queryUtility(ICatalog, name="students_catalog") 50 if certcode == 'all': 51 certcode = None 50 52 result = cat.searchResults( 51 depcode = (depcode, depcode), faccode = (faccode, faccode) 53 depcode = (depcode, depcode), faccode = (faccode, faccode), 54 certcode = (certcode, certcode) 52 55 ) 53 56 students_utils = getUtility(IStudentsUtils) … … 117 120 faccode = None 118 121 depcode = None 122 certcode = None 119 123 120 124 note = None 121 125 122 def __init__(self, faccode, depcode, session, level, author='System'): 126 def __init__(self, faccode, depcode, certcode, session, level, 127 author='System'): 123 128 super(SessionResultsPresentation, self).__init__( 124 args=[faccode, depcode, session, level], kwargs={'author':author}) 129 args=[faccode, depcode, certcode, session, level], 130 kwargs={'author':author}) 125 131 site = grok.getSite() 126 132 self.studylevelsource = StudyLevelSource().factory … … 136 142 self.faccode = faccode 137 143 self.depcode = depcode 144 self.certcode = certcode 138 145 self.factitle = site['faculties'][faccode].longtitle 139 146 self.deptitle = site['faculties'][faccode][depcode].longtitle 147 if self.certcode == 'all': 148 self.certtitle = translate( 149 _('All Certificates'), 'waeup.kofa', 150 target_language=self.portal_language) 151 else: 152 self.certtitle = site['faculties'][faccode][ 153 depcode].certificates[certcode].longtitle 140 154 self.author = author 141 155 self.creation_dt_string = self.creation_dt.astimezone( 142 156 getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z") 143 self.data = get_students(faccode, depcode, session, level)157 self.data = get_students(faccode, depcode, certcode, session, level) 144 158 145 159 def create_pdf(self, job_id): … … 150 164 STYLE["Normal"]), 151 165 Spacer(1, 12),] 152 pdf_data += [Paragraph('%s<br />%s<br />Session: %s<br />Level: %s' % ( 153 self.factitle, self.deptitle, self.session, self.level), 166 pdf_data += [Paragraph( 167 translate( 168 '${a}<br />${b}<br />${c}<br /><br />Session: ${d}<br />Level: ${e}', 169 mapping = {'a':self.certtitle, 170 'b':self.deptitle, 171 'c':self.factitle, 172 'd':self.session, 173 'e':self.level, 174 }), 154 175 STYLE["Normal"]), 155 176 Spacer(1, 12),] … … 197 218 pdf = creator.create_pdf( 198 219 pdf_data, None, doc_title, self.author, 199 doc_title + ' - %s/%s - %s - %s -' % ( 200 self.faccode, self.depcode, self.levelcode, self.sessioncode), 220 doc_title + ' - %s/%s/%s - %s - %s -' % ( 221 self.faccode, self.depcode, self.certcode, 222 self.levelcode, self.sessioncode), 201 223 note = self.note 202 224 ) … … 209 231 grok.name('session_results_presentation') 210 232 211 def generate(self, site, faccode=None, depcode=None, 233 def generate(self, site, faccode=None, depcode=None, certcode=None, 212 234 session=None, level=None, author=None): 213 235 result = SessionResultsPresentation(faccode=faccode, depcode=depcode, 214 236 certcode=certcode, session=session, level=level, author=author) 215 237 return result 216 238 … … 230 252 grok.template('levelreportgeneratorpage') 231 253 label = _('Create session results presentation') 232 233 def update(self, CREATE=None, faccode_depcode=None,234 session=None, level=None):235 super(SessionResultsPresentationGeneratorPage, self).update(236 CREATE, faccode_depcode ,session, level)237 238 #def _set_level_values(self):239 # vocab_terms = course_levels.by_value.values()240 # self.levels = [('All levels', 'all')] + sorted(241 # [(x.title, x.token) for x in vocab_terms])242 # return243 254 244 255 def _set_level_values(self): … … 260 271 261 272 def _filename(self): 262 return 'SessionResultsPresentation_%s_%s_%s_%s_%s .pdf' % (263 self.context.faccode, self.context.depcode, 273 return 'SessionResultsPresentation_%s_%s_%s_%s_%s_%s.pdf' % ( 274 self.context.faccode, self.context.depcode, self.context.certcode, 264 275 self.context.sessioncode, self.context.levelcode, 265 276 self.context.creation_dt_string) -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_level_report.py
r14392 r14423 18 18 def test_iface(self): 19 19 # ensure we fullfill interface contracts 20 obj = LevelReport('fac1', 'dep1', 2010, 100)20 obj = LevelReport('fac1', 'dep1', 'CERT1', 2010, 100) 21 21 verifyClass(ILevelReport, LevelReport) 22 22 verifyObject(ILevelReport, obj) … … 39 39 self.student['studycourse']['100']['Course3'] = ticket 40 40 # we can get a table with one student 41 result = get_students('fac1', 'dep1', 2010, 100) 41 result = get_students('fac1', 'dep1', 'CERT1', 2010, 100) 42 self.assertEqual(result, 43 [(u'1234', u'Bob Tester', 90, 30, '1.666', 44 'm_Course2_m Course3', '', 90, 30, '1.666', '')]) 45 # same result when selecting all certificates 46 result = get_students('fac1', 'dep1', 'all', 2010, 100) 42 47 self.assertEqual(result, 43 48 [(u'1234', u'Bob Tester', 90, 30, '1.666', … … 72 77 ticket4.credits = 30 73 78 self.student['studycourse']['100']['Course6'] = ticket4 74 report = LevelReport('fac1', 'dep1', 2010, 100)79 report = LevelReport('fac1', 'dep1', 'all', 2010, 100) 75 80 result = report.create_pdf('JOB_ID') 76 81 self.assertTrue(result.startswith('%PDF-')) … … 108 113 self.browser.getControl(name="level").value = ['100'] 109 114 self.browser.getControl(name="session").value = ['2010'] 110 self.browser.getControl(name="faccode_depcode").value = ['fac1_dep1'] 115 self.browser.getControl(name="faccode_depcode_certcode").value = [ 116 'fac1_dep1_CERT1'] 111 117 self.browser.getControl("Create").click() 112 118 return … … 123 129 'application/pdf') 124 130 self.assertTrue( 125 'filename="LevelReport_fac1_dep1_ 2010_100_' in131 'filename="LevelReport_fac1_dep1_CERT1_2010_100_' in 126 132 self.browser.headers['content-disposition']) 127 133 self.assertEqual(len(self.app['reports'].running_report_jobs), 1) … … 137 143 self.assertTrue( 138 144 'INFO - zope.mgr - students.reports.level_report.LevelReportGeneratorPage - ' 139 'report %s created: Level Report (faculty=fac1, department=dep1, session=2010, level=100)' 145 'report %s created: Level Report (faculty=fac1, department=dep1, ' 146 'certificate=CERT1, session=2010, level=100)' 140 147 % job_id in logcontent 141 148 ) 142 149 self.assertTrue( 143 150 'INFO - zope.mgr - students.reports.level_report.LevelReportPDFView - ' 144 'report %s downloaded: LevelReport_fac1_dep1_ 2010_100_'151 'report %s downloaded: LevelReport_fac1_dep1_CERT1_2010_100_' 145 152 % job_id in logcontent 146 153 ) -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_session_results_presentation.py
r14410 r14423 20 20 def test_iface(self): 21 21 # ensure we fullfill interface contracts 22 obj = SessionResultsPresentation('fac1', 'dep1', 2010, 100)22 obj = SessionResultsPresentation('fac1', 'dep1', 'CERT1', 2010, 100) 23 23 verifyClass(ISessionResultsPresentation, SessionResultsPresentation) 24 24 verifyObject(ISessionResultsPresentation, obj) … … 26 26 27 27 def test_get_students(self): 28 result = get_students('fac1', 'dep1', 2010, 100)28 result = get_students('fac1', 'dep1', 'CERT1', 2010, 100) 29 29 self.assertEqual(result, 30 30 [[], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')], []]) … … 32 32 33 33 def test_get_students_at_all_levels(self): 34 result = get_students('fac1', 'dep1', 2010, 0) 34 result = get_students('fac1', 'dep1', 'CERT1', 2010, 0) 35 self.assertEqual(result, 36 [[], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')], []]) 37 return 38 39 def test_get_students_all_certs(self): 40 result = get_students('fac1', 'dep1', 'all', 2010, 100) 35 41 self.assertEqual(result, 36 42 [[], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')], []]) … … 43 49 studylevel.level_session = 2010 44 50 self.student['studycourse']['200'] = studylevel 45 result = get_students('fac1', 'dep1', 2010, 0)51 result = get_students('fac1', 'dep1', 'CERT1', 2010, 0) 46 52 self.assertEqual(result, 47 53 [[], [], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')]]) … … 50 56 def test_get_students_without_scores(self): 51 57 self.student['studycourse']['100']['Course1'].score = None 52 result = get_students('fac1', 'dep1', 2010, 0)58 result = get_students('fac1', 'dep1', 'CERT1', 2010, 0) 53 59 self.assertEqual(result, 54 60 [[], [], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')]]) … … 56 62 def test_get_students_without_level_in_session(self): 57 63 self.student['studycourse']['100'].level_session = 2011 58 result = get_students('fac1', 'dep1', 2010)64 result = get_students('fac1', 'dep1', 'CERT1', 2010) 59 65 self.assertEqual(result, 60 66 [[], [], [], [], [], [], []]) … … 62 68 63 69 def test_create_pdf(self): 64 report = SessionResultsPresentation('fac1', 'dep1', 2010, 100)70 report = SessionResultsPresentation('fac1', 'dep1', 'CERT1', 2010, 100) 65 71 result = report.create_pdf('JOB_ID') 66 72 self.assertTrue(result.startswith('%PDF-')) … … 80 86 self.student['studycourse']['620'] = studylevel 81 87 self.student['studycourse']['620']['Course2'] = ticket 82 report = SessionResultsPresentation('fac1', 'dep1', 2013, 620)88 report = SessionResultsPresentation('fac1', 'dep1', 'CERT1', 2013, 620) 83 89 result = report.create_pdf('JOB_ID') 84 90 self.assertTrue(result.startswith('%PDF-')) … … 101 107 self.student['studycourse']['200'] = studylevel 102 108 self.student['studycourse']['200']['Course2'] = ticket 103 report = SessionResultsPresentation('fac1', 'dep1', 2010, 0)109 report = SessionResultsPresentation('fac1', 'dep1', 'CERT1', 2010, 0) 104 110 result = report.create_pdf('JOB_ID') 105 111 self.assertTrue(result.startswith('%PDF-')) … … 137 143 self.browser.getControl(name="level").value = [level] 138 144 self.browser.getControl(name="session").value = ['2010'] 139 self.browser.getControl(name="faccode_depcode ").value = ['fac1_dep1']145 self.browser.getControl(name="faccode_depcode_certcode").value = ['fac1_dep1_CERT1'] 140 146 self.browser.getControl("Create").click() 141 147 return … … 152 158 'application/pdf') 153 159 self.assertTrue( 154 'filename="SessionResultsPresentation_fac1_dep1_ 2010_100_' in160 'filename="SessionResultsPresentation_fac1_dep1_CERT1_2010_100_' in 155 161 self.browser.headers['content-disposition']) 156 162 self.assertEqual(len(self.app['reports'].running_report_jobs), 1) … … 166 172 self.assertTrue( 167 173 'INFO - zope.mgr - students.reports.session_results_presentation.SessionResultsPresentationGeneratorPage - ' 168 'report %s created: Session Results Presentation (faculty=fac1, department=dep1, session=2010, level=100)' 174 'report %s created: Session Results Presentation ' 175 '(faculty=fac1, department=dep1, certificate=CERT1, session=2010, level=100)' 169 176 % job_id in logcontent 170 177 ) 171 178 self.assertTrue( 172 179 'INFO - zope.mgr - students.reports.session_results_presentation.SessionResultsPresentationPDFView - ' 173 'report %s downloaded: SessionResultsPresentation_fac1_dep1_ 2010_100_'180 'report %s downloaded: SessionResultsPresentation_fac1_dep1_CERT1_2010_100_' 174 181 % job_id in logcontent 175 182 ) … … 192 199 'application/pdf') 193 200 self.assertTrue( 194 'filename="SessionResultsPresentation_fac1_dep1_ 2010_0_' in201 'filename="SessionResultsPresentation_fac1_dep1_CERT1_2010_0_' in 195 202 self.browser.headers['content-disposition']) 196 203 self.assertEqual(len(self.app['reports'].running_report_jobs), 1) … … 206 213 self.assertTrue( 207 214 'INFO - zope.mgr - students.reports.session_results_presentation.SessionResultsPresentationGeneratorPage - ' 208 'report %s created: Session Results Presentation (faculty=fac1, department=dep1, session=2010, level=0)' 215 'report %s created: Session Results Presentation ' 216 '(faculty=fac1, department=dep1, certificate=CERT1, session=2010, level=0)' 209 217 % job_id in logcontent 210 218 ) 211 219 self.assertTrue( 212 220 'INFO - zope.mgr - students.reports.session_results_presentation.SessionResultsPresentationPDFView - ' 213 'report %s downloaded: SessionResultsPresentation_fac1_dep1_ 2010_0_'221 'report %s downloaded: SessionResultsPresentation_fac1_dep1_CERT1_2010_0_' 214 222 % job_id in logcontent 215 223 )
Note: See TracChangeset for help on using the changeset viewer.