Ignore:
Timestamp:
26 Jan 2013, 11:08:25 (12 years ago)
Author:
Henrik Bettermann
Message:

Customize course registration slip (work in progress).

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

Legend:

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

    r9905 r9914  
    1818import grok
    1919from zope.i18n import translate
     20from zope.component import getUtility
    2021from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
    21 from waeup.kofa.students.browser import CourseTicketAddFormPage
     22from waeup.kofa.interfaces import IKofaUtils
     23from waeup.kofa.students.interfaces import IStudentsUtils
     24from waeup.kofa.students.browser import (
     25    StudentBasePDFFormPage,
     26    CourseTicketAddFormPage,
     27    StudyLevelDisplayFormPage,
     28    ExportPDFCourseRegistrationSlipPage)
    2229from kofacustom.nigeria.students.browser import (
    2330    NigeriaOnlinePaymentDisplayFormPage,
    2431    NigeriaOnlinePaymentAddFormPage,
    2532    NigeriaExportPDFPaymentSlipPage)
    26 
    2733from waeup.aaue.students.interfaces import (
    28     ICustomStudentOnlinePayment)
     34    ICustomStudentOnlinePayment,
     35    ICustomStudentStudyLevel)
     36from waeup.aaue.interfaces import MessageFactory as _
    2937
    3038class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
     
    5361    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
    5462    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
     63
     64class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
     65    """ Page to display student study levels
     66    """
     67    grok.context(ICustomStudentStudyLevel)
     68    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit('total_credits')
     69    form_fields[
     70        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
     71
     72class CustomExportPDFCourseRegistrationSlipPage(
     73    ExportPDFCourseRegistrationSlipPage):
     74    """Deliver a PDF slip of the context.
     75    """
     76    grok.context(ICustomStudentStudyLevel)
     77    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
     78        'total_credits', 'level_session', 'level_verdict',
     79        'validated_by', 'validation_date', 'gpa')
     80
     81    @property
     82    def label(self):
     83        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     84        lang = self.request.cookies.get('kofa.language', portal_language)
     85        level_title = translate(self.context.level_title, 'waeup.kofa',
     86            target_language=lang)
     87        line0 = ''
     88        if self.context.student.current_mode.endswith('_pt'):
     89            line0 = 'DIRECTORATE OF PART-TIME DEGREE PROGRAMMES\n'
     90        line1 = translate(_('Course Registration Slip'),
     91            'waeup.kofa', target_language=portal_language) \
     92            + ' %s' % level_title
     93        line2 = translate(_('Session'),
     94            'waeup.kofa', target_language=portal_language) \
     95            + ' %s' % self.context.getSessionString
     96        return '%s%s\n%s' % (line0, line1, line2)
     97
     98    @property
     99    def title(self):
     100        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     101        return translate(_('Units Registered'), 'waeup.kofa',
     102            target_language=portal_language)
     103
     104    def _signatures(self):
     105        return (_('Student Signature'), _('Head of Department'))
     106
     107    def render(self):
     108        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     109        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
     110        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
     111        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
     112        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
     113        Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
     114        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
     115        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
     116        Signature = translate(_('Course Lecturer\'s Signature'), 'waeup.aaue',
     117            target_language=portal_language)
     118        studentview = StudentBasePDFFormPage(self.context.student,
     119            self.request, self.omit_fields)
     120        students_utils = getUtility(IStudentsUtils)
     121        tabledata_1 = sorted(
     122            [value for value in self.context.values() if value.semester == 1],
     123            key=lambda value: str(value.semester) + value.code)
     124        tabledata_2 = sorted(
     125            [value for value in self.context.values() if value.semester == 2],
     126            key=lambda value: str(value.semester) + value.code)
     127        tableheader = [(Code,'code', 2.0),
     128                         (Title,'title', 5),
     129                         (Dept,'dcode', 1.5), #(Faculty,'fcode', 1.5),
     130                         (Cred, 'credits', 1.5),
     131                         (Score, 'score', 1.4),
     132                         (Grade, 'grade', 1.4),
     133                         (Signature, 'dummy', 3),
     134                         ]
     135        if len(self.label.split('\n')) == 3:
     136            topMargin = 1.9
     137        elif len(self.label.split('\n')) == 2:
     138            topMargin = 1.7
     139        else:
     140            topMargin = 1.5
     141        return students_utils.renderPDF(
     142            self, 'course_registration_slip.pdf',
     143            self.context.student, studentview,
     144            tableheader_1=tableheader,
     145            tabledata_1=tabledata_1,
     146            tableheader_2=tableheader,
     147            tabledata_2=tabledata_2,
     148            signatures=self._signatures(),
     149            topMargin=topMargin
     150            )
  • main/waeup.aaue/trunk/src/waeup/aaue/students/interfaces.py

    r9905 r9914  
    6868    """
    6969
     70    total_credits_s1 = schema.Int(
     71        title = _(u'1st Semester Units'),
     72        required = False,
     73        readonly = True,
     74        )
     75
     76    total_credits_s2 = schema.Int(
     77        title = _(u'2nd Semester Units'),
     78        required = False,
     79        readonly = True,
     80        )
     81
     82    gpa = schema.Int(
     83        title = _(u'GPA'),
     84        required = False,
     85        readonly = True,
     86        )
     87
    7088class ICustomStudentOnlinePayment(ICustomOnlinePayment):
    7189    """A student payment via payment gateways.
  • main/waeup.aaue/trunk/src/waeup/aaue/students/studylevel.py

    r9905 r9914  
    3939    grok.provides(ICustomStudentStudyLevel)
    4040
     41    @property
     42    def total_credits_s1(self):
     43        total = 0
     44        for ticket in self.values():
     45            if ticket.semester == 1:
     46                total += ticket.credits
     47        return total
     48
     49    @property
     50    def total_credits_s2(self):
     51        total = 0
     52        for ticket in self.values():
     53            if ticket.semester == 2:
     54                total += ticket.credits
     55        return total
     56
    4157CustomStudentStudyLevel = attrs_to_fields(
    42     CustomStudentStudyLevel, omit=['total_credits', 'gpa'])
     58    CustomStudentStudyLevel, omit=[
     59    'total_credits', 'total_credits_s1', 'total_credits_s2', 'gpa'])
    4360
    4461class CustomStudentStudyLevelFactory(StudentStudyLevelFactory):
Note: See TracChangeset for help on using the changeset viewer.