Changeset 10692 for main/waeup.kwarapoly


Ignore:
Timestamp:
4 Nov 2013, 10:57:34 (11 years ago)
Author:
Henrik Bettermann
Message:

Customize course registration slip.

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

Legend:

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

    r10691 r10692  
    2020from zope.component import getUtility
    2121from hurry.workflow.interfaces import IWorkflowInfo
    22 from waeup.kofa.interfaces import ADMITTED
     22from waeup.kofa.interfaces import ADMITTED, IKofaUtils
    2323from waeup.kofa.browser.layout import UtilityView
    2424from waeup.kofa.students.interfaces import IStudentsUtils
    2525from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
    2626from waeup.kofa.students.browser import (
    27     StartClearancePage, BedTicketAddPage, ExportPDFAdmissionSlipPage)
     27    StartClearancePage, BedTicketAddPage, ExportPDFAdmissionSlipPage,
     28    StudentBasePDFFormPage)
    2829from waeup.kwarapoly.students.interfaces import (
    29     ICustomStudent, ICustomStudentBase)
     30    ICustomStudent, ICustomStudentBase, ICustomStudentStudyLevel)
    3031from waeup.kwarapoly.interfaces import MessageFactory as _
    3132from waeup.kofa.students.workflow import (
     
    3738    NigeriaExportPDFPaymentSlipPage,
    3839    NigeriaStudentClearanceEditFormPage,
     40    NigeriaExportPDFCourseRegistrationSlipPage,
    3941    )
    4042
     
    129131            self.context.student, omit_fields=self.omit_fields,
    130132            pre_text=pre_text, post_text=post_text)
     133
     134# copied from waeup.aaue
     135class CustomExportPDFCourseRegistrationSlipPage(
     136    NigeriaExportPDFCourseRegistrationSlipPage):
     137    """Deliver a PDF slip of the context.
     138    """
     139    grok.context(ICustomStudentStudyLevel)
     140    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
     141        'level_session', 'level_verdict',
     142        'validated_by', 'validation_date', 'gpa')
     143
     144    omit_fields = ('password', 'suspended', 'suspended_comment',
     145        'phone', 'adm_code', 'sex', 'email', 'date_of_birth',
     146        'department', 'current_mode')
     147
     148    @property
     149    def title(self):
     150        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     151        return translate(_('Credits Registered'), 'waeup.kofa',
     152            target_language=portal_language)
     153
     154    def _signatures(self):
     155        return (
     156            [('I have selected the course on the advise of my Head of '
     157             'Department. <br>', _('Student\'s Signature'), '<br>')],
     158            [('This student has satisfied the department\'s requirements. '
     159             'I recommend to approve the course registration. <br>',
     160             _('Head of Department\'s Signature'), '<br>')],
     161            [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')],
     162            [('', _('Director\'s Signature'))]
     163            )
     164
     165    def render(self):
     166        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     167        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
     168        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
     169        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
     170        Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
     171        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
     172        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
     173        Signature = translate(_('HOD\'s Signature'), 'waeup.kwarapoly',
     174            target_language=portal_language)
     175        studentview = StudentBasePDFFormPage(self.context.student,
     176            self.request, self.omit_fields)
     177        students_utils = getUtility(IStudentsUtils)
     178
     179        tabledata = []
     180        tableheader = []
     181        contenttitle = []
     182        for i in range(1,7):
     183            tabledata.append(sorted(
     184                [value for value in self.context.values() if value.semester == i],
     185                key=lambda value: str(value.semester) + value.code))
     186            tableheader.append([(Code,'code', 2.0),
     187                               (Title,'title', 7),
     188                               (Cred, 'credits', 1.5),
     189                               (Score, 'score', 1.4),
     190                               (Grade, 'grade', 1.4),
     191                               (Signature, 'dummy', 3),
     192                               ])
     193        if len(self.label.split('\n')) == 3:
     194            topMargin = 1.9
     195        elif len(self.label.split('\n')) == 2:
     196            topMargin = 1.7
     197        else:
     198            topMargin = 1.5
     199        return students_utils.renderPDF(
     200            self, 'course_registration_slip.pdf',
     201            self.context.student, studentview,
     202            tableheader=tableheader,
     203            tabledata=tabledata,
     204            signatures=self._signatures(),
     205            topMargin=topMargin,
     206            omit_fields=self.omit_fields
     207            )
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/tests/test_browser.py

    r10691 r10692  
    3232from waeup.kofa.interfaces import (
    3333    IExtFileStore, IFileStoreNameChooser)
     34from waeup.kofa.browser.tests.test_pdf import samples_dir
    3435from waeup.kofa.students.interfaces import IStudentsUtils
    3536from waeup.kwarapoly.testing import FunctionalLayer
     
    348349
    349350    def test_pdf_slips(self):
    350         IWorkflowState(self.student).setState('school fee paid')
    351351        # Login
    352352        self.browser.open(self.login_path)
     
    354354        self.browser.getControl(name="form.password").value = 'spwd'
    355355        self.browser.getControl("Login").click()
     356        # admission slip
     357        IWorkflowState(self.student).setState('school fee paid')
    356358        self.browser.open(self.student_path)
    357359        self.browser.getLink("Download admission letter").click()
     
    359361        self.assertEqual(self.browser.headers['Content-Type'],
    360362                         'application/pdf')
     363        path = os.path.join(samples_dir(), 'admission_slip.pdf')
     364        open(path, 'wb').write(self.browser.contents)
     365        print "Sample PDF admission_slip_slip.pdf written to %s" % path
    361366        self.browser.open(self.student_path)
    362367        self.assertRaises(
     
    364369        self.browser.open(self.student_path, 'admission_notification.pdf')
    365370        self.assertFalse('Not allowed' in self.browser.contents)
    366 
     371        # admission notification
    367372        IWorkflowState(self.student).setState('cleared')
    368373        self.browser.open(self.student_path)
     
    371376        self.assertEqual(self.browser.headers['Content-Type'],
    372377                         'application/pdf')
     378        path = os.path.join(samples_dir(), 'admission_notification.pdf')
     379        open(path, 'wb').write(self.browser.contents)
     380        print "Sample PDF admission_notification.pdf written to %s" % path
    373381        self.browser.open(self.student_path)
    374382        self.assertRaises(
     
    377385        self.assertFalse('Not allowed' in self.browser.contents)
    378386        return
     387
     388    def test_course_registration_pdf_slip(self):
     389        # Student cant login if their password is not set
     390        IWorkflowState(self.student).setState('school fee paid')
     391        self.browser.open(self.login_path)
     392        self.browser.getControl(name="form.login").value = self.student_id
     393        self.browser.getControl(name="form.password").value = 'spwd'
     394        self.browser.getControl("Login").click()
     395        self.browser.getLink("Study Course").click()
     396        self.browser.getLink("Add course list").click()
     397        self.assertMatches('...Add current level 100 (Year 1)...',
     398                           self.browser.contents)
     399        self.browser.getControl("Create course list now").click()
     400        # A level with one course ticket was created
     401        self.browser.getLink("100").click()
     402        self.browser.getLink("Download course registration slip").click()
     403        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     404        self.assertEqual(self.browser.headers['Content-Type'],
     405                         'application/pdf')
     406        path = os.path.join(samples_dir(), 'course_registration_slip.pdf')
     407        open(path, 'wb').write(self.browser.contents)
     408        print "Sample PDF course_registration_slip.pdf written to %s" % path
     409        return
Note: See TracChangeset for help on using the changeset viewer.