Changeset 9647 for main/waeup.kofa
- Timestamp:
- 16 Nov 2012, 21:43:29 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/browser/templates/reportscontainerpage.pt
r9645 r9647 32 32 <input type="hidden" name="job_id" 33 33 tal:attributes="value python: entry[0]" /> 34 <input type="submit" class="btn primary" 35 name="DOWNLOAD" value="Download" 36 tal:condition="python: entry[4]" /> 34 37 <input type="submit" class="btn secondary" 35 38 name="DISCARD" value="Discard" 36 39 tal:condition="python: entry[3]" /> 37 <input type="submit" class="btn primary"38 name="DOWNLOAD" value="Download"39 tal:condition="python: entry[4]" />40 40 </form> 41 41 </td> -
main/waeup.kofa/trunk/src/waeup/kofa/reports.py
r9646 r9647 342 342 kw = self.kwargs.get('kw', dict()) 343 343 args = ', '.join(["%r" % x for x in args]) 344 kw = ', '.join(['%s=%r' % (key, val) for key, val in kw.items()]) 344 #kw = ', '.join(['%s = %r' % (key, val) for key, val in kw.items()]) 345 kw = ', '.join(['%s' % val for val in kw.values()]) 345 346 if len(args) and len(kw): 346 347 str_repr = args + ', ' + kw -
main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/studentreportgeneratorpage.pt
r9643 r9647 19 19 </select> 20 20 <div class="help-inline" i18n:translate=""> 21 Academic session to report21 Select academic session to report 22 22 </div> 23 23 </div> 24 <br /> 25 <label for="session">Study Mode Group:</label> 26 <div class="input"> 27 <select name="mode"> 28 <span tal:repeat="items view/modes" tal:omit-tag=""> 29 <option 30 tal:define="name python: items[1]; title python: items[0]" 31 tal:attributes="value name"> 32 <span tal:replace="title">TITLE</span> 33 </option> 34 </span> 35 </select> 36 <div class="help-inline" i18n:translate=""> 37 Set study modes filter 38 </div> 39 </div> 40 24 41 </div> 25 42 <div class="input"> -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports.py
r9637 r9647 25 25 from waeup.kofa.reports import IReport 26 26 27 MODE_GROUPS = { 28 'All':('all',), 29 'Undergraduate Full-Time':('ug_ft',), 30 'Undergraduate Part-Time':('ug_pt',), 31 'Postgraduate Full-Time':('pg_ft',), 32 'Postgraduate Part-Time':('pg_pt',), 33 } 34 27 35 class IStudentReport(IReport): 28 36 pass 29 37 30 def get_students_by _session(session):31 """Get students of a certain session.38 def get_students_by(session, mode): 39 """Get students in a certain session and study mode. 32 40 33 41 Returns a table ordered by faculty code (one per row) and … … 52 60 fac_codes = tuple(sorted([x for x in site['faculties'].keys()], 53 61 key=lambda x: x.lower())) 54 fac_codes = fac_codes + ( 'Total',)62 fac_codes = fac_codes + (u'Total',) 55 63 # XXX: Here we do _one_ query and then examine the single 56 64 # students. One could also do multiple queries and just look for … … 61 69 table = [[0 for x in xrange(len(states))] for y in xrange(len(fac_codes))] 62 70 for stud in result: 71 if mode != 'All' and stud.current_mode not in MODE_GROUPS[mode]: 72 continue 63 73 row = fac_codes.index(stud.faccode) 64 74 col = states.index(stud.state) … … 112 122 data = None 113 123 session = None 114 115 def __init__(self, session, author='System'): 124 mode = None 125 126 def __init__(self, session, mode, author='System'): 116 127 super(StudentReport, self).__init__( 117 args=[session], kwargs={'author':author}) 118 self.session = session 128 args=[session, mode], kwargs={'author':author}) 129 self.session = academic_sessions_vocab.getTerm(session).title 130 self.mode = mode 119 131 self.author = author 120 self.data = get_students_by _session(session)132 self.data = get_students_by(session, mode) 121 133 122 134 def __repr__(self): 123 return 'StudentReport(session=%s, author=%r)' % (124 self.session, self. author)135 return 'StudentReport(session=%s, mode=%s, author=%r)' % ( 136 self.session, self.mode, self.author) 125 137 126 138 def get_data(self): 127 self.data = get_students_by _session(self.session)139 self.data = get_students_by(self.session, self.mode) 128 140 129 141 def create_pdf(self): … … 131 143 table_data = tbl_data_to_table(*self.data) 132 144 col_widths = [None,] + [1.6*cm] * len(self.data[1]) + [None,] 133 pdf_data = [Paragraph('<b>Session:</b> %s' % self.session,134 STYLE["Normal"]),135 Spacer(1, 12),]136 pdf_data += [145 #pdf_data = [Paragraph('<b>Study mode:</b> %s' % self.mode, 146 # STYLE["Normal"]), 147 # Spacer(1, 12),] 148 pdf_data = [ 137 149 Table(table_data, style=TABLE_STYLE, colWidths=col_widths)] 138 doc_title = 'Report: Students of Session %s\nby faculty and status' % ( 150 doc_title = '%s Students in Session %s' % ( 151 self.mode, 139 152 self.session,) 140 153 pdf = creator.create_pdf( 141 154 pdf_data, None, doc_title, self.author, 142 'S ession %s Students,' % self.session)155 'Students in Session %s,' % self.session) 143 156 open('/tmp/result.pdf', 'wb').write(pdf) 144 157 return pdf … … 154 167 return self.title 155 168 156 def generate(self, site, session=None, author=None):157 result = StudentReport(session=session, author=author)169 def generate(self, site, session=None, mode=None, author=None): 170 result = StudentReport(session=session, mode=mode, author=author) 158 171 return result 159 172 … … 182 195 return None 183 196 184 def update(self, CREATE=None, session=None ):197 def update(self, CREATE=None, session=None, mode=None): 185 198 self.parent_url = self.url(self.context.__parent__) 186 199 self._set_session_values() 200 self._set_mode_values() 187 201 if CREATE and session: 188 202 # create a new report job for students by session 189 203 container = self.context.__parent__ 190 204 user_id = self.request.principal.id 191 kw = dict(session=self._value_dict[session]) 205 kw = dict( 206 #session=self._session_value_dict[session], 207 session=int(session), 208 mode=mode) 192 209 self.flash(_('New report is being created in background')) 193 210 container.start_report_job( … … 200 217 vocab_terms = academic_sessions_vocab.by_value.values() 201 218 self.sessions = [(x.title, x.token) for x in vocab_terms] 202 self._value_dict = dict([(x.token, x.value) for x in vocab_terms])219 #self._session_value_dict = dict([(x.token, x.value) for x in vocab_terms]) 203 220 return 204 221 222 def _set_mode_values(self): 223 self.modes = sorted([(key, key) for key in MODE_GROUPS.keys()]) 224 return 205 225 206 226 class StudentReportPDFView(grok.View): -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_catalog.py
r9264 r9647 59 59 setSite(self.app) 60 60 self.certificate = self.create_cert(u'fac1', u'dep1', u'CERT1') 61 self.certificate.study_mode = u'ug_ft' 61 62 62 63 # Create student with subobjects -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_reports.py
r9633 r9647 1 1 # Tests for student related reports 2 from waeup.kofa.students.reports import get_students_by_session, StudentReport 2 from waeup.kofa.students.reports import ( 3 get_students_by, StudentReport) 3 4 from waeup.kofa.students.tests.test_catalog import CatalogTestSetup 4 5 from waeup.kofa.testing import FunctionalLayer … … 14 15 def test_get_students_by_session_simple(self): 15 16 # we can get a table with one student 16 result1 = get_students_by _session(2010)17 result2 = get_students_by _session(2009)17 result1 = get_students_by(2010, 'Undergraduate Full-Time') 18 result2 = get_students_by(2009, 'Undergraduate Full-Time') 18 19 self.assertEqual( 19 20 result1, … … 33 34 # we can get a table with several students 34 35 self.create_cert('fac2', 'dept2', 'CERT2') 35 result1 = get_students_by _session(2010)36 result2 = get_students_by _session(2009)36 result1 = get_students_by(2010, 'Undergraduate Full-Time') 37 result2 = get_students_by(2009, 'Undergraduate Full-Time') 37 38 self.assertEqual( 38 39 result1, … … 53 54 def test_create_pdf(self): 54 55 self.create_cert('FAC2', 'dept2', 'CERT2') 55 report = StudentReport(2010 )56 report = StudentReport(2010, 'Undergraduate Full-Time') 56 57 result = report.create_pdf() 57 58 self.assertTrue(result.startswith('%PDF-')) -
main/waeup.kofa/trunk/src/waeup/kofa/tests/test_reports.py
r9645 r9647 218 218 self.assertEqual( 219 219 job.description, 220 "Report 1 ('a', 'b', a=1, b=2)")220 "Report 1 ('a', 'b', 1, 2)") 221 221 # w/o args nor kwargs 222 222 job = AsyncReportJob(self.root_folder, 'report1') … … 231 231 job = AsyncReportJob(self.root_folder, 'report1', kw=kw) 232 232 self.assertEqual( 233 job.description, "Report 1 ( a=1, b=2)")233 job.description, "Report 1 (1, 2)") 234 234 return 235 235 … … 248 248 self.root_folder, 'NOT_EXISTENT', kw=dict(a=1, b=2)) 249 249 self.assertEqual( 250 job.description, u'Unregistered Report Generator ( a=1, b=2)')250 job.description, u'Unregistered Report Generator (1, 2)') 251 251 # with args and kws set 252 252 job = AsyncReportJob( 253 253 self.root_folder, 'NOT_EXISTENT', args=['a'], kw=dict(b=2)) 254 254 self.assertEqual( 255 job.description, u"Unregistered Report Generator ('a', b=2)")255 job.description, u"Unregistered Report Generator ('a', 2)") 256 256 return 257 257
Note: See TracChangeset for help on using the changeset viewer.