Changeset 10560 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 29 Aug 2013, 12:36:21 (11 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students/reports
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/level_report.py
r10557 r10560 149 149 pagesize=landscape(A4)) 150 150 return pdf 151 152 @implementer(IReportGenerator) 153 class LevelReportGenerator(grok.GlobalUtility): 154 155 title = _('Level Report') 156 grok.name('level_reports') 157 158 def generate(self, site, faccode=None, depcode=None, 159 session=None, level=None, author=None): 160 result = LevelReportReport(faccode=faccode, depcode=depcode, 161 session=session, level=level, author=author) 162 return result 163 164 ############################################################### 165 ## Browser related stuff 166 ## 167 ## XXX: move to local browser module 168 ############################################################### 169 from waeup.kofa.browser.layout import KofaPage 170 from waeup.kofa.interfaces import academic_sessions_vocab 171 from waeup.kofa.reports import get_generators 172 grok.templatedir('browser_templates') 173 class LevelReportGeneratorPage(KofaPage): 174 175 grok.context(LevelReportGenerator) 176 grok.name('index.html') 177 grok.require('waeup.manageReports') 178 179 label = _('Create level report') 180 181 @property 182 def generator_name(self): 183 for name, gen in get_generators(): 184 if gen == self.context: 185 return name 186 return None 187 188 def update(self, CREATE=None, faccode_depcode=None, 189 session=None, level=None): 190 self.parent_url = self.url(self.context.__parent__) 191 self._set_session_values() 192 self._set_level_values() 193 self._set_faccode_depcode_values() 194 #faccode = faccode_depcode.split('_')[0] 195 #depcode = faccode_depcode.split('_')[1] 196 if CREATE and session: 197 # create a new report job for students by session 198 container = self.context.__parent__ 199 user_id = self.request.principal.id 200 kw = dict( 201 session=int(session), 202 level=int(level), 203 faccode=faccode, 204 depcode=depcode) 205 self.flash(_('New report is being created in background')) 206 job_id = container.start_report_job( 207 self.generator_name, user_id, kw=kw) 208 ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 209 grok.getSite().logger.info( 210 '%s - report %s created: %s (session=%s, mode=%s)' % ( 211 ob_class, job_id, self.context.title, session, mode)) 212 self.redirect(self.parent_url) 213 return 214 return 215 216 def _set_session_values(self): 217 vocab_terms = academic_sessions_vocab.by_value.values() 218 self.sessions = [(x.title, x.token) for x in vocab_terms] 219 return 220 221 def _set_level_values(self): 222 vocab_terms = course_levels.by_value.values() 223 self.levels = sorted([(x.title, x.token) for x in vocab_terms]) 224 return 225 226 def _set_faccode_depcode_values(self): 227 # Not yet implemented 228 self.faccode_depcodes = None 229 return 230 231 232 class LevelReportPDFView(grok.View): 233 234 grok.context(ILevelReport) 235 grok.name('pdf') 236 grok.require('waeup.Public') 237 238 def render(self): 239 filename = 'LevelReport_%s_%s_%s.pdf' % ( 240 self.context.session, self.context.mode, 241 self.context.creation_dt_string) 242 filename = filename.replace( 243 '/', '_').replace(' ','_').replace(':', '-') 244 self.response.setHeader( 245 'Content-Type', 'application/pdf') 246 self.response.setHeader( 247 'Content-Disposition:', 'attachment; filename="%s' % filename) 248 pdf_stream = self.context.create_pdf() 249 ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 250 grok.getSite().logger.info('%s - report %s downloaded: %s' % ( 251 ob_class, self.context.__name__, filename)) 252 return pdf_stream
Note: See TracChangeset for help on using the changeset viewer.