Changeset 13898


Ignore:
Timestamp:
9 Jun 2016, 12:36:41 (9 years ago)
Author:
Henrik Bettermann
Message:

Add ExportPDFScoresSlip.

Location:
main/waeup.kofa/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r13894 r13898  
    441.4.2.dev0 (unreleased)
    55=======================
     6
     7* Add `ExportPDFScoresSlip`.
    68
    79* Add `DownloadScoresView` which is for lecturers only. Remove
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/viewlets.py

    r13894 r13898  
    551551    grok.order(1)
    552552
     553class DownloadTicketOverviewActionButton(ManageActionButton):
     554    """ 'Download ticket overview' button for courses.
     555    """
     556    grok.context(ICourse)
     557    grok.view(EditScoresPage)
     558    grok.name('coursetickets')
     559    grok.require('waeup.editScores')
     560    icon = 'actionicon_pdf.png'
     561    text = _('Download pdf file')
     562    target = 'coursetickets.pdf'
     563    grok.order(2)
     564
    553565class ManageCertificateActionButton(ManageActionButton):
    554566    """ 'Manage settings' button for certificates.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r13894 r13898  
    3939from waeup.kofa.browser.breadcrumbs import Breadcrumb
    4040from waeup.kofa.browser.pages import (
    41     ContactAdminFormPage, ExportCSVView, doll_up, exports_not_allowed)
     41    ContactAdminFormPage, ExportCSVView, doll_up, exports_not_allowed,
     42    LocalRoleAssignmentUtilityView)
    4243from waeup.kofa.browser.interfaces import ICaptchaManager
    4344from waeup.kofa.hostels.hostel import NOT_OCCUPIED
     
    31633164    grok.require('waeup.editScores')
    31643165    grok.name('download_scores')
    3165     redirect_target = '@@export'
    31663166
    31673167    def update(self):
     
    31943194            'Content-Disposition:', 'attachment; filename="%s' % filename)
    31953195        return self.csv
     3196
     3197class ExportPDFScoresSlip(UtilityView, grok.View,
     3198    LocalRoleAssignmentUtilityView):
     3199    """Deliver a PDF slip of course tickets for a lecturer.
     3200    """
     3201    grok.context(ICourse)
     3202    grok.name('coursetickets.pdf')
     3203    grok.require('waeup.editScores')
     3204
     3205    def table_data(self, session):
     3206        cat = queryUtility(ICatalog, name='coursetickets_catalog')
     3207        coursetickets = cat.searchResults(
     3208            session=(session, session),
     3209            code=(self.context.code, self.context.code)
     3210            )
     3211        result = [[_('Matric No.'),
     3212                   _('Reg. No.'),
     3213                   _('Fullname'),
     3214                   _('Status'),
     3215                   _('Course of Studies'),
     3216                   _('Level'),
     3217                   _('Score') ],]
     3218        for ticket in list(coursetickets):
     3219            row = [ticket.student.matric_number,
     3220                  ticket.student.reg_number,
     3221                  ticket.student.display_fullname,
     3222                  ticket.student.translated_state,
     3223                  ticket.student.certcode,
     3224                  ticket.level,
     3225                  ticket.score]
     3226            result.append(row)
     3227        return result
     3228
     3229    def render(self):
     3230        session = grok.getSite()['configuration'].current_academic_session
     3231        lecturers = [i['user_title'] for i in self.getUsersWithLocalRoles()
     3232                     if i['local_role'] == 'waeup.local.Lecturer']
     3233        lecturers =  ', '.join(lecturers)
     3234        students_utils = getUtility(IStudentsUtils)
     3235        return students_utils.renderPDFCourseticketsOverview(
     3236            self, session, self.table_data(session), lecturers)
    31963237
    31973238class ExportJobContainerOverview(KofaPage):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r13894 r13898  
    18891889        self.assertTrue('mrslecturer - students.browser.EditScoresPage - '
    18901890                        'K1000000 100/COURSE1 score updated (None)' in logcontent)
     1891        # A course ticket slip can be downloaded
     1892        self.browser.open(
     1893            "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/coursetickets.pdf")
     1894        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     1895        self.assertEqual(self.browser.headers['Content-Type'],
     1896                         'application/pdf')
     1897        path = os.path.join(samples_dir(), 'coursetickets.pdf')
     1898        open(path, 'wb').write(self.browser.contents)
     1899        print "Sample PDF coursetickets.pdf written to %s" % path
     1900
    18911901
    18921902    def test_change_current_mode(self):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r13797 r13898  
    5555    ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
    5656    ('BOX', (0,0), (-1,-1), 1, colors.black),
    57 
    5857    ]
    5958
     
    936935        return pdf_stream
    937936
     937    def renderPDFCourseticketsOverview(
     938            self, view, session, table_data, lecturers):
     939        filename = 'coursetickets_%s_%s_%s.pdf' % (
     940            view.context.code, session, view.request.principal.id)
     941        session = academic_sessions_vocab.getTerm(session).title
     942        creator = getUtility(IPDFCreator)
     943        style = getSampleStyleSheet()
     944        pdf_data = [Table(table_data, style=CONTENT_STYLE)]
     945        doc_title = translate(
     946            _('${a} - Session ${b}\n'
     947              'Lecturer(s): ${c}',
     948            mapping = {'a':view.context.code, 'b':session, 'c':lecturers}))
     949        author = '%s (%s)' % (view.request.principal.title,
     950                              view.request.principal.id)
     951        view.response.setHeader(
     952            'Content-Type', 'application/pdf')
     953        view.response.setHeader(
     954            'Content-Disposition:', 'attachment; filename="%s' % filename)
     955        pdf_stream = creator.create_pdf(
     956            pdf_data, None, doc_title, author, doc_title + ' -'
     957            )
     958        return pdf_stream
     959
    938960    def maxCredits(self, studylevel):
    939961        """Return maximum credits.
Note: See TracChangeset for help on using the changeset viewer.