Ignore:
Timestamp:
24 Nov 2023, 11:20:06 (13 months ago)
Author:
Henrik Bettermann
Message:

Implement a QR Code view.

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

Legend:

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

    r17497 r17650  
    2424import os
    2525import textwrap
     26import segno
    2627from cStringIO import StringIO
    2728from datetime import datetime
     
    632633            self.context.student, omit_fields=self.omit_fields,
    633634            letterhead_path=letterhead_path, post_text=None)
     635
     636class QRCodeView(UtilityView, grok.View):
     637    """View which renders a QRCode only.
     638    """
     639    grok.context(IStudent)
     640    grok.name('qrcode_admission_letter.png')
     641    grok.require('waeup.viewStudent')
     642    scale = 3
     643    uri = 'admission_slip.pdf'
     644
     645    def render(self):
     646        qrcode = segno.make(self.url(self.context, self.uri))
     647        self.response.setHeader('Content-Type', 'image/png')
     648        return qrcode.png_data_uri(
     649            scale=self.scale).split(',')[1].decode('base64')
    634650
    635651class StudentBaseManageFormPage(KofaEditFormPage):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r17261 r17650  
    30353035                           self.browser.contents)
    30363036
     3037    def test_student_qrcodeview(self):
     3038        IWorkflowInfo(self.student).fireTransition('admit')
     3039        self.browser.open(self.login_path)
     3040        self.browser.getControl(name="form.login").value = self.student_id
     3041        self.browser.getControl(name="form.password").value = 'spwd'
     3042        self.browser.getControl("Login").click()
     3043        self.browser.open(self.student_path + '/qrcode_admission_letter.png')
     3044        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     3045        self.assertEqual(self.browser.headers['Content-Type'], 'image/png')
     3046        path = os.path.join(samples_dir(), 'qrcode_admission_letter.png')
     3047        open(path, 'wb').write(self.browser.contents)
     3048        print "Sample png file written to %s" % path
     3049
    30373050    def test_student_course_registration(self):
    30383051        # Student cant login if their password is not set
Note: See TracChangeset for help on using the changeset viewer.