Ignore:
Timestamp:
21 Jan 2017, 13:45:59 (8 years ago)
Author:
Henrik Bettermann
Message:

Confine Level Reports and Session Results Presentations to certificates.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students/reports
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/browser_templates/levelreportgeneratorpage.pt

    r13366 r14423  
    77  </p>
    88  <br />
    9   <label for="session" i18n:translate="">Department</label>
    10   <select name="faccode_depcode" class="form-control half">
    11     <span tal:repeat="items view/faccode_depcodes" tal:omit-tag="">
     9
     10  <label for="session" i18n:translate="">Certificate</label>
     11  <input id="filterbox" class="kofa-filterbox form-control half"
     12         placeholder="Enter search text, then select item below."
     13         type="text" i18n:translate=""/>
     14  <br />
     15  <select id="filteredselect" name="faccode_depcode_certcode"
     16          class="form-control half" size=5>
     17      <span tal:repeat="items view/faccode_depcode_certcode"
     18          tal:omit-tag="">
    1219      <option
    1320          tal:define="name python: items[1]; title python: items[0]"
     
    1926  <br />
    2027  <label for="session">Academic Session</label>
    21   <div class="input">
    22     <select name="session" class="form-control half">
    23       <span tal:repeat="items view/sessions" tal:omit-tag="">
    24         <option
    25             tal:define="name python: items[1]; title python: items[0]"
    26             tal:attributes="value name">
    27           <span tal:replace="title">TITLE</span>
    28         </option>
    29       </span>
    30     </select>
    31   </div>
     28  <select name="session" class="form-control half">
     29    <span tal:repeat="items view/sessions" tal:omit-tag="">
     30      <option
     31          tal:define="name python: items[1]; title python: items[0]"
     32          tal:attributes="value name">
     33        <span tal:replace="title">TITLE</span>
     34      </option>
     35    </span>
     36  </select>
    3237  <br />
    3338  <label for="session">Level</label>
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/level_report.py

    r14414 r14423  
    3838    faccode = Attribute('Faculty to report')
    3939    depcode = Attribute('Department to report')
     40    certcode = Attribute('Certificate to report')
    4041    creation_dt_string = Attribute('Human readable report creation datetime')
    4142
    42 def get_students(faccode, depcode, session, level):
    43     """Get students in a certain department who registered courses
    44     in a certain session at a certain level.
     43def get_students(faccode, depcode, certcode, session, level):
     44    """Get students in a certain department, studying a certain programmen
     45    who registered courses in a certain session at a certain level.
    4546
    4647    Returns a list of student data tuples.
     
    4849    site = grok.getSite()
    4950    cat = queryUtility(ICatalog, name="students_catalog")
     51    if certcode == 'all':
     52        certcode = None
    5053    result = cat.searchResults(
    51         depcode = (depcode, depcode), faccode = (faccode, faccode)
     54        depcode = (depcode, depcode), faccode = (faccode, faccode),
     55        certcode = (certcode, certcode)
    5256        )
    5357    table = []
     
    171175    faccode = None
    172176    depcode = None
     177    certcode = None
    173178
    174179    note = None
    175180
    176     def __init__(self, faccode, depcode, session, level, author='System'):
     181    def __init__(self, faccode, depcode, certcode, session, level,
     182                 author='System'):
    177183        super(LevelReport, self).__init__(
    178             args=[faccode, depcode, session, level], kwargs={'author':author})
     184            args=[faccode, depcode, certcode, session, level],
     185            kwargs={'author':author})
    179186        site = grok.getSite()
    180187        self.studylevelsource = StudyLevelSource().factory
     
    187194        self.faccode = faccode
    188195        self.depcode = depcode
     196        self.certcode = certcode
    189197        self.factitle = site['faculties'][faccode].longtitle
    190198        self.deptitle = site['faculties'][faccode][depcode].longtitle
     199        if self.certcode == 'all':
     200            self.certtitle = translate(
     201                _('All Certificates'), 'waeup.kofa',
     202                target_language=self.portal_language)
     203        else:
     204            self.certtitle = site['faculties'][faccode][
     205                depcode].certificates[certcode].longtitle
    191206        self.author = author
    192207        self.creation_dt_string = self.creation_dt.astimezone(
    193208            getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z")
    194         self.data = get_students(faccode, depcode, session, level)
     209        self.data = get_students(faccode, depcode, certcode, session, level)
    195210
    196211    def create_pdf(self, job_id):
     
    206221        pdf_data += [Paragraph(
    207222                    translate(
    208                         '${a}<br />${b}<br />Session: ${c}<br />Level: ${d}',
    209                         mapping = {'a':self.factitle,
     223                        '${a}<br />${b}<br />${c}<br /><br />Session: ${d}<br />Level: ${e}',
     224                        mapping = {'a':self.certtitle,
    210225                                   'b':self.deptitle,
    211                                    'c':self.session,
    212                                    'd':self.level,
     226                                   'c':self.factitle,
     227                                   'd':self.session,
     228                                   'e':self.level,
    213229                                   }),
    214230                    STYLE["Normal"]),
     
    227243        pdf = creator.create_pdf(
    228244            pdf_data, None, doc_title, self.author,
    229             doc_title + ' - %s/%s - %s - %s -' % (
    230             self.faccode, self.depcode, self.levelcode, self.sessioncode),
     245            doc_title + ' - %s/%s/%s - %s - %s -' % (
     246            self.faccode, self.depcode, self.certcode,
     247            self.levelcode, self.sessioncode),
    231248            note = self.note
    232249            )
     
    239256    grok.name('level_report')
    240257
    241     def generate(self, site, faccode=None, depcode=None,
     258    def generate(self, site, faccode=None, depcode=None, certcode=None,
    242259                 session=None, level=None, author=None):
    243260        result = LevelReport(faccode=faccode, depcode=depcode,
     261                             certcode=certcode,
    244262                             session=session, level=level, author=author)
    245263        return result
     
    270288        return None
    271289
    272     def update(self, CREATE=None, faccode_depcode=None,
     290    def update(self, CREATE=None, faccode_depcode_certcode=None,
    273291               session=None, level=None):
    274292        self.parent_url = self.url(self.context.__parent__)
    275293        self._set_session_values()
    276294        self._set_level_values()
    277         self._set_faccode_depcode_values()
    278         if CREATE and session:
     295        self._set_faccode_depcode_certcode_values()
     296        if not faccode_depcode_certcode:
     297            self.flash(_('No certificate selected.'), type="warning")
     298            return
     299        if CREATE:
    279300            # create a new report job for students by session
    280             faccode = faccode_depcode.split('_')[0]
    281             depcode = faccode_depcode.split('_')[1]
     301            faccode = faccode_depcode_certcode.split('_')[0]
     302            depcode = faccode_depcode_certcode.split('_')[1]
     303            certcode = faccode_depcode_certcode.split('_')[2]
    282304            container = self.context.__parent__
    283305            user_id = self.request.principal.id
     
    290312                level=level,
    291313                faccode=faccode,
    292                 depcode=depcode)
     314                depcode=depcode,
     315                certcode=certcode)
    293316            self.flash(_('New report is being created in background'))
    294317            job_id = container.start_report_job(
     
    296319            ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')
    297320            grok.getSite().logger.info(
    298                 '%s - report %s created: %s (faculty=%s, department=%s, session=%s, level=%s)' % (
    299                 ob_class, job_id, self.context.title, faccode, depcode, session, level))
     321                '%s - report %s created: %s (faculty=%s, department=%s, certificate=%s, session=%s, level=%s)' % (
     322                ob_class, job_id, self.context.title, faccode, depcode,
     323                certcode, session, level))
    300324            self.redirect(self.parent_url)
    301325            return
     
    322346        return
    323347
    324     def _set_faccode_depcode_values(self):
    325         faccode_depcodes = []
     348    def _set_faccode_depcode_certcode_values(self):
     349        faccode_depcode_certcode = []
    326350        faculties = grok.getSite()['faculties']
    327351        for fac in faculties.values():
    328352            for dep in fac.values():
    329                 faccode_depcodes.append(
    330                     ('%s (%s)' %(dep.longtitle, fac.longtitle),
    331                      '%s_%s' %(fac.code, dep.code)))
    332         self.faccode_depcodes = sorted(
    333             faccode_depcodes, key=lambda value: value[0])
     353                faccode_depcode_certcode.append(
     354                    ('All certificates -- %s, %s)'
     355                     %(dep.longtitle, fac.longtitle),
     356                     '%s_%s_all'
     357                     %(fac.code, dep.code)))
     358                for cert in dep.certificates.values():
     359                    faccode_depcode_certcode.append(
     360                        ('%s -- %s, %s)'
     361                         %(cert.longtitle, dep.longtitle, fac.longtitle),
     362                         '%s_%s_%s'
     363                         %(fac.code, dep.code, cert.code)))
     364        self.faccode_depcode_certcode = sorted(
     365            faccode_depcode_certcode, key=lambda value: value[0])
    334366        return
    335367
     
    342374
    343375    def _filename(self):
    344         return 'LevelReport_%s_%s_%s_%s_%s.pdf' % (
    345             self.context.faccode, self.context.depcode,
     376        return 'LevelReport_%s_%s_%s_%s_%s_%s.pdf' % (
     377            self.context.faccode, self.context.depcode, self.context.certcode,
    346378            self.context.sessioncode, self.context.levelcode,
    347379            self.context.creation_dt_string)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/session_results_presentation.py

    r14418 r14423  
    4040    """
    4141
    42 def get_students(faccode, depcode, session, level=None):
    43     """Get students in a certain department who registered courses
    44     in a certain session at a certain level.
     42def get_students(faccode, depcode, certcode, session, level=None):
     43    """Get students in a certain department, studying a certain programmen
     44    who registered courses in a certain session at a certain level.
    4545
    4646    Returns a list of lists of student data tuples.
     
    4848    site = grok.getSite()
    4949    cat = queryUtility(ICatalog, name="students_catalog")
     50    if certcode == 'all':
     51        certcode = None
    5052    result = cat.searchResults(
    51         depcode = (depcode, depcode), faccode = (faccode, faccode)
     53        depcode = (depcode, depcode), faccode = (faccode, faccode),
     54        certcode = (certcode, certcode)
    5255        )
    5356    students_utils = getUtility(IStudentsUtils)
     
    117120    faccode = None
    118121    depcode = None
     122    certcode = None
    119123
    120124    note = None
    121125
    122     def __init__(self, faccode, depcode, session, level, author='System'):
     126    def __init__(self, faccode, depcode, certcode, session, level,
     127                 author='System'):
    123128        super(SessionResultsPresentation, self).__init__(
    124             args=[faccode, depcode, session, level], kwargs={'author':author})
     129            args=[faccode, depcode, certcode, session, level],
     130            kwargs={'author':author})
    125131        site = grok.getSite()
    126132        self.studylevelsource = StudyLevelSource().factory
     
    136142        self.faccode = faccode
    137143        self.depcode = depcode
     144        self.certcode = certcode
    138145        self.factitle = site['faculties'][faccode].longtitle
    139146        self.deptitle = site['faculties'][faccode][depcode].longtitle
     147        if self.certcode == 'all':
     148            self.certtitle = translate(
     149                _('All Certificates'), 'waeup.kofa',
     150                target_language=self.portal_language)
     151        else:
     152            self.certtitle = site['faculties'][faccode][
     153                depcode].certificates[certcode].longtitle
    140154        self.author = author
    141155        self.creation_dt_string = self.creation_dt.astimezone(
    142156            getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z")
    143         self.data = get_students(faccode, depcode, session, level)
     157        self.data = get_students(faccode, depcode, certcode, session, level)
    144158
    145159    def create_pdf(self, job_id):
     
    150164                              STYLE["Normal"]),
    151165                    Spacer(1, 12),]
    152         pdf_data += [Paragraph('%s<br />%s<br />Session: %s<br />Level: %s' % (
    153                     self.factitle, self.deptitle, self.session, self.level),
     166        pdf_data += [Paragraph(
     167                    translate(
     168                        '${a}<br />${b}<br />${c}<br /><br />Session: ${d}<br />Level: ${e}',
     169                        mapping = {'a':self.certtitle,
     170                                   'b':self.deptitle,
     171                                   'c':self.factitle,
     172                                   'd':self.session,
     173                                   'e':self.level,
     174                                   }),
    154175                    STYLE["Normal"]),
    155176                    Spacer(1, 12),]
     
    197218        pdf = creator.create_pdf(
    198219            pdf_data, None, doc_title, self.author,
    199             doc_title + ' - %s/%s - %s - %s -' % (
    200             self.faccode, self.depcode, self.levelcode, self.sessioncode),
     220            doc_title + ' - %s/%s/%s - %s - %s -' % (
     221            self.faccode, self.depcode, self.certcode,
     222            self.levelcode, self.sessioncode),
    201223            note = self.note
    202224            )
     
    209231    grok.name('session_results_presentation')
    210232
    211     def generate(self, site, faccode=None, depcode=None,
     233    def generate(self, site, faccode=None, depcode=None, certcode=None,
    212234                 session=None, level=None, author=None):
    213235        result = SessionResultsPresentation(faccode=faccode, depcode=depcode,
    214                              session=session, level=level, author=author)
     236                 certcode=certcode, session=session, level=level, author=author)
    215237        return result
    216238
     
    230252    grok.template('levelreportgeneratorpage')
    231253    label = _('Create session results presentation')
    232 
    233     def update(self, CREATE=None, faccode_depcode=None,
    234                session=None, level=None):
    235         super(SessionResultsPresentationGeneratorPage, self).update(
    236             CREATE, faccode_depcode ,session, level)
    237 
    238     #def _set_level_values(self):
    239     #    vocab_terms = course_levels.by_value.values()
    240     #    self.levels = [('All levels', 'all')] + sorted(
    241     #        [(x.title, x.token) for x in vocab_terms])
    242     #    return
    243254
    244255    def _set_level_values(self):
     
    260271
    261272    def _filename(self):
    262         return 'SessionResultsPresentation_%s_%s_%s_%s_%s.pdf' % (
    263             self.context.faccode, self.context.depcode,
     273        return 'SessionResultsPresentation_%s_%s_%s_%s_%s_%s.pdf' % (
     274            self.context.faccode, self.context.depcode, self.context.certcode,
    264275            self.context.sessioncode, self.context.levelcode,
    265276            self.context.creation_dt_string)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_level_report.py

    r14392 r14423  
    1818    def test_iface(self):
    1919        # ensure we fullfill interface contracts
    20         obj = LevelReport('fac1', 'dep1', 2010, 100)
     20        obj = LevelReport('fac1', 'dep1', 'CERT1', 2010, 100)
    2121        verifyClass(ILevelReport, LevelReport)
    2222        verifyObject(ILevelReport, obj)
     
    3939        self.student['studycourse']['100']['Course3'] = ticket
    4040        # we can get a table with one student
    41         result = get_students('fac1', 'dep1', 2010, 100)
     41        result = get_students('fac1', 'dep1', 'CERT1', 2010, 100)
     42        self.assertEqual(result,
     43            [(u'1234', u'Bob Tester', 90, 30, '1.666',
     44            'm_Course2_m Course3', '', 90, 30, '1.666', '')])
     45        # same result when selecting all certificates
     46        result = get_students('fac1', 'dep1', 'all', 2010, 100)
    4247        self.assertEqual(result,
    4348            [(u'1234', u'Bob Tester', 90, 30, '1.666',
     
    7277        ticket4.credits = 30
    7378        self.student['studycourse']['100']['Course6'] = ticket4
    74         report = LevelReport('fac1', 'dep1', 2010, 100)
     79        report = LevelReport('fac1', 'dep1', 'all', 2010, 100)
    7580        result = report.create_pdf('JOB_ID')
    7681        self.assertTrue(result.startswith('%PDF-'))
     
    108113        self.browser.getControl(name="level").value = ['100']
    109114        self.browser.getControl(name="session").value = ['2010']
    110         self.browser.getControl(name="faccode_depcode").value = ['fac1_dep1']
     115        self.browser.getControl(name="faccode_depcode_certcode").value = [
     116            'fac1_dep1_CERT1']
    111117        self.browser.getControl("Create").click()
    112118        return
     
    123129                         'application/pdf')
    124130        self.assertTrue(
    125             'filename="LevelReport_fac1_dep1_2010_100_' in
     131            'filename="LevelReport_fac1_dep1_CERT1_2010_100_' in
    126132            self.browser.headers['content-disposition'])
    127133        self.assertEqual(len(self.app['reports'].running_report_jobs), 1)
     
    137143        self.assertTrue(
    138144            'INFO - zope.mgr - students.reports.level_report.LevelReportGeneratorPage - '
    139             'report %s created: Level Report (faculty=fac1, department=dep1, session=2010, level=100)'
     145            'report %s created: Level Report (faculty=fac1, department=dep1, '
     146            'certificate=CERT1, session=2010, level=100)'
    140147            % job_id in logcontent
    141148            )
    142149        self.assertTrue(
    143150            'INFO - zope.mgr - students.reports.level_report.LevelReportPDFView - '
    144             'report %s downloaded: LevelReport_fac1_dep1_2010_100_'
     151            'report %s downloaded: LevelReport_fac1_dep1_CERT1_2010_100_'
    145152            % job_id in logcontent
    146153            )
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_session_results_presentation.py

    r14410 r14423  
    2020    def test_iface(self):
    2121        # ensure we fullfill interface contracts
    22         obj = SessionResultsPresentation('fac1', 'dep1', 2010, 100)
     22        obj = SessionResultsPresentation('fac1', 'dep1', 'CERT1', 2010, 100)
    2323        verifyClass(ISessionResultsPresentation, SessionResultsPresentation)
    2424        verifyObject(ISessionResultsPresentation, obj)
     
    2626
    2727    def test_get_students(self):
    28         result = get_students('fac1', 'dep1', 2010, 100)
     28        result = get_students('fac1', 'dep1', 'CERT1', 2010, 100)
    2929        self.assertEqual(result,
    3030            [[], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')], []])
     
    3232
    3333    def test_get_students_at_all_levels(self):
    34         result = get_students('fac1', 'dep1', 2010, 0)
     34        result = get_students('fac1', 'dep1', 'CERT1', 2010, 0)
     35        self.assertEqual(result,
     36            [[], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')], []])
     37        return
     38
     39    def test_get_students_all_certs(self):
     40        result = get_students('fac1', 'dep1', 'all', 2010, 100)
    3541        self.assertEqual(result,
    3642            [[], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')], []])
     
    4349        studylevel.level_session = 2010
    4450        self.student['studycourse']['200'] = studylevel
    45         result = get_students('fac1', 'dep1', 2010, 0)
     51        result = get_students('fac1', 'dep1', 'CERT1', 2010, 0)
    4652        self.assertEqual(result,
    4753            [[], [], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')]])
     
    5056    def test_get_students_without_scores(self):
    5157        self.student['studycourse']['100']['Course1'].score = None
    52         result = get_students('fac1', 'dep1', 2010, 0)
     58        result = get_students('fac1', 'dep1', 'CERT1', 2010, 0)
    5359        self.assertEqual(result,
    5460            [[], [], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')]])
     
    5662    def test_get_students_without_level_in_session(self):
    5763        self.student['studycourse']['100'].level_session = 2011
    58         result = get_students('fac1', 'dep1', 2010)
     64        result = get_students('fac1', 'dep1', 'CERT1', 2010)
    5965        self.assertEqual(result,
    6066            [[], [], [], [], [], [], []])
     
    6268
    6369    def test_create_pdf(self):
    64         report = SessionResultsPresentation('fac1', 'dep1', 2010, 100)
     70        report = SessionResultsPresentation('fac1', 'dep1', 'CERT1', 2010, 100)
    6571        result = report.create_pdf('JOB_ID')
    6672        self.assertTrue(result.startswith('%PDF-'))
     
    8086        self.student['studycourse']['620'] = studylevel
    8187        self.student['studycourse']['620']['Course2'] = ticket
    82         report = SessionResultsPresentation('fac1', 'dep1', 2013, 620)
     88        report = SessionResultsPresentation('fac1', 'dep1', 'CERT1', 2013, 620)
    8389        result = report.create_pdf('JOB_ID')
    8490        self.assertTrue(result.startswith('%PDF-'))
     
    101107        self.student['studycourse']['200'] = studylevel
    102108        self.student['studycourse']['200']['Course2'] = ticket
    103         report = SessionResultsPresentation('fac1', 'dep1', 2010, 0)
     109        report = SessionResultsPresentation('fac1', 'dep1', 'CERT1', 2010, 0)
    104110        result = report.create_pdf('JOB_ID')
    105111        self.assertTrue(result.startswith('%PDF-'))
     
    137143        self.browser.getControl(name="level").value = [level]
    138144        self.browser.getControl(name="session").value = ['2010']
    139         self.browser.getControl(name="faccode_depcode").value = ['fac1_dep1']
     145        self.browser.getControl(name="faccode_depcode_certcode").value = ['fac1_dep1_CERT1']
    140146        self.browser.getControl("Create").click()
    141147        return
     
    152158                         'application/pdf')
    153159        self.assertTrue(
    154             'filename="SessionResultsPresentation_fac1_dep1_2010_100_' in
     160            'filename="SessionResultsPresentation_fac1_dep1_CERT1_2010_100_' in
    155161            self.browser.headers['content-disposition'])
    156162        self.assertEqual(len(self.app['reports'].running_report_jobs), 1)
     
    166172        self.assertTrue(
    167173            'INFO - zope.mgr - students.reports.session_results_presentation.SessionResultsPresentationGeneratorPage - '
    168             'report %s created: Session Results Presentation (faculty=fac1, department=dep1, session=2010, level=100)'
     174            'report %s created: Session Results Presentation '
     175            '(faculty=fac1, department=dep1, certificate=CERT1, session=2010, level=100)'
    169176            % job_id in logcontent
    170177            )
    171178        self.assertTrue(
    172179            'INFO - zope.mgr - students.reports.session_results_presentation.SessionResultsPresentationPDFView - '
    173             'report %s downloaded: SessionResultsPresentation_fac1_dep1_2010_100_'
     180            'report %s downloaded: SessionResultsPresentation_fac1_dep1_CERT1_2010_100_'
    174181            % job_id in logcontent
    175182            )
     
    192199                         'application/pdf')
    193200        self.assertTrue(
    194             'filename="SessionResultsPresentation_fac1_dep1_2010_0_' in
     201            'filename="SessionResultsPresentation_fac1_dep1_CERT1_2010_0_' in
    195202            self.browser.headers['content-disposition'])
    196203        self.assertEqual(len(self.app['reports'].running_report_jobs), 1)
     
    206213        self.assertTrue(
    207214            'INFO - zope.mgr - students.reports.session_results_presentation.SessionResultsPresentationGeneratorPage - '
    208             'report %s created: Session Results Presentation (faculty=fac1, department=dep1, session=2010, level=0)'
     215            'report %s created: Session Results Presentation '
     216            '(faculty=fac1, department=dep1, certificate=CERT1, session=2010, level=0)'
    209217            % job_id in logcontent
    210218            )
    211219        self.assertTrue(
    212220            'INFO - zope.mgr - students.reports.session_results_presentation.SessionResultsPresentationPDFView - '
    213             'report %s downloaded: SessionResultsPresentation_fac1_dep1_2010_0_'
     221            'report %s downloaded: SessionResultsPresentation_fac1_dep1_CERT1_2010_0_'
    214222            % job_id in logcontent
    215223            )
Note: See TracChangeset for help on using the changeset viewer.