Changeset 12898


Ignore:
Timestamp:
2 May 2015, 06:12:58 (10 years ago)
Author:
Henrik Bettermann
Message:

Adjust level_report and session_results_presentation so that all possible study levels can be selected.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/level_report.py

    r12897 r12898  
    8181from waeup.kofa.reports import Report
    8282from waeup.kofa.browser.interfaces import IPDFCreator
    83 from waeup.kofa.university.vocabularies import course_levels
    8483
    8584STYLE = getSampleStyleSheet()
     
    148147            args=[faccode, depcode, session, level], kwargs={'author':author})
    149148        site = grok.getSite()
     149        self.studylevelsource = StudyLevelSource().factory
     150        self.portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    150151        self.session = academic_sessions_vocab.getTerm(session).title
    151         self.level = course_levels.getTerm(level).title
     152        self.level = translate(self.studylevelsource.getTitle(None, int(level)),
     153            'waeup.kofa', target_language=self.portal_language)
    152154        self.levelcode = level
    153155        self.sessioncode = session
     
    170172                              STYLE["Normal"]),
    171173                    Spacer(1, 12),]
    172         pdf_data += [Paragraph('%s<br />%s<br />Level: %s<br />Session: %s' % (
    173                     self.factitle, self.deptitle, self.level, self.session),
     174        pdf_data += [Paragraph(
     175                    translate(
     176                        '${a}<br />${b}<br />Level: ${c}<br />Session: ${d}',
     177                        mapping = {'a':self.factitle,
     178                                   'b':self.deptitle,
     179                                   'c':self.level,
     180                                   'd':self.session, }),
    174181                    STYLE["Normal"]),
    175182                    Spacer(1, 12),]
     
    179186
    180187        pdf_data.append(Spacer(1, 40))
    181         signatures = ['Ag. Head of Department', 'Dean of Faculty']
     188        signatures = [
     189            translate(_('Ag. Head of Department')),
     190            translate(_('Dean of Faculty'))]
    182191        signaturetables = get_signature_tables(signatures, landscape=True)
    183192        pdf_data.append(signaturetables[0])
     
    239248            container = self.context.__parent__
    240249            user_id = self.request.principal.id
    241             if level is not None:
     250            if level:
    242251                level = int(level)
    243             if session is not None:
     252            if session:
    244253                session = int(session)
    245254            kw = dict(
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/session_results_presentation.py

    r11254 r12898  
    1717##
    1818import grok
     19from zope.i18n import translate
    1920from zope.catalog.interfaces import ICatalog
    2021from zope.component import queryUtility, getUtility
     
    2324    IKofaUtils,
    2425    academic_sessions_vocab, registration_states_vocab)
     26from waeup.kofa.students.vocabularies import StudyLevelSource
    2527from waeup.kofa.students.interfaces import IStudentsUtils
    2628from waeup.kofa.interfaces import MessageFactory as _
     
    6062                stud.display_fullname,
    6163                )
    62         if level is not None:
     64        if level != 0:
    6365            if not stud['studycourse'].has_key(str(level)):
    6466                continue
     
    7678                continue
    7779            if itemcount > 1:
    78                 # Error: more than one session registered in this session
     80                # Error: more than one level registered in this session
    7981                table[len(students_utils.gpa_boundaries)].append(line)
    8082                continue
     
    9597from waeup.kofa.reports import Report
    9698from waeup.kofa.browser.interfaces import IPDFCreator
    97 from waeup.kofa.university.vocabularies import course_levels
    9899
    99100STYLE = getSampleStyleSheet()
     
    121122            args=[faccode, depcode, session, level], kwargs={'author':author})
    122123        site = grok.getSite()
     124        self.studylevelsource = StudyLevelSource().factory
     125        self.portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    123126        self.session = academic_sessions_vocab.getTerm(session).title
    124         if level == None:
    125             self.level = 'All levels'
     127        if level == 0:
     128            self.level = translate(_('all levels'))
    126129        else:
    127             self.level = course_levels.getTerm(level).title
     130            self.level = translate(self.studylevelsource.getTitle(None, int(level)),
     131                'waeup.kofa', target_language=self.portal_language)
    128132        self.levelcode = level
    129133        self.sessioncode = session
     
    181185class SessionResultsPresentationGenerator(grok.GlobalUtility):
    182186
    183     title = _('Session Results Presentation')
     187    title = 'Session Results Presentation'
    184188    grok.name('session_results_presentation')
    185189
     
    208212    def update(self, CREATE=None, faccode_depcode=None,
    209213               session=None, level=None):
    210         if level == 'all':
    211             level = None
    212214        super(SessionResultsPresentationGeneratorPage, self).update(
    213215            CREATE, faccode_depcode ,session, level)
    214216
     217    #def _set_level_values(self):
     218    #    vocab_terms = course_levels.by_value.values()
     219    #    self.levels = [('All levels', 'all')] + sorted(
     220    #        [(x.title, x.token) for x in vocab_terms])
     221    #    return
     222
    215223    def _set_level_values(self):
    216         vocab_terms = course_levels.by_value.values()
    217         self.levels = [('All levels', 'all')] + sorted(
    218             [(x.title, x.token) for x in vocab_terms])
     224        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     225        studylevelsource = StudyLevelSource().factory
     226        self.levels = [(u'All levels', 0)]
     227        for code in studylevelsource.getValues(None):
     228            title = translate(studylevelsource.getTitle(None, code),
     229                'waeup.kofa', target_language=portal_language)
     230            self.levels.append((title, code))
    219231        return
    220232
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_session_results_presentation.py

    r10581 r12898  
    1212from waeup.kofa.tests.test_async import FunctionalAsyncTestCase
    1313from waeup.kofa.browser.tests.test_pdf import samples_dir
    14 from waeup.kofa.students.studylevel import StudentStudyLevel
     14from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket
    1515
    1616class SessionResultsPresentationTests(CatalogTestSetup):
     
    3232
    3333    def test_get_students_at_all_levels(self):
    34         result = get_students('fac1', 'dep1', 2010)
     34        result = get_students('fac1', 'dep1', 2010, 0)
    3535        self.assertEqual(result,
    3636            [[], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')], []])
     
    4343        studylevel.level_session = 2010
    4444        self.student['studycourse']['200'] = studylevel
    45         result = get_students('fac1', 'dep1', 2010)
     45        result = get_students('fac1', 'dep1', 2010, 0)
    4646        self.assertEqual(result,
    4747            [[], [], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')]])
     
    5050    def test_get_students_without_scores(self):
    5151        self.student['studycourse']['100']['Course1'].score = None
    52         result = get_students('fac1', 'dep1', 2010)
     52        result = get_students('fac1', 'dep1', 2010, 0)
    5353        self.assertEqual(result,
    5454            [[], [], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')]])
     
    7070        return
    7171
     72    def test_create_pdf_620(self):
     73        studylevel = StudentStudyLevel()
     74        studylevel.level = 620
     75        studylevel.level_session = 2013
     76        ticket = CourseTicket()
     77        ticket.code = 'Course2'
     78        ticket.credits = 40
     79        ticket.score = 44
     80        self.student['studycourse']['620'] = studylevel
     81        self.student['studycourse']['620']['Course2'] = ticket
     82        report = SessionResultsPresentation('fac1', 'dep1', 2013, 620)
     83        result = report.create_pdf()
     84        self.assertTrue(result.startswith('%PDF-'))
     85        path = os.path.join(samples_dir(), 'session_results_presentation_620.pdf')
     86        open(path, 'wb').write(result)
     87        print "Sample session_results_presentation_620.pdf written to %s" % path
     88        return
     89
    7290    def test_create_pdf_with_two_levels_in_session(self):
    73         # Register second level in the same session (which shouldn't be!)
     91        # Register second level with tickets in the same session (which shouldn't be!)
    7492        # Check the pdf file if the student record has really been classified
    7593        # as erroneous.
     
    7795        studylevel.level = 200
    7896        studylevel.level_session = 2010
     97        ticket = CourseTicket()
     98        ticket.code = 'Course2'
     99        ticket.credits = 40
     100        ticket.score = 11
    79101        self.student['studycourse']['200'] = studylevel
    80         report = SessionResultsPresentation('fac1', 'dep1', 2010, None)
     102        self.student['studycourse']['200']['Course2'] = ticket
     103        report = SessionResultsPresentation('fac1', 'dep1', 2010, 0)
    81104        result = report.create_pdf()
    82105        self.assertTrue(result.startswith('%PDF-'))
     
    160183    def test_report_download_all_levels(self):
    161184        # We can download a generated report for all levels
    162         self.trigger_report_creation(level='all')
     185        self.trigger_report_creation(level='0')
    163186        # When the job is finished and we reload the page...
    164187        job_id = self.wait_for_report_job_completed()
     
    169192                         'application/pdf')
    170193        self.assertTrue(
    171             'filename="SessionResultsPresentation_fac1_dep1_2010_None_' in
     194            'filename="SessionResultsPresentation_fac1_dep1_2010_0_' in
    172195            self.browser.headers['content-disposition'])
    173196        self.assertEqual(len(self.app['reports'].running_report_jobs), 1)
     
    183206        self.assertTrue(
    184207            'INFO - zope.mgr - students.reports.session_results_presentation.SessionResultsPresentationGeneratorPage - '
    185             'report %s created: Session Results Presentation (faculty=fac1, department=dep1, session=2010, level=None)'
     208            'report %s created: Session Results Presentation (faculty=fac1, department=dep1, session=2010, level=0)'
    186209            % job_id in logcontent
    187210            )
    188211        self.assertTrue(
    189212            'INFO - zope.mgr - students.reports.session_results_presentation.SessionResultsPresentationPDFView - '
    190             'report %s downloaded: SessionResultsPresentation_fac1_dep1_2010_None_'
     213            'report %s downloaded: SessionResultsPresentation_fac1_dep1_2010_0_'
    191214            % job_id in logcontent
    192215            )
Note: See TracChangeset for help on using the changeset viewer.