Ignore:
Timestamp:
24 May 2019, 09:59:55 (6 years ago)
Author:
Henrik Bettermann
Message:

Add attendance_sheet.pdf view.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/viewlets.py

    r15422 r15423  
    628628    grok.order(5)
    629629
     630class DownloadAttendanceSheetActionButton(ManageActionButton):
     631    """ 'Download ticket overview' button for courses.
     632    """
     633    grok.context(ICourse)
     634    grok.view(CoursePage)
     635    grok.name('attendance')
     636    grok.require('waeup.showStudents')
     637    icon = 'actionicon_pdf.png'
     638    text = _('Download attendance sheet')
     639    target = 'attendance.pdf'
     640    grok.order(6)
     641
    630642class DownloadCSVFileActionButton(ManageActionButton):
    631643    """ 'Download csv file' button for courses.
     
    638650    text = _('Download csv file (editable scores only)')
    639651    target = 'download_scores'
    640     grok.order(7)
     652    grok.order(1)
    641653
    642654class ManageCertificateActionButton(ManageActionButton):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r15422 r15423  
    36403640        students_utils = getUtility(IStudentsUtils)
    36413641        return students_utils.renderPDFCourseticketsOverview(
    3642             self, session, self.data(session), lecturers, 'landscape', 90,
    3643             self.note)
     3642            self, 'coursetickets', session, self.data(session), lecturers,
     3643            'landscape', 90, self.note)
     3644
     3645class ExportAttendanceSlip(UtilityView, grok.View,
     3646    LocalRoleAssignmentUtilityView):
     3647    """Deliver a PDF slip of course tickets in attendance sheet format.
     3648    """
     3649    grok.context(ICourse)
     3650    grok.name('attendance.pdf')
     3651    grok.require('waeup.showStudents')
     3652
     3653    @property
     3654    def note(self):
     3655        return
     3656
     3657    def data(self, session):
     3658        cat = queryUtility(ICatalog, name='coursetickets_catalog')
     3659        # Attention: Also tickets of previous studycourses are found
     3660        coursetickets = cat.searchResults(
     3661            session=(session, session),
     3662            code=(self.context.code, self.context.code)
     3663            )
     3664        header = [[_('Student Id'),
     3665                   _('Matric No.'),
     3666                   _('Level'),
     3667                   _('Course of Studies'),
     3668                   _('Booklet No.'),
     3669                   _('Signature'),
     3670                   ],]
     3671        tickets = []
     3672        for ticket in list(coursetickets):
     3673            row = [ticket.student.student_id,
     3674                  ticket.student.matric_number,
     3675                  ticket.level,
     3676                  ticket.student.certcode,
     3677                  None,
     3678                  50 * ' ',
     3679                  ]
     3680            tickets.append(row)
     3681        return header + sorted(tickets, key=lambda value: value[0]), None
     3682
     3683    def render(self):
     3684        session = grok.getSite()['configuration'].current_academic_session
     3685        lecturers = [i['user_title'] for i in self.getUsersWithLocalRoles()
     3686                     if i['local_role'] == 'waeup.local.Lecturer']
     3687        lecturers =  ', '.join(lecturers)
     3688        students_utils = getUtility(IStudentsUtils)
     3689        return students_utils.renderPDFCourseticketsOverview(
     3690            self, 'attendance', session, self.data(session),
     3691            lecturers, 'landscape', 90, self.note)
    36443692
    36453693class ExportJobContainerOverview(KofaPage):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py

    r15333 r15423  
    157157
    158158    def renderPDFCourseticketsOverview(
    159                   view, session, data, lecturers, orientation,
     159                  view, name, session, data, lecturers, orientation,
    160160                  title_length, note):
    161161        """Render pdf slip of course tickets for a lecturer.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r15422 r15423  
    45174517        print "Sample PDF coursetickets.pdf written to %s" % path
    45184518
     4519    def test_lecturers_can_download_attendance_sheet(self):
     4520        # A course ticket slip can be downloaded
     4521        self.course.title = (u'Lorem ipsum     dolor sit amet, consectetur     adipisici, '
     4522                             u'sed         eiusmod tempor    incidunt ut  labore et dolore')
     4523        self.login_as_lecturer()
     4524        pdf_url = '%s/attendance.pdf' % self.course_url
     4525        self.browser.open(pdf_url)
     4526        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     4527        self.assertEqual(
     4528            self.browser.headers['Content-Type'], 'application/pdf')
     4529        path = os.path.join(samples_dir(), 'attendance.pdf')
     4530        open(path, 'wb').write(self.browser.contents)
     4531        print "Sample PDF attendance.pdf written to %s" % path
     4532
     4533
    45194534    def test_lecturers_can_download_scores_as_csv(self):
    45204535        # Lecturers can download course scores as CSV.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r15337 r15423  
    10081008
    10091009    def renderPDFCourseticketsOverview(
    1010             self, view, session, data, lecturers, orientation,
     1010            self, view, name, session, data, lecturers, orientation,
    10111011            title_length, note):
    10121012        """Render pdf slip of course tickets for a lecturer.
    10131013        """
    1014         filename = 'coursetickets_%s_%s_%s.pdf' % (
    1015             view.context.code, session, view.request.principal.id)
     1014        filename = '%s_%s_%s_%s.pdf' % (
     1015            name, view.context.code, session, view.request.principal.id)
    10161016        session = academic_sessions_vocab.getTerm(session).title
    10171017        creator = getUtility(IPDFCreator, name=orientation)
     
    10551055                       'b':view.context.code,
    10561056                       'd':session}))
     1057        if name == 'attendance':
     1058            doc_title += _('\nAttendance Sheet')
     1059        if name == 'coursetickets':
     1060            doc_title += _('\nCourse Tickets Overview')
    10571061        footer_title = translate(_('${a} (${b}) - ${d}',
    10581062            mapping = {'a':ft,
Note: See TracChangeset for help on using the changeset viewer.