Ignore:
Timestamp:
6 Dec 2011, 12:27:21 (13 years ago)
Author:
Henrik Bettermann
Message:

Use the viewlet manager 'FileManager?' to render either images or placeholders of uploaded files.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/resources.py

    r7195 r7280  
    9999#:   require the JavaScript code to be rendered into the page::
    100100#:
    101 #:     from waeup.sirp.browser.resources import datepicker
     101#:     from waeup.sirp.browser.resources import warning
    102102#:     # ...
    103103#:     class MyPage(...):
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r7278 r7280  
    510510            '<img align="middle" height="125px" src="passport.jpg" />'
    511511            in self.browser.contents)
    512 
    513         # The clearance slip can't yet be opened
     512        # The clearance slip can't be opened because it requires a proper
     513        # passport jpg file.
     514        self.browser.open(self.student_path + '/clearance.pdf')
     515        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     516        self.assertTrue('Error in image file' in self.browser.contents)
     517        # We remove the passport file again
     518        self.browser.open(self.manage_student_path)
     519        self.browser.getControl('Delete').click()
    514520        self.browser.open(self.student_path + '/clearance.pdf')
    515521        self.assertEqual(self.browser.headers['Status'], '200 Ok')
  • main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py

    r7256 r7280  
    2828    Table, Spacer)
    2929from reportlab.platypus.tables import TableStyle
     30from zope.component import getUtility
    3031from zope.formlib.form import setUpEditWidgets
     32from waeup.sirp.interfaces import IExtFileStore
    3133from waeup.sirp.students.interfaces import IStudentsUtils
    3234
     
    6365    data = []
    6466    style = getSampleStyleSheet()
     67    img = getUtility(IExtFileStore).getFileByContext(
     68        studentview.context, attr='passport.jpg')
     69    #import pdb; pdb.set_trace()
     70    if img is None:
     71        from waeup.sirp.browser import DEFAULT_PASSPORT_IMAGE_PATH
     72        img = open(DEFAULT_PASSPORT_IMAGE_PATH, 'rb')
     73    doc_img = Image(img.name, width=4*cm, height=3*cm, kind='bound')
     74    data.append([doc_img])
     75    data.append([Spacer(1, 12)])
    6576    for widget in studentview.widgets:
    6677        if widget.name == 'form.adm_code':
     
    164175        #story.append(HRFlowable())
    165176        if student:
    166             story.append(Spacer(1, 18))
     177            story.append(Spacer(1, 12))
    167178            studenttable = render_student_data(student, studentview)
    168179            story.append(studenttable)
    169         story.append(Spacer(1, 18))
     180        story.append(Spacer(1, 12))
    170181        set_up_widgets(view)
    171182        data = []
     
    176187            f_text = Paragraph(f_text, style["Normal"])
    177188            data.append([f_label,f_text])
     189        # First, import browser components locally
     190        # to avoid circular import
     191        from waeup.sirp.students.viewlets import FileManager
     192        from waeup.sirp.browser import DEFAULT_IMAGE_PATH
     193        fm = FileManager(view.context, view.request, view)
     194        # Collect viewlets
     195        fm.update()
     196        # Insert list of scanned documents
     197        for viewlet in fm.viewlets:
     198            f_label = '<font size=12>%s</font>' % viewlet.label
     199            f_label = Paragraph(f_label, style["Normal"])
     200            if viewlet.template.__grok_name__ == 'imagedisplay':
     201                # In case we define FileDisplay viewlets with
     202                # an imagedisplay template in the customization package
     203                img = getUtility(IExtFileStore).getFileByContext(
     204                    view.context, attr=viewlet.download_name)
     205                if img is None:
     206                    img = open(DEFAULT_IMAGE_PATH, 'rb')
     207                doc_img = Image(img.name, width=2*cm, height=1*cm, kind='bound')
     208                data.append([f_label,doc_img])
     209            else:
     210                f_text = '<font size=12>%s</font>' % viewlet.title
     211                f_text = Paragraph(f_text, style["Normal"])
     212                data.append([f_label,f_text])
    178213        table = Table(data,style=SLIP_STYLE)
    179214        story.append(table)
    180         frame_body.addFromList(story,pdf)
    181 
     215        try:
     216            frame_body.addFromList(story,pdf)
     217        except IOError:
     218            view.flash('Error in image file.')
     219            return view.redirect(view.url(view.context))
    182220        story = []
    183221        frame_footer = Frame(1*cm,0,width-(2*cm),1*cm)
     
    186224        story.append(Paragraph(f_text, style["Normal"]))
    187225        frame_footer.addFromList(story,pdf)
    188 
    189226        view.response.setHeader(
    190227            'Content-Type', 'application/pdf')
  • main/waeup.sirp/trunk/src/waeup/sirp/students/viewlets.py

    r7243 r7280  
    2929    StudentClearanceDisplayFormPage, StudentClearanceManageFormPage,
    3030    write_log_message, StudentBaseManageFormPage, StudentBaseDisplayFormPage,
    31     StudentFilesUploadPage)
     31    StudentFilesUploadPage, ExportPDFClearanceSlipPage)
    3232from waeup.sirp.students.interfaces import IStudent, IStudentClearance
    3333
     
    377377    download_name = u'birth_certificate'
    378378
     379class BirthCertificateSlip(BirthCertificateDisplay):
     380    grok.view(ExportPDFClearanceSlipPage)
     381
    379382class BirthCertificateUpload(FileUpload):
    380383    """Birth Certificate upload viewlet.
     
    394397    title = u'Acceptance Letter Scan'
    395398    download_name = u'acceptance_letter'
     399
     400class AcceptanceLetterSlip(AcceptanceLetterDisplay):
     401    grok.view(ExportPDFClearanceSlipPage)
    396402
    397403class AcceptanceLetterUpload(FileUpload):
Note: See TracChangeset for help on using the changeset viewer.