Changeset 12897 for main/waeup.kofa/trunk/src/waeup/kofa/students
- Timestamp:
- 1 May 2015, 14:32:09 (10 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students/reports
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/browser_templates/studentstatisticsreportgeneratorpage.pt
r12515 r12897 40 40 </select> 41 41 <br /> 42 <label for="level">Current Level</label> 43 <select name="level" i18n:translate="" class="form-control half"> 44 <span tal:repeat="items view/levels" tal:omit-tag=""> 45 <option 46 tal:define="name python: items[1]; title python: items[0]" 47 tal:attributes="value name"> 48 <span tal:replace="title">TITLE</span> 49 </option> 50 </span> 51 </select> 52 <br /> 42 53 <input i18n:translate="" type="submit" class="btn btn-primary" 43 54 name="CREATE" value="Create" /> -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/level_report.py
r11254 r12897 17 17 ## 18 18 import grok 19 from zope.i18n import translate 19 20 from zope.catalog.interfaces import ICatalog 20 21 from zope.component import queryUtility, getUtility … … 26 27 from waeup.kofa.reports import IReport 27 28 from waeup.kofa.browser.pdf import get_signature_tables 29 from waeup.kofa.students.vocabularies import StudyLevelSource 28 30 from waeup.kofa.students.reports.student_statistics import ( 29 31 StudentStatisticsReportPDFView) … … 174 176 pdf_data += [ 175 177 Table(table_data, style=TABLE_STYLE, colWidths=col_widths)] 176 doc_title = 'Level Report'178 doc_title = translate(_('Level Report')) 177 179 178 180 pdf_data.append(Spacer(1, 40)) … … 183 185 pdf = creator.create_pdf( 184 186 pdf_data, None, doc_title, self.author, 185 'Level Report%s/%s/%s/%s' % (187 doc_title + ' %s/%s/%s/%s' % ( 186 188 self.faccode, self.depcode, self.levelcode, self.sessioncode) 187 189 ) … … 262 264 return 263 265 266 #def _set_level_values(self): 267 # vocab_terms = course_levels.by_value.values() 268 # self.levels = sorted([(x.title, x.token) for x in vocab_terms]) 269 # return 270 264 271 def _set_level_values(self): 265 vocab_terms = course_levels.by_value.values() 266 self.levels = sorted([(x.title, x.token) for x in vocab_terms]) 272 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 273 studylevelsource = StudyLevelSource().factory 274 self.levels = [] 275 for code in studylevelsource.getValues(None): 276 title = translate(studylevelsource.getTitle(None, code), 277 'waeup.kofa', target_language=portal_language) 278 self.levels.append((title, code)) 267 279 return 268 280 -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/student_payment_statistics.py
r12619 r12897 17 17 ## 18 18 import grok 19 from zope.i18n import translate 19 20 from zope.catalog.interfaces import ICatalog 20 21 from zope.component import queryUtility, getUtility … … 23 24 IKofaUtils, 24 25 academic_sessions_vocab, registration_states_vocab) 26 from waeup.kofa.students.vocabularies import StudyLevelSource 25 27 from waeup.kofa.interfaces import MessageFactory as _ 26 28 from waeup.kofa.reports import IReport … … 31 33 session = Attribute('Session to report') 32 34 mode = Attribute('Study modes group to report') 35 level = Attribute('Level to report') 33 36 creation_dt_string = Attribute('Human readable report creation datetime') 34 37 35 38 36 def get_student_payment_stats(session, mode, breakdown): 37 """Get students in a certain session and study mode. 39 def get_student_payment_stats(session, mode, level, breakdown): 40 """Get payment amounts of students in a certain session, study mode 41 and current level. 38 42 39 43 Returns a table ordered by code (faculty or department, one per row) and … … 83 87 if mode != 'All' and stud.current_mode not in mode_groups[mode]: 84 88 continue 89 if level != 0 and stud.current_level != level: 90 continue 85 91 if getattr(stud, breakdown) not in codes: 86 92 # studs can have a faccode ``None`` … … 176 182 mode = None 177 183 178 def __init__(self, session, mode, breakdown, author='System'):184 def __init__(self, session, mode, level, breakdown, author='System'): 179 185 super(StudentPaymentStatisticsReport, self).__init__( 180 186 args=[session, mode, breakdown], kwargs={'author':author}) 187 self.studylevelsource = StudyLevelSource().factory 188 self.portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 181 189 self.session = academic_sessions_vocab.getTerm(session).title 182 190 self.mode = mode 191 if level == 0: 192 self.level = '' 193 else: 194 self.level = translate(self.studylevelsource.getTitle(None, int(level)), 195 'waeup.kofa', target_language=self.portal_language) 183 196 self.breakdown = breakdown 184 197 self.author = author 185 198 self.creation_dt_string = self.creation_dt.astimezone( 186 199 getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z") 187 self.data = get_student_payment_stats(session, mode, breakdown)200 self.data = get_student_payment_stats(session, mode, level, breakdown) 188 201 189 202 def create_pdf(self): … … 196 209 pdf_data += [ 197 210 Table(table_data, style=TABLE_STYLE, colWidths=col_widths)] 198 doc_title = '%s Student Payments in Session %s' % (self.mode, self.session) 199 pdf = creator.create_pdf( 200 pdf_data, None, doc_title, self.author, 201 'Student Payments in Session %s' % self.session 202 ) 211 if not self.level: 212 doc_title = translate( 213 _('${a} Student Payments - ${b}', 214 mapping = {'a':self.mode, 'b':self.session})) 215 pdf = creator.create_pdf( 216 pdf_data, None, doc_title, self.author, doc_title + '-' 217 ) 218 else: 219 doc_title = translate( 220 _('${a} Student Payments - ${b} - ${c}', 221 mapping = {'a':self.mode, 'b': self.level, 'c':self.session})) 222 pdf = creator.create_pdf( 223 pdf_data, None, doc_title, self.author, doc_title + '-' 224 ) 203 225 return pdf 204 226 … … 210 232 grok.name('student_payment_stats') 211 233 212 def generate(self, site, session=None, 213 mode=None, breakdown=None, author=None): 234 def generate( 235 self, site, session=None, mode=None, 236 level=None, breakdown=None, author=None): 214 237 result = StudentPaymentStatisticsReport( 215 session=session, mode=mode, breakdown=breakdown, author=author) 238 session=session, mode=mode, level=level, 239 breakdown=breakdown, author=author) 216 240 return result 217 241 … … 245 269 246 270 def _filename(self): 247 return 'StudentPaymentStatisticsReport_%s_%s_%s .pdf' % (248 self.context.session, self.context.mode, 271 return 'StudentPaymentStatisticsReport_%s_%s_%s_%s.pdf' % ( 272 self.context.session, self.context.mode, self.context.level, 249 273 self.context.creation_dt_string) 250 274 -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/student_statistics.py
r12619 r12897 17 17 ## 18 18 import grok 19 from zope.i18n import translate 19 20 from zope.catalog.interfaces import ICatalog 20 21 from zope.component import queryUtility, getUtility … … 23 24 IKofaUtils, 24 25 academic_sessions_vocab, registration_states_vocab) 26 from waeup.kofa.students.vocabularies import StudyLevelSource 25 27 from waeup.kofa.interfaces import MessageFactory as _ 26 28 from waeup.kofa.reports import IReport … … 29 31 30 32 session = Attribute('Session to report') 33 level = Attribute('Level to report') 31 34 mode = Attribute('Study modes group to report') 32 35 creation_dt_string = Attribute('Human readable report creation datetime') 33 36 34 def get_student_stats(session, mode, breakdown):35 """Get students in a certain session and study mode.37 def get_student_stats(session, mode, level, breakdown): 38 """Get students in a certain session, study mode and current level. 36 39 37 40 Returns a table ordered by code (faculty or department, one per row) and … … 81 84 if mode != 'All' and stud.current_mode not in mode_groups[mode]: 82 85 continue 86 if level != 0 and stud.current_level != level: 87 continue 83 88 if getattr(stud, breakdown) not in codes: 84 89 # studs can have a faccode ``None`` … … 139 144 mode = None 140 145 141 def __init__(self, session, mode, breakdown, author='System'):146 def __init__(self, session, mode, level, breakdown, author='System'): 142 147 super(StudentStatisticsReport, self).__init__( 143 148 args=[session, mode, breakdown], kwargs={'author':author}) 149 self.studylevelsource = StudyLevelSource().factory 150 self.portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 144 151 self.session = academic_sessions_vocab.getTerm(session).title 145 152 self.mode = mode 153 if level == 0: 154 self.level = '' 155 else: 156 self.level = translate(self.studylevelsource.getTitle(None, int(level)), 157 'waeup.kofa', target_language=self.portal_language) 146 158 self.breakdown = breakdown 147 159 self.author = author 148 160 self.creation_dt_string = self.creation_dt.astimezone( 149 161 getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z") 150 self.data = get_student_stats(session, mode, breakdown)162 self.data = get_student_stats(session, mode, level, breakdown) 151 163 152 164 def create_pdf(self): … … 159 171 pdf_data += [ 160 172 Table(table_data, style=TABLE_STYLE, colWidths=col_widths)] 161 doc_title = '%s Students in Session %s' % (self.mode, self.session) 162 pdf = creator.create_pdf( 163 pdf_data, None, doc_title, self.author, 164 'Students in Session %s' % self.session 165 ) 173 if not self.level: 174 doc_title = translate( 175 _('${a} Students - ${b}', 176 mapping = {'a':self.mode, 'b':self.session})) 177 pdf = creator.create_pdf( 178 pdf_data, None, doc_title, self.author, doc_title + '-' 179 ) 180 else: 181 doc_title = translate( 182 _('${a} Students - ${b} - ${c}', 183 mapping = {'a':self.mode, 'b': self.level, 'c':self.session})) 184 pdf = creator.create_pdf( 185 pdf_data, None, doc_title, self.author, doc_title + '-' 186 ) 166 187 return pdf 167 188 … … 172 193 grok.name('student_stats') 173 194 174 def generate(self, site, session=None, mode=None, breakdown=None, author=None): 195 def generate( 196 self, site, session=None, mode=None, 197 level=None, breakdown=None, author=None): 175 198 result = StudentStatisticsReport( 176 session=session, mode=mode, breakdown=breakdown, author=author) 199 session=session, mode=mode, level=level, 200 breakdown=breakdown, author=author) 177 201 return result 178 202 … … 202 226 return None 203 227 204 def update(self, CREATE=None, session=None, mode=None, breakdown=None): 228 def update( 229 self, CREATE=None, session=None, mode=None, level=None, breakdown=None): 205 230 self.parent_url = self.url(self.context.__parent__) 206 231 self._set_session_values() 207 232 self._set_mode_values() 233 self._set_level_values() 208 234 self._set_breakdown_values() 209 235 if CREATE and session: 210 # create a new report job for students by session 236 # create a new report job for students by session and level 211 237 container = self.context.__parent__ 212 238 user_id = self.request.principal.id … … 214 240 session=int(session), 215 241 mode=mode, 242 level=int(level), 216 243 breakdown=breakdown) 217 244 self.flash(_('New report is being created in background')) … … 220 247 ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 221 248 grok.getSite().logger.info( 222 '%s - report %s created: %s (session=%s, mode=%s, breakdown=%s)' % ( 223 ob_class, job_id, self.context.title, session, mode, breakdown)) 249 '%s - report %s created: %s (session=%s, mode=%s, level=%s, breakdown=%s)' % ( 250 ob_class, job_id, self.context.title, 251 session, mode, level, breakdown)) 224 252 self.redirect(self.parent_url) 225 253 return … … 234 262 mode_groups = getUtility(IKofaUtils).MODE_GROUPS 235 263 self.modes = sorted([(key, key) for key in mode_groups.keys()]) 264 return 265 266 def _set_level_values(self): 267 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 268 studylevelsource = StudyLevelSource().factory 269 self.levels = [(u'All levels', 0)] 270 for code in studylevelsource.getValues(None): 271 title = translate(studylevelsource.getTitle(None, code), 272 'waeup.kofa', target_language=portal_language) 273 self.levels.append((title, code)) 236 274 return 237 275 … … 248 286 249 287 def _filename(self): 250 return 'StudentStatisticsReport_%s_%s_%s .pdf' % (251 self.context.session, self.context.mode, 288 return 'StudentStatisticsReport_%s_%s_%s_%s.pdf' % ( 289 self.context.session, self.context.mode, self.context.level, 252 290 self.context.creation_dt_string) 253 291 -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_student_payment_statistics.py
r12564 r12897 22 22 # ensure we fullfill interface contracts 23 23 obj = StudentPaymentStatisticsReport( 24 2010, 'Undergraduate Full-Time', 'faccode')24 2010, 'Undergraduate Full-Time', 0, 'faccode') 25 25 verifyClass(IStudentPaymentStatisticsReport, StudentPaymentStatisticsReport) 26 26 verifyObject(IStudentPaymentStatisticsReport, obj) … … 29 29 def test_get_student_payment_stats_session_simple(self): 30 30 # we can get a table with one student 31 result1 = get_student_payment_stats(2010, 'Undergraduate Full-Time', 'faccode') 32 result2 = get_student_payment_stats(2009, 'Undergraduate Full-Time', 'faccode') 31 result1 = get_student_payment_stats( 32 2010, 'Undergraduate Full-Time', 0, 'faccode') 33 result2 = get_student_payment_stats( 34 2009, 'Undergraduate Full-Time', 0, 'faccode') 33 35 self.assertEqual( 34 36 result1, … … 53 55 def test_create_pdf(self): 54 56 report = StudentPaymentStatisticsReport( 55 2010, 'Undergraduate Full-Time', 'faccode')57 2010, 'Undergraduate Full-Time', 0, 'faccode') 56 58 result = report.create_pdf() 57 59 self.assertTrue(result.startswith('%PDF-')) … … 104 106 'application/pdf') 105 107 self.assertTrue( 106 'filename="StudentPaymentStatisticsReport_2004_2005_All_ ' in108 'filename="StudentPaymentStatisticsReport_2004_2005_All__' in 107 109 self.browser.headers['content-disposition']) 108 110 self.assertEqual(len(self.app['reports'].running_report_jobs), 1) … … 118 120 self.assertTrue( 119 121 'INFO - zope.mgr - students.reports.student_payment_statistics.StudentPaymentStatisticsReportGeneratorPage - ' 120 'report %s created: Student Payment Statistics (session=2004, mode=All, breakdown=depcode)'122 'report %s created: Student Payment Statistics (session=2004, mode=All, level=0, breakdown=depcode)' 121 123 % job_id in logcontent 122 124 ) 123 125 self.assertTrue( 124 126 'INFO - zope.mgr - students.reports.student_payment_statistics.StudentPaymentStatisticsReportPDFView - ' 125 'report %s downloaded: StudentPaymentStatisticsReport_2004_2005_All_ '127 'report %s downloaded: StudentPaymentStatisticsReport_2004_2005_All__' 126 128 % job_id in logcontent 127 129 ) -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_student_statistics.py
r12619 r12897 25 25 # ensure we fullfill interface contracts 26 26 obj = StudentStatisticsReport( 27 2010, 'Undergraduate Full-Time', 'faccode')27 2010, 'Undergraduate Full-Time', 0, 'faccode') 28 28 verifyClass(IStudentStatisticsReport, StudentStatisticsReport) 29 29 verifyObject(IStudentStatisticsReport, obj) … … 32 32 def test_get_student_stats_session_simple(self): 33 33 # we can get a table with one student 34 result1 = get_student_stats(2010, 'Undergraduate Full-Time', 'faccode') 35 result2 = get_student_stats(2009, 'Undergraduate Full-Time', 'faccode') 34 result1 = get_student_stats( 35 2010, 'Undergraduate Full-Time', 0, 'faccode') 36 result2 = get_student_stats( 37 2009, 'Undergraduate Full-Time', 0, 'faccode') 36 38 self.assertEqual( 37 39 result1, … … 51 53 # we can get a table with several students 52 54 self.create_cert(u'fac2', u'dep2', u'CERT2') 53 result1 = get_student_stats(2010, 'Undergraduate Full-Time', 'faccode') 54 result2 = get_student_stats(2009, 'Undergraduate Full-Time', 'faccode') 55 result1 = get_student_stats( 56 2010, 'Undergraduate Full-Time', 0, 'faccode') 57 result2 = get_student_stats( 58 2009, 'Undergraduate Full-Time', 0, 'faccode') 55 59 self.assertEqual( 56 60 result1, … … 72 76 # we can get a table with several students 73 77 self.create_cert(u'fac2', u'dep2', u'CERT2') 74 result1 = get_student_stats(2010, 'Undergraduate Full-Time', 'depcode') 75 result2 = get_student_stats(2009, 'Undergraduate Full-Time', 'depcode') 78 result1 = get_student_stats(2010, 'Undergraduate Full-Time', 0, 'depcode') 79 result2 = get_student_stats(2009, 'Undergraduate Full-Time', 0, 'depcode') 80 self.assertEqual( 81 result1, 82 ((u'fac1/dep1', u'fac2/dep2', u'Total'), 83 self.states, 84 ((1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1), 85 (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 86 (1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1),))) 87 self.assertEqual( 88 result2, 89 ((u'fac1/dep1', u'fac2/dep2', u'Total'), 90 self.states, 91 ((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 92 (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 93 (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),))) 94 return 95 96 def test_get_student_stats_session_multiple_dep_breakdown_level_100(self): 97 # we can get a table with several students 98 self.create_cert(u'fac2', u'dep2', u'CERT2') 99 result1 = get_student_stats(2010, 'Undergraduate Full-Time', 0, 'depcode') 100 result2 = get_student_stats(2009, 'Undergraduate Full-Time', 0, 'depcode') 76 101 self.assertEqual( 77 102 result1, … … 93 118 self.create_cert(u'FAC2', u'dept2', u'CERT2') 94 119 report = StudentStatisticsReport( 95 2010, 'Undergraduate Full-Time', 'faccode')120 2010, 'Undergraduate Full-Time', 0, 'faccode') 96 121 result = report.create_pdf() 97 122 self.assertTrue(result.startswith('%PDF-')) … … 99 124 open(path, 'wb').write(result) 100 125 print "Sample PDF student_statistics.pdf written to %s" % path 126 return 127 128 def test_create_100level_pdf(self): 129 self.create_cert(u'FAC2', u'dept2', u'CERT2') 130 report = StudentStatisticsReport( 131 2010, 'Undergraduate Full-Time', 100, 'faccode') 132 result = report.create_pdf() 133 self.assertTrue(result.startswith('%PDF-')) 134 path = os.path.join(samples_dir(), 'student_statistics_100.pdf') 135 open(path, 'wb').write(result) 136 print "Sample PDF student_statistics_100.pdf written to %s" % path 101 137 return 102 138 … … 158 194 self.assertTrue( 159 195 'INFO - zope.mgr - students.reports.student_statistics.StudentStatisticsReportGeneratorPage - ' 160 'report %s created: Student Statistics (session=2004, mode=All, breakdown=depcode)'196 'report %s created: Student Statistics (session=2004, mode=All, level=0, breakdown=depcode)' 161 197 % job_id in logcontent 162 198 ) 163 199 self.assertTrue( 164 200 'INFO - zope.mgr - students.reports.student_statistics.StudentStatisticsReportPDFView - ' 165 'report %s downloaded: StudentStatisticsReport_2004_2005_All_ '201 'report %s downloaded: StudentStatisticsReport_2004_2005_All__' 166 202 % job_id in logcontent 167 203 )
Note: See TracChangeset for help on using the changeset viewer.