Ignore:
Timestamp:
15 Mar 2017, 12:08:35 (8 years ago)
Author:
Henrik Bettermann
Message:

Add GradSessionResultsPresentation?.

Location:
main/waeup.aaue/trunk/src/waeup/aaue/students/reports
Files:
2 edited

Legend:

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

    r14600 r14631  
    1919import grok
    2020from zope.component import getUtility
     21from zope.interface import implementer, Interface, Attribute
    2122from waeup.kofa.interfaces import IKofaUtils
    2223from waeup.kofa.students.reports.session_results_presentation import (
    23     SessionResultsPresentation, SessionResultsPresentationGenerator)
     24    SessionResultsPresentation, SessionResultsPresentationGenerator,
     25    ISessionResultsPresentation, SessionResultsPresentationGeneratorPage,
     26    SessionResultsPresentationPDFView)
    2427
    2528class CustomSessionResultsPresentation(SessionResultsPresentation):
     
    9093            level=level, author=author)
    9194        return result
     95
     96
     97# Session Results Presentation for graduating students only
     98
     99class IGradSessionResultsPresentation(ISessionResultsPresentation):
     100    """Marker interface to distuingish graduating students level reports
     101    from ordinary level reports.
     102    """
     103
     104@implementer(IGradSessionResultsPresentation)
     105class GradSessionResultsPresentation(CustomSessionResultsPresentation):
     106    """
     107    """
     108
     109    title = 'Presentation of Results to Senate'
     110
     111    @property
     112    def right_footer(self):
     113        return self.title + ' (graduating students only) - %s -' % self.session
     114
     115    def _excluded(self, level_obj):
     116        """
     117        """
     118        final_level = max(level_obj.student['studycourse'].keys())
     119        final_level_obj = level_obj.student['studycourse'][final_level]
     120        if final_level_obj.remark not in (
     121            'Pass', '3s_rd_s', '2s_2_s', '2s_1_s', '1s_st_s'):
     122            return True
     123        return False
     124
     125class GradSessionResultsPresentationGenerator(SessionResultsPresentationGenerator):
     126
     127    title = 'Presentation of Graduating Students Results to Senate'
     128    grok.name('grad_session_results_presentation')
     129
     130    def generate(self, site, faccode=None, depcode=None, certcode=None,
     131                 session=None, level=None, author=None):
     132        result = GradSessionResultsPresentation(faccode=faccode, depcode=depcode,
     133            certcode=certcode, session=session, level=level, author=author)
     134        return result
     135
     136class GradSessionResultsPresentationGeneratorPage(SessionResultsPresentationGeneratorPage):
     137
     138    grok.context(GradSessionResultsPresentationGenerator)
     139
     140class GradSessionResultsPresentationPDFView(SessionResultsPresentationPDFView):
     141
     142    grok.context(IGradSessionResultsPresentation)
     143    grok.name('pdf')
     144    grok.require('waeup.handleReports')
     145
     146    def _filename(self):
     147        return 'GradSessionResultsPresentation_rno%s_%s.pdf' % (
     148            self.context.__name__,
     149            self.context.creation_dt_string)
  • main/waeup.aaue/trunk/src/waeup/aaue/students/reports/tests/test_session_results_presentation.py

    r14608 r14631  
    1212from waeup.kofa.browser.tests.test_pdf import samples_dir
    1313
    14 from waeup.aaue.students.reports.session_results_presentation import CustomSessionResultsPresentation
     14from waeup.aaue.students.reports.session_results_presentation import (
     15    CustomSessionResultsPresentation,
     16    GradSessionResultsPresentation,
     17    IGradSessionResultsPresentation)
    1518
    1619from waeup.aaue.testing import FunctionalLayer
     
    4043        return
    4144
    42 
    4345    def test_create_pdf(self):
    4446        self.certificate.degree = 'BA(FS)'
     
    5557
    5658 
     59class GradSessionResultsPresentationTests(CatalogTestSetup):
     60
     61    layer = FunctionalLayer
     62
     63    def test_iface(self):
     64        # ensure we fullfill interface contracts
     65        obj = GradSessionResultsPresentation('fac1', 'dep1', 'CERT1', 2010, 100)
     66        verifyClass(IGradSessionResultsPresentation, GradSessionResultsPresentation)
     67        verifyObject(IGradSessionResultsPresentation, obj)
     68        return
     69
     70    def test_get_students(self):
     71        sr = GradSessionResultsPresentation('fac1', 'dep1', 'CERT1', 2010, 100)
     72        result = sr._get_students('fac1', 'dep1', 'CERT1', 2010, 100)
     73        self.assertEqual(result, [[], [], [], [], [], [], []])
     74        # if end level is 100, the student seems graduating and
     75        # we can get a table with one student
     76        self.certificate.end_level = 100
     77        self.student['studycourse']['100']['Course1'].credits = 91
     78        result = sr._get_students('fac1', 'dep1', 'CERT1', 2010, 100)
     79        self.assertEqual(result, [[], [], [], [], [], [], []])
     80        self.student['studycourse']['100']['Course1'].score = 60
     81        self.student['studycourse']['100']['Course1'].ca = 10
     82        result = sr._get_students('fac1', 'dep1', 'CERT1', 2010, 100)
     83        self.assertEqual(result,
     84            [[], [], [], [], [], [(u'E1000000', u'1234', u'TESTER, Bob')], []])
     85        return
     86
     87    def test_create_pdf(self):
     88        self.certificate.degree = 'BA(FS)'
     89        self.certificate.end_level = 100
     90        self.student['studycourse']['100']['Course1'].credits = 91
     91        self.student['studycourse']['100']['Course1'].ca = 0
     92        self.app['faculties']['fac1'].officer_1 = 'Rosa Moonshine - Dean of Faculty'
     93        self.app['faculties']['fac1']['dep1'].officer_1 = 'Amalia Sunshine - Head of Department'
     94        self.app['faculties']['fac1']['dep1'].officer_2 = 'Theresa Starbright - External Examiner'
     95        report = GradSessionResultsPresentation('fac1', 'dep1', 'CERT1', 2010, 100)
     96        result = report.create_pdf('JOB_ID')
     97        self.assertTrue(result.startswith('%PDF-'))
     98        path = os.path.join(samples_dir(), 'grad_session_results_presentation.pdf')
     99        open(path, 'wb').write(result)
     100        print "Sample grad_session_results_presentation.pdf written to %s" % path
     101        return
     102
Note: See TracChangeset for help on using the changeset viewer.