Ignore:
Timestamp:
26 Nov 2014, 13:03:56 (10 years ago)
Author:
Henrik Bettermann
Message:

Add PDFDocumentSlipPage and related components.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/customers
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py

    r12059 r12062  
    5050from waeup.ikoba.customers.interfaces import (
    5151    ICustomer, ICustomersContainer, ICustomerRequestPW, ICustomersUtils,
    52     ICustomerDocument, ICustomerDocumentsContainer, ICustomerCreate
     52    ICustomerDocument, ICustomerDocumentsContainer, ICustomerCreate,
     53    ICustomerPDFDocument
    5354    )
    5455from waeup.ikoba.customers.catalog import search
     
    932933        return
    933934
    934 class ExportPDFDocumentsOverviewPage(UtilityView, grok.View):
     935class PDFDocumentsOverviewPage(UtilityView, grok.View):
    935936    """Deliver an overview slip.
    936937    """
     
    988989            tabledata=tabledata,
    989990            omit_fields=self.omit_fields)
     991
     992
     993class PDFDocumentSlipPage(UtilityView, grok.View):
     994    """Deliver pdf file including metadata.
     995    """
     996    grok.context(ICustomerDocument)
     997    grok.name('document_slip.pdf')
     998    grok.require('waeup.viewCustomer')
     999    prefix = 'form'
     1000
     1001    omit_fields = ('suspended', 'sex',
     1002                   'suspended_comment',)
     1003
     1004    #form_fields = grok.AutoFields(ICustomerPDFDocument).omit(
     1005    #    'last_transition_date')
     1006    form_fields =()
     1007
     1008    @property
     1009    def label(self):
     1010        portal_language = getUtility(IIkobaUtils).PORTAL_LANGUAGE
     1011        return '%s of %s\nTitle: %s' % (
     1012            self.context.translated_class_name,
     1013            self.context.customer.display_fullname,
     1014            self.context.title)
     1015
     1016    def render(self):
     1017        portal_language = getUtility(IIkobaUtils).PORTAL_LANGUAGE
     1018        customerview = CustomerBasePDFFormPage(self.context.customer,
     1019            self.request, self.omit_fields)
     1020        customers_utils = getUtility(ICustomersUtils)
     1021        return customers_utils.renderPDF(
     1022            self, 'document_slip.pdf',
     1023            self.context.customer, customerview,
     1024            omit_fields=self.omit_fields)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/fileviewlets.py

    r12058 r12062  
    4141    CustomerFilesUploadPage,
    4242    DocumentDisplayFormPage, DocumentManageFormPage, DocumentEditFormPage,
    43     ExportPDFDocumentsOverviewPage)
     43    PDFDocumentSlipPage,)
    4444
    4545grok.context(IIkobaObject)  # Make IIkobaObject the default context
     
    262262# File viewlets for customer documents
    263263
    264 class SampleManageUpload(FileUpload):
     264class SampleScanManageUpload(FileUpload):
    265265    """Scan upload viewlet for officers.
    266266    """
     
    276276
    277277
    278 class SampleEditUpload(SampleManageUpload):
     278class SampleScanEditUpload(SampleScanManageUpload):
    279279    """Scan upload viewlet for customer.
    280280    """
     
    283283
    284284
    285 class SampleDisplay(FileDisplay):
     285class SampleScanDisplay(FileDisplay):
    286286    """Scan display viewlet.
    287287    """
     
    303303    download_name = u'sample'
    304304
    305 
    306 class PDFManageUpload(FileUpload):
     305class SampleScanPDFSlip(SampleScanDisplay):
     306    grok.view(PDFDocumentSlipPage)
     307
     308
     309class PDFScanManageUpload(FileUpload):
    307310    """Scan upload viewlet for officers.
    308311    """
     
    317320
    318321
    319 class PDFEditUpload(PDFManageUpload):
     322class PDFScanEditUpload(PDFScanManageUpload):
    320323    """Scan upload viewlet for customer.
    321324    """
     
    324327
    325328
    326 class PDFDisplay(FileDisplay):
     329class PDFScanDisplay(FileDisplay):
    327330    """Scan display viewlet.
    328331    """
     
    343346    grok.require('waeup.viewCustomer')
    344347    download_name = u'sample.pdf'
     348
     349class PDFScanSlip(PDFScanDisplay):
     350    grok.view(PDFDocumentSlipPage)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12059 r12062  
    893893        # Costumer can upload a document.
    894894        self.browser.getLink("Edit").click()
    895         ctrl = self.browser.getControl(name='sampleeditupload')
     895        ctrl = self.browser.getControl(name='samplescaneditupload')
    896896        file_obj = open(SAMPLE_IMAGE, 'rb')
    897897        file_ctrl = ctrl.mech_control
    898898        file_ctrl.add_file(file_obj, filename='my_document.jpg')
    899899        self.browser.getControl(
    900             name='upload_sampleeditupload').click()
     900            name='upload_samplescaneditupload').click()
    901901        self.assertTrue(
    902902            'href="http://localhost/app/customers/K1000000/documents/d102/sample"'
     
    919919        # Create a pseudo image file and select it to be uploaded
    920920        image = open(SAMPLE_IMAGE, 'rb')
    921         ctrl = self.browser.getControl(name='samplemanageupload')
     921        ctrl = self.browser.getControl(name='samplescanmanageupload')
    922922        file_ctrl = ctrl.mech_control
    923923        file_ctrl.add_file(image, filename='my_sample_scan.jpg')
     
    929929        # ... but the correct upload submit button does
    930930        image = open(SAMPLE_IMAGE)
    931         ctrl = self.browser.getControl(name='samplemanageupload')
     931        ctrl = self.browser.getControl(name='samplescanmanageupload')
    932932        file_ctrl = ctrl.mech_control
    933933        file_ctrl.add_file(image, filename='my_sample_scan.jpg')
    934934        self.browser.getControl(
    935             name='upload_samplemanageupload').click()
     935            name='upload_samplescanmanageupload').click()
    936936        self.assertTrue(
    937937            'href="http://localhost/app/customers/K1000000/documents/d101/sample"'
     
    945945        self.browser.open(self.customer_path + '/documents/d101/manage')
    946946        self.assertFalse(
    947             'upload_samplemanageupload' in self.browser.contents)
     947            'upload_samplescanmanageupload' in self.browser.contents)
    948948        # File must be deleted first
    949         self.browser.getControl(name='delete_samplemanageupload').click()
     949        self.browser.getControl(name='delete_samplescanmanageupload').click()
    950950        self.assertTrue(
    951951            'sample deleted' in self.browser.contents)
    952952        # Uploading a file which is bigger than 150k will raise an error
    953953        big_image = StringIO(open(SAMPLE_IMAGE, 'rb').read() * 75)
    954         ctrl = self.browser.getControl(name='samplemanageupload')
     954        ctrl = self.browser.getControl(name='samplescanmanageupload')
    955955        file_ctrl = ctrl.mech_control
    956956        file_ctrl.add_file(big_image, filename='my_sample_scan.jpg')
    957957        self.browser.getControl(
    958             name='upload_samplemanageupload').click()
     958            name='upload_samplescanmanageupload').click()
    959959        self.assertTrue(
    960960            'Uploaded file is too big' in self.browser.contents)
    961961        # we do not rely on filename extensions given by uploaders
    962962        image = open(SAMPLE_IMAGE, 'rb') # a jpg-file
    963         ctrl = self.browser.getControl(name='samplemanageupload')
     963        ctrl = self.browser.getControl(name='samplescanmanageupload')
    964964        file_ctrl = ctrl.mech_control
    965965        # tell uploaded file is bmp
    966966        file_ctrl.add_file(image, filename='my_sample_scan.bmp')
    967967        self.browser.getControl(
    968             name='upload_samplemanageupload').click()
     968            name='upload_samplescanmanageupload').click()
    969969        self.assertTrue(
    970970            # jpg file was recognized
    971971            'File sample.jpg uploaded.' in self.browser.contents)
    972972        # Delete file again
    973         self.browser.getControl(name='delete_samplemanageupload').click()
     973        self.browser.getControl(name='delete_samplescanmanageupload').click()
    974974        self.assertTrue(
    975975            'sample deleted' in self.browser.contents)
    976976        # File names must meet several conditions
    977977        bmp_image = open(SAMPLE_IMAGE_BMP, 'rb')
    978         ctrl = self.browser.getControl(name='samplemanageupload')
     978        ctrl = self.browser.getControl(name='samplescanmanageupload')
    979979        file_ctrl = ctrl.mech_control
    980980        file_ctrl.add_file(bmp_image, filename='my_sample_scan.bmp')
    981981        self.browser.getControl(
    982             name='upload_samplemanageupload').click()
     982            name='upload_samplescanmanageupload').click()
    983983        self.assertTrue('Only the following extensions are allowed'
    984984            in self.browser.contents)
     
    995995        # Create a pseudo image file and select it to be uploaded
    996996        image = open(SAMPLE_IMAGE, 'rb')
    997         ctrl = self.browser.getControl(name='pdfmanageupload')
     997        ctrl = self.browser.getControl(name='pdfscanmanageupload')
    998998        file_ctrl = ctrl.mech_control
    999999        file_ctrl.add_file(image, filename='my_sample_scan.jpg')
    10001000        self.browser.getControl(
    1001             name='upload_pdfmanageupload').click()
     1001            name='upload_pdfscanmanageupload').click()
    10021002        self.assertTrue(
    10031003            'pdf file extension expected' in self.browser.contents)
    1004         ctrl = self.browser.getControl(name='pdfmanageupload')
     1004        ctrl = self.browser.getControl(name='pdfscanmanageupload')
    10051005        file_ctrl = ctrl.mech_control
    10061006        file_ctrl.add_file(image, filename='my_sample_scan.pdf')
    10071007        self.browser.getControl(
    1008             name='upload_pdfmanageupload').click()
     1008            name='upload_pdfscanmanageupload').click()
    10091009        self.assertTrue(
    10101010            'Could not determine file type' in self.browser.contents)
    10111011        pdf = open(SAMPLE_PDF, 'rb')
    1012         ctrl = self.browser.getControl(name='pdfmanageupload')
     1012        ctrl = self.browser.getControl(name='pdfscanmanageupload')
    10131013        file_ctrl = ctrl.mech_control
    10141014        file_ctrl.add_file(pdf, filename='my_sample_scan.pdf')
    10151015        self.browser.getControl(
    1016             name='upload_pdfmanageupload').click()
     1016            name='upload_pdfscanmanageupload').click()
    10171017        self.assertTrue(
    10181018            'href="http://localhost/app/customers/K1000000/documents/d102/sample.pdf">PDF File</a>'
     
    10251025    def test_view_slips(self):
    10261026        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    1027         # Officers can open the pdf transcript
     1027        # Officers can open the document overview
    10281028        self.browser.open(self.customer_path + '/documents')
    10291029        self.browser.getLink("Download documents overview").click()
     
    10331033        open(path, 'wb').write(self.browser.contents)
    10341034        print "Sample PDF overview_slip.pdf written to %s" % path
     1035        # Officers can open document slips
     1036        self.browser.open(self.customer_path + '/documents/d101')
     1037        self.browser.getLink("Download document slip").click()
     1038        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     1039        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
     1040        path = os.path.join(samples_dir(), 'document_slip.pdf')
     1041        open(path, 'wb').write(self.browser.contents)
     1042        print "Sample document_slip.pdf written to %s" % path
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/utils.py

    r12057 r12062  
    232232    fm.update()
    233233    if fm.viewlets:
    234         sc_translation = trans(_('Scanned Documents'), lang)
     234        sc_translation = trans(_('Connected Files'), lang)
    235235        data.append(Paragraph(sc_translation, HEADING_STYLE))
    236236        # Insert list of scanned documents
     
    350350        # Insert history
    351351        if show_history:
    352             hist_translation = trans(_('Workflow History'), portal_language)
    353             data.append(Paragraph(hist_translation, HEADING_STYLE))
    354             data.extend(creator.fromStringList(customer.history.messages))
     352            if getattr(view.context, 'history', None):
     353                hist_translation = trans(_('Document Workflow History'), portal_language)
     354                data.append(Paragraph(hist_translation, HEADING_STYLE))
     355                data.extend(creator.fromStringList(view.context.history.messages))
     356            else:
     357                hist_translation = trans(_('Customer Workflow History'), portal_language)
     358                data.append(Paragraph(hist_translation, HEADING_STYLE))
     359                data.extend(creator.fromStringList(customer.history.messages))
    355360
    356361        # Insert content tables (optionally on second page)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/viewlets.py

    r12059 r12062  
    298298
    299299
    300 class PDFSlipActionButton(ManageActionButton):
     300class PDFOverviewActionButton(ManageActionButton):
    301301    grok.order(2)
    302302    grok.context(ICustomerDocumentsContainer)
     
    350350    target = 'index'
    351351    icon = 'actionicon_view.png'
     352
     353class PDFSlipActionButton(ManageActionButton):
     354    grok.order(3)
     355    grok.context(ICustomerDocument)
     356    grok.view(DocumentDisplayFormPage)
     357    grok.require('waeup.viewCustomer')
     358    icon = 'actionicon_pdf.png'
     359    text = _('Download document slip')
     360    target = 'document_slip.pdf'
Note: See TracChangeset for help on using the changeset viewer.