Changeset 9191


Ignore:
Timestamp:
16 Sep 2012, 19:23:06 (12 years ago)
Author:
Henrik Bettermann
Message:

Export pdf admission letter.

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

Legend:

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

    r9189 r9191  
    360360        return
    361361
     362class ExportPDFAdmissionSlipPage(UtilityView, grok.View):
     363    """Deliver a PDF Admission slip.
     364    """
     365    grok.context(IStudent)
     366    grok.name('admission_slip.pdf')
     367    grok.require('waeup.viewStudent')
     368    prefix = 'form'
     369
     370    form_fields = grok.AutoFields(IStudentBase).select('student_id', 'reg_number')
     371
     372    @property
     373    def label(self):
     374        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     375        return translate(_('Admission Letter of'),
     376            'waeup.kofa', target_language=portal_language) \
     377            + ' %s' % self.context.display_fullname
     378
     379    def render(self):
     380        students_utils = getUtility(IStudentsUtils)
     381        return students_utils.renderPDFAdmissionLetter(self,
     382            self.context.student)
     383
    362384class StudentBaseManageFormPage(KofaEditFormPage):
    363385    """ View to manage student base data
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r9183 r9191  
    11921192        self.assertTrue(
    11931193            'You logged in.' in self.browser.contents)
    1194         # Student can upload a passport picture
     1194        # Admitted student can upload a passport picture
    11951195        self.browser.open(self.student_path + '/change_portrait')
    11961196        ctrl = self.browser.getControl(name='passportuploadedit')
     
    12031203            '<img align="middle" height="125px" src="passport.jpg" />'
    12041204            in self.browser.contents)
     1205        # Students can open admission letter
     1206        self.browser.getLink("Base Data").click()
     1207        self.browser.getLink("Download admission letter").click()
     1208        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     1209        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
    12051210        # Student can view the clearance data
     1211        self.browser.open(self.student_path)
    12061212        self.browser.getLink("Clearance Data").click()
    12071213        # Student can't open clearance edit form before starting clearance
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r9187 r9191  
    138138        f_label = formatted_label(size=12) % _('Study Course')
    139139        f_label = Paragraph(f_label, style["Normal"])
    140         f_text = formatted_text(studentview.context.certcode, size=12)
     140        f_text = formatted_text(
     141            studentview.context['studycourse'].certificate.longtitle(), size=12)
     142        f_text = Paragraph(f_text, style["Normal"])
     143        data_right.append([f_label,f_text])
     144
     145        f_label = formatted_label(size=12) % _('Department')
     146        f_label = Paragraph(f_label, style["Normal"])
     147        f_text = formatted_text(
     148            studentview.context[
     149            'studycourse'].certificate.__parent__.__parent__.longtitle(),
     150            size=12)
     151        f_text = Paragraph(f_text, style["Normal"])
     152        data_right.append([f_label,f_text])
     153
     154        f_label = formatted_label(size=12) % _('Faculty')
     155        f_label = Paragraph(f_label, style["Normal"])
     156        f_text = formatted_text(
     157            studentview.context[
     158            'studycourse'].certificate.__parent__.__parent__.__parent__.longtitle(),
     159            size=12)
    141160        f_text = Paragraph(f_text, style["Normal"])
    142161        data_right.append([f_label,f_text])
     
    401420        return available_beds[0]
    402421
     422    def renderPDFAdmissionLetter(self, view, student=None):
     423        """Render pdf admission letter.
     424        """
     425        # XXX: we have to fix the import problems here.
     426        from waeup.kofa.browser.interfaces import IPDFCreator
     427        from waeup.kofa.browser.pdf import format_html, NOTE_STYLE
     428        if student is None:
     429            return
     430        style = getSampleStyleSheet()
     431        creator = getUtility(IPDFCreator)
     432        data = []
     433        doc_title = view.label
     434        author = '%s (%s)' % (view.request.principal.title,
     435                              view.request.principal.id)
     436        footer_text = view.label
     437        if getattr(student, 'student_id', None) is not None:
     438            footer_text = "%s - %s - " % (student.student_id, footer_text)
     439
     440        # Admission text
     441        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     442        inst_name = grok.getSite()['configuration'].name
     443        text = trans(_(
     444            'This is to inform you that you have been provisionally'
     445            ' admitted into ${a} as follows:', mapping = {'a': inst_name}),
     446            portal_language)
     447        html = format_html(text)
     448        data.append(Paragraph(html, NOTE_STYLE))
     449        data.append(Spacer(1, 20))
     450
     451        # Student data
     452        data.append(render_student_data(view))
     453
     454        # Insert history
     455        data.append(Spacer(1, 20))
     456        datelist = student.history.messages[0].split()[0].split('-')
     457        creation_date = u'%s/%s/%s' % (datelist[2], datelist[1], datelist[0])
     458        text = trans(_(
     459            'Your Kofa student record was created on ${a}.',
     460            mapping = {'a': creation_date}),
     461            portal_language)
     462        html = format_html(text)
     463        data.append(Paragraph(html, NOTE_STYLE))
     464
     465        # Create pdf stream
     466        view.response.setHeader(
     467            'Content-Type', 'application/pdf')
     468        pdf_stream = creator.create_pdf(
     469            data, None, doc_title, author=author, footer=footer_text,
     470            note=None)
     471        return pdf_stream
     472
    403473    def renderPDF(self, view, filename='slip.pdf', student=None,
    404474                  studentview=None, tableheader=None, tabledata=None,
     
    431501
    432502        # Insert widgets
    433         data.append(Paragraph(view.title, style["Heading3"]))
    434         portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    435         separators = getattr(self, 'SEPARATORS_DICT', {})
    436         table = creator.getWidgetsTable(
    437             view.form_fields, view.context, None, lang=portal_language,
    438             separators=separators)
    439         data.append(table)
     503        if view.form_fields:
     504            data.append(Paragraph(view.title, style["Heading3"]))
     505            portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     506            separators = getattr(self, 'SEPARATORS_DICT', {})
     507            table = creator.getWidgetsTable(
     508                view.form_fields, view.context, None, lang=portal_language,
     509                separators=separators)
     510            data.append(table)
    440511
    441512        # Insert scanned docs
  • main/waeup.kofa/trunk/src/waeup/kofa/students/viewlets.py

    r9180 r9191  
    150150
    151151class ContactActionButton(ManageActionButton):
    152     grok.order(4)
     152    grok.order(5)
    153153    grok.context(IStudent)
    154154    grok.view(StudentBaseDisplayFormPage)
     
    166166    target = 'manage_base'
    167167
     168class AdmissionSlipActionButton(ManageActionButton):
     169    grok.order(4)
     170    grok.context(IStudent)
     171    grok.view(StudentBaseDisplayFormPage)
     172    grok.require('waeup.viewStudent')
     173    icon = 'actionicon_pdf.png'
     174    text = _('Download admission letter')
     175    target = 'admission_slip.pdf'
     176
    168177class StudentTransfernButton(ManageActionButton):
    169     grok.order(5)
     178    grok.order(6)
    170179    grok.context(IStudent)
    171180    grok.view(StudentBaseDisplayFormPage)
     
    176185
    177186class StudentDeactivateActionButton(ManageActionButton):
    178     grok.order(6)
     187    grok.order(7)
    179188    grok.context(IStudent)
    180189    grok.view(StudentBaseDisplayFormPage)
     
    196205
    197206class StudentActivateActionButton(ManageActionButton):
    198     grok.order(6)
     207    grok.order(7)
    199208    grok.context(IStudent)
    200209    grok.view(StudentBaseDisplayFormPage)
Note: See TracChangeset for help on using the changeset viewer.