Changeset 14513 for main/waeup.kofa/trunk/src/waeup/kofa/students/reports
- Timestamp:
- 8 Feb 2017, 07:38:30 (8 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students/reports
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/student_payment_statistics.py
r14438 r14513 37 37 38 38 39 def get_student_payment_stats(session, mode, level, breakdown): 39 def get_student_payment_stats(session, mode, level, entry_session, 40 p_session, breakdown): 40 41 """Get payment amounts of students in a certain session, study mode 41 42 and current level. … … 82 83 cat = queryUtility(ICatalog, name="students_catalog") 83 84 result = cat.searchResults(current_session=(session, session)) 84 table = [[0 for x in xrange(2*len(payment_cats))] for y in xrange(len(codes)+1)] 85 table = [[0 for x in xrange(2*len(payment_cats))] 86 for y in xrange(len(codes)+1)] 85 87 mode_groups = getUtility(IKofaUtils).MODE_GROUPS 86 88 for stud in result: 87 if mode != 'All' and stud.current_mode not in mode_groups[mode]: 89 if mode != 'All' and stud.current_mode \ 90 and stud.current_mode not in mode_groups[mode]: 88 91 continue 89 92 if level != 0 and stud.current_level != level: 93 continue 94 if entry_session != 0 and stud.entry_session != entry_session: 90 95 continue 91 96 if getattr(stud, breakdown) not in codes: … … 95 100 for key in stud['payments'].keys(): 96 101 ticket = stud['payments'][key] 97 if ticket.p_category not in payment_cats or\ 98 ticket.p_state != 'paid' or\ 99 ticket.p_session != session: 102 if ticket.p_category not in payment_cats: 103 continue 104 if ticket.p_state != 'paid': 105 continue 106 if p_session != 0 and ticket.p_session != p_session: 100 107 continue 101 108 col = payment_cats.index(ticket.p_category) … … 181 188 session = None 182 189 mode = None 190 entry_session = None 191 p_session = None 183 192 pdfcreator = 'landscape' 184 193 185 def __init__(self, session, mode, level, breakdown, author='System'): 194 def __init__(self, session, mode, level, entry_session, p_session, 195 breakdown, author='System'): 186 196 super(StudentPaymentStatisticsReport, self).__init__( 187 args=[session, mode, breakdown], kwargs={'author':author}) 197 args=[session, mode, level, entry_session, p_session, breakdown], 198 kwargs={'author':author}) 199 self.sessioncode = session 200 self.levelcode = level 201 self.entrysessioncode = entry_session 202 self.psessioncode = p_session 188 203 self.studylevelsource = StudyLevelSource().factory 189 204 self.portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 190 205 self.session = academic_sessions_vocab.getTerm(session).title 191 self.mode = mode 206 if entry_session != 0: 207 self.entry_session = academic_sessions_vocab.getTerm( 208 entry_session).title 209 else: 210 self.entry_session = 'All sessions' 211 if p_session != 0: 212 self.p_session = academic_sessions_vocab.getTerm( 213 p_session).title 214 else: 215 self.p_session = 'All sessions' 216 if mode == 'All': 217 self.mode = 'All study modes' 218 else: 219 self.mode = mode 192 220 if level == 0: 193 self.level = '' 194 else: 195 self.level = translate(self.studylevelsource.getTitle(None, int(level)), 221 self.level = 'All levels' 222 else: 223 self.level = translate( 224 self.studylevelsource.getTitle(None, int(level)), 196 225 'waeup.kofa', target_language=self.portal_language) 197 226 self.breakdown = breakdown … … 199 228 self.creation_dt_string = self.creation_dt.astimezone( 200 229 getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z") 201 self.data = get_student_payment_stats(session, mode, level, breakdown) 230 self.data = get_student_payment_stats( 231 session, mode, level, entry_session, p_session, breakdown) 202 232 203 233 def create_pdf(self, job_id): … … 209 239 STYLE["Normal"]), 210 240 Spacer(1, 12),] 241 pdf_data += [Paragraph( 242 translate( 243 'Study Mode: ${a}<br />' 244 'Academic Session: ${b}<br />Level: ${c}<br />' 245 'Entry Session: ${d}<br />Payment Session: ${e}', 246 mapping = {'a':self.mode, 247 'b':self.session, 248 'c':self.level, 249 'd':self.entry_session, 250 'e':self.p_session, 251 }), 252 STYLE["Normal"]), 253 Spacer(1, 12),] 211 254 pdf_data += [ 212 255 Table(table_data, style=TABLE_STYLE, colWidths=col_widths)] 213 if not self.level: 214 doc_title = translate( 215 _('${a} Student Payments - ${b}', 216 mapping = {'a':self.mode, 'b':self.session})) 217 pdf = creator.create_pdf( 218 pdf_data, None, doc_title, self.author, doc_title + '-' 219 ) 220 else: 221 doc_title = translate( 222 _('${a} Student Payments - ${b} - ${c}', 223 mapping = {'a':self.mode, 'b': self.level, 'c':self.session})) 224 pdf = creator.create_pdf( 225 pdf_data, None, doc_title, self.author, doc_title + '-' 226 ) 256 doc_title = translate(_('Student Payment Statistics')) 257 right_footer = translate( 258 _('${a} Student Payments - ${b} -', 259 mapping = {'a':self.mode, 'b':self.session})) 260 pdf = creator.create_pdf( 261 pdf_data, None, doc_title, self.author, right_footer 262 ) 227 263 return pdf 228 229 264 230 265 @implementer(IReportGenerator) … … 236 271 def generate( 237 272 self, site, session=None, mode=None, 238 level=None, breakdown=None, author=None): 273 level=None, entry_session=None, p_session=None, 274 breakdown=None, author=None): 239 275 result = StudentPaymentStatisticsReport( 240 276 session=session, mode=mode, level=level, 277 entry_session=entry_session, p_session=p_session, 241 278 breakdown=breakdown, author=author) 242 279 return result … … 261 298 262 299 grok.context(StudentPaymentStatisticsReportGenerator) 263 grok.template('student statisticsreportgeneratorpage')300 grok.template('studentpaymentstatisticsreportgeneratorpage') 264 301 265 302 label = _('Create student payment statistics report') 266 303 304 def update( 305 self, CREATE=None, session=None, mode=None, level=None, 306 entry_session=None, p_session=None, breakdown=None): 307 self.parent_url = self.url(self.context.__parent__) 308 self._set_session_values() 309 self._set_mode_values() 310 self._set_level_values() 311 self._set_breakdown_values() 312 if CREATE and session: 313 # create a new report job for students by session and level 314 container = self.context.__parent__ 315 user_id = self.request.principal.id 316 kw = dict( 317 session=int(session), 318 mode=mode, 319 level=int(level), 320 entry_session=int(entry_session), 321 p_session=int(p_session), 322 breakdown=breakdown) 323 self.flash(_('New report is being created in background')) 324 job_id = container.start_report_job( 325 self.generator_name, user_id, kw=kw) 326 ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 327 grok.getSite().logger.info( 328 '%s - report %s created: %s (session=%s, mode=%s, level=%s, ' 329 'entry_session=%s, p_session=%s, breakdown=%s)' % ( 330 ob_class, job_id, self.context.title, 331 session, mode, level, entry_session, p_session, breakdown)) 332 self.redirect(self.parent_url) 333 return 334 return 335 336 def _set_session_values(self): 337 vocab_terms = academic_sessions_vocab.by_value.values() 338 self.sessions = [(x.title, x.token) for x in vocab_terms] 339 self.sessions_plus = [(u'All', 0)] + self.sessions 340 return 267 341 268 342 class StudentPaymentStatisticsReportPDFView(StudentStatisticsReportPDFView): … … 271 345 272 346 def _filename(self): 273 return 'StudentPaymentStatisticsReport_ %s_%s_%s_%s.pdf' % (274 self.context. session, self.context.mode, self.context.level,347 return 'StudentPaymentStatisticsReport_rno%s_%s.pdf' % ( 348 self.context.__name__, 275 349 self.context.creation_dt_string) 276 277 350 278 351 class StudentStatsBreadcrumb(Breadcrumb): -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_student_payment_statistics.py
r14373 r14513 22 22 # ensure we fullfill interface contracts 23 23 obj = StudentPaymentStatisticsReport( 24 2010, 'Undergraduate Full-Time', 0, 'faccode')24 2010, 'Undergraduate Full-Time', 0, 0, 0, 'faccode') 25 25 verifyClass(IStudentPaymentStatisticsReport, StudentPaymentStatisticsReport) 26 26 verifyObject(IStudentPaymentStatisticsReport, obj) … … 30 30 # we can get a table with one student 31 31 result1 = get_student_payment_stats( 32 2010, 'Undergraduate Full-Time', 0, 'faccode')32 2010, 'Undergraduate Full-Time', 0, 0, 0, 'faccode') 33 33 result2 = get_student_payment_stats( 34 2009, 'Undergraduate Full-Time', 0, 'faccode')34 2009, 'Undergraduate Full-Time', 0, 0, 0, 'faccode') 35 35 self.assertEqual( 36 36 result1, … … 55 55 def test_create_pdf(self): 56 56 report = StudentPaymentStatisticsReport( 57 2010, 'Undergraduate Full-Time', 0, 'faccode')57 2010, 'Undergraduate Full-Time', 0, 0, 0, 'faccode') 58 58 result = report.create_pdf('JOB_ID') 59 59 self.assertTrue(result.startswith('%PDF-')) … … 106 106 'application/pdf') 107 107 self.assertTrue( 108 'filename="StudentPaymentStatisticsReport_ 2004_2005_All__'in108 'filename="StudentPaymentStatisticsReport_rno%s' % job_id in 109 109 self.browser.headers['content-disposition']) 110 110 self.assertEqual(len(self.app['reports'].running_report_jobs), 1) 111 job_id = self.app['reports'].running_report_jobs[0][0]112 111 # ... and discarded 113 112 self.browser.open('http://localhost/app/reports') … … 120 119 self.assertTrue( 121 120 'INFO - zope.mgr - students.reports.student_payment_statistics.StudentPaymentStatisticsReportGeneratorPage - ' 122 'report %s created: Student Payment Statistics (session=2004, mode=All, level=0, breakdown=depcode)' 121 'report %s created: Student Payment Statistics ' 122 '(session=2004, mode=All, level=0, entry_session=0, ' 123 'p_session=0, breakdown=depcode)' 123 124 % job_id in logcontent 124 125 ) 125 126 self.assertTrue( 126 127 'INFO - zope.mgr - students.reports.student_payment_statistics.StudentPaymentStatisticsReportPDFView - ' 127 'report %s downloaded: StudentPaymentStatisticsReport_ 2004_2005_All__'128 % job_idin logcontent128 'report %s downloaded: StudentPaymentStatisticsReport_rno%s_' 129 % (job_id, job_id) in logcontent 129 130 ) 130 131 self.assertTrue(
Note: See TracChangeset for help on using the changeset viewer.