Ignore:
Timestamp:
10 Jan 2017, 09:25:41 (8 years ago)
Author:
Henrik Bettermann
Message:

Inherit from LevelReportGeneratorPage? to remove redundant code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.aaue/trunk/src/waeup/aaue/students/reports/raw_score_report.py

    r14374 r14381  
    2929from waeup.kofa.browser.pdf import get_signature_tables
    3030from waeup.kofa.students.vocabularies import StudyLevelSource
     31from waeup.kofa.students.reports.level_report import LevelReportGeneratorPage
    3132from waeup.kofa.students.reports.student_statistics import (
    3233    StudentStatisticsReportPDFView)
     
    283284from waeup.kofa.browser.breadcrumbs import Breadcrumb
    284285grok.templatedir('browser_templates')
    285 class RawScoreReportGeneratorPage(KofaPage):
     286class RawScoreReportGeneratorPage(LevelReportGeneratorPage):
    286287
    287288    grok.context(RawScoreReportGenerator)
    288     grok.name('index.html')
    289     grok.require('waeup.handleReports')
    290     grok.template('levelreportgeneratorpage')
    291289
    292290    label = _('Create raw score report')
    293 
    294     @property
    295     def generator_name(self):
    296         for name, gen in get_generators():
    297             if gen == self.context:
    298                 return name
    299         return None
    300 
    301     def update(self, CREATE=None, faccode_depcode=None,
    302                session=None, level=None):
    303         self.parent_url = self.url(self.context.__parent__)
    304         self._set_session_values()
    305         self._set_level_values()
    306         self._set_faccode_depcode_values()
    307         if CREATE and session:
    308             # create a new report job for students by session
    309             faccode = faccode_depcode.split('_')[0]
    310             depcode = faccode_depcode.split('_')[1]
    311             container = self.context.__parent__
    312             user_id = self.request.principal.id
    313             if level:
    314                 level = int(level)
    315             if session:
    316                 session = int(session)
    317             kw = dict(
    318                 session=session,
    319                 level=level,
    320                 faccode=faccode,
    321                 depcode=depcode)
    322             self.flash(_('New report is being created in background'))
    323             job_id = container.start_report_job(
    324                 self.generator_name, user_id, kw=kw)
    325             ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')
    326             grok.getSite().logger.info(
    327                 '%s - report %s created: %s (faculty=%s, department=%s, session=%s, level=%s)' % (
    328                 ob_class, job_id, self.context.title, faccode, depcode, session, level))
    329             self.redirect(self.parent_url)
    330             return
    331         return
    332 
    333     def _set_session_values(self):
    334         vocab_terms = academic_sessions_vocab.by_value.values()
    335         self.sessions = [(x.title, x.token) for x in vocab_terms]
    336         return
    337 
    338     #def _set_level_values(self):
    339     #    vocab_terms = course_levels.by_value.values()
    340     #    self.levels = sorted([(x.title, x.token) for x in vocab_terms])
    341     #    return
    342 
    343     def _set_level_values(self):
    344         portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    345         studylevelsource = StudyLevelSource().factory
    346         self.levels = []
    347         for code in studylevelsource.getValues(None):
    348             title = translate(studylevelsource.getTitle(None, code),
    349                 'waeup.kofa', target_language=portal_language)
    350             self.levels.append((title, code))
    351         return
    352 
    353     def _set_faccode_depcode_values(self):
    354         faccode_depcodes = []
    355         faculties = grok.getSite()['faculties']
    356         for fac in faculties.values():
    357             for dep in fac.values():
    358                 faccode_depcodes.append(
    359                     ('%s (%s)' %(dep.longtitle, fac.longtitle),
    360                      '%s_%s' %(fac.code, dep.code)))
    361         self.faccode_depcodes = sorted(
    362             faccode_depcodes, key=lambda value: value[0])
    363         return
    364291
    365292class RawScoreReportPDFView(StudentStatisticsReportPDFView):
Note: See TracChangeset for help on using the changeset viewer.