Ignore:
Timestamp:
11 Jan 2015, 22:43:35 (10 years ago)
Author:
Henrik Bettermann
Message:

We need to provide unique filenames. Let's use the document id for the filename and not the download_name of the respective viewlet.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba
Files:
8 edited

Legend:

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

    r12386 r12444  
    109109    label = _(u'File')
    110110    title = _(u'Scan')
    111     download_name = u'filename.jpg'
     111    download_name = None
     112
     113    @property
     114    def download_filename(self):
     115        return u"%s.pdf" % self.context.document_id[:9]
    112116
    113117    @property
     
    131135    upload_button =_('Upload selected file')
    132136    delete_button = _('Delete')
     137
     138    @property
     139    def download_filename(self):
     140        return u"%s.pdf" % self.context.document_id[:9]
    133141
    134142    @property
     
    175183    """
    176184    grok.baseclass()
    177     grok.name('none.jpg')
    178     download_name = u'none.jpg'
     185    download_name = None
     186
     187    @property
     188    def download_filename(self):
     189        return u"%s.pdf" % self.context.document_id[:9]
    179190
    180191    def render(self):
     
    198209        elif ext == '.tif':
    199210            self.response.setHeader('Content-Type', 'image/tiff')
     211        if self.download_filename:
     212            self.response.setHeader('Content-Disposition',
     213                'attachment; filename="%s' % self.download_filename)
    200214        return image
  • main/waeup.ikoba/trunk/src/waeup/ikoba/browser/templates/filedisplay.pt

    r12242 r12444  
    55  <td>
    66    <a tal:attributes="href python: view.url(context, viewlet.download_name)"
    7        tal:content="viewlet/download_name"
     7       tal:content="viewlet/download_filename"
    88       target="image">
    99      LINK
  • main/waeup.ikoba/trunk/src/waeup/ikoba/browser/templates/fileupload.pt

    r11949 r12444  
    77    <tal:file tal:condition="viewlet/file_exists">
    88      <a tal:attributes="href python: view.url(context, viewlet.download_name)"
    9          tal:content="viewlet/title"
     9         tal:content="viewlet/download_filename"
    1010         target="image">
    1111        LINK
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/fileviewlets.py

    r12408 r12444  
    9797class SampleScanEditUpload(SampleScanManageUpload):
    9898    """Scan upload viewlet for customer.
     99
     100    If a user has both permissions, waeup.manageCustomer and
     101    waeup.handleCustomer, the upload viewlet appears twice.
    99102    """
    100103    grok.view(DocumentEditFormPage)
     
    121124    grok.require('waeup.viewCustomer')
    122125    download_name = u'sample'
     126
    123127
    124128class SampleScanPDFSlip(SampleScanDisplay):
     
    166170    download_name = u'sample.pdf'
    167171
     172
    168173class PDFScanSlip(PDFScanDisplay):
    169174    grok.view(PDFDocumentSlipPage)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12388 r12444  
    11041104            name='upload_pdfscanmanageupload').click()
    11051105        self.assertTrue(
    1106             'href="http://localhost/app/customers/K1000000/documents/%s/sample.pdf">PDF File</a>'
    1107             % docid in self.browser.contents)
     1106            'href="http://localhost/app/customers/K1000000/documents/%s/sample.pdf">%s.pdf</a>'
     1107            % (docid, docid[:9]) in self.browser.contents)
    11081108        # Browsing the link shows a real pdf
    11091109        self.browser.open('sample.pdf')
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/document.py

    r12442 r12444  
    146146    form_fields_interface = IPDFDocument
    147147
    148     filenames = ('scan.pdf',)
     148    filenames = ('file.pdf',)
    149149
    150150PDFDocument = attrs_to_fields(PDFDocument)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/fileviewlets.py

    r12243 r12444  
    4040    title = _(u'PDF File')
    4141    mus = 1024 * 200
    42     download_name = u'sample.pdf'
     42    download_name = u'file.pdf'
    4343    tab_redirect = '#tab2'
    4444
     
    5353    label = _(u'PDF Scan')
    5454    title = _(u'PDF Scan')
    55     download_name = u'sample.pdf'
     55    download_name = u'file.pdf'
    5656
    5757
     
    5959    """Scan document.
    6060    """
    61     ##: Needs to be protected if not published
    62     grok.name('sample.pdf')
     61    grok.name('file.pdf')
    6362    grok.context(PDFDocument)
    6463    grok.require('waeup.Public')
    65     download_name = u'sample.pdf'
     64    download_name = u'file.pdf'
    6665
    6766    def update(self):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/tests/test_browser.py

    r12442 r12444  
    148148            name='upload_pdfscanmanageupload').click()
    149149        self.assertTrue(
    150             'href="http://localhost/app/documents/DOC1/sample.pdf">PDF File</a>'
     150            'href="http://localhost/app/documents/DOC1/file.pdf">DOC1.pdf</a>'
    151151            in self.browser.contents)
    152152        # The file can be found in the file system
    153153        file = getUtility(IExtFileStore).getFileByContext(
    154             document, attr='sample.pdf')
     154            document, attr='file.pdf')
    155155        file_content = file.read()
    156156        pdf.seek(0)
     
    159159        # Browsing the link shows a real pdf only if the document
    160160        # has been published
    161         self.browser.getLink("PDF File").click()
     161        self.browser.getLink("DOC1.pdf").click()
    162162        self.assertTrue(
    163163            'The document requested has not yet been published'
    164164            in self.browser.contents)
    165165        IWorkflowState(document).setState(PUBLISHED)
    166         self.browser.open(self.container_path + '/DOC1/sample.pdf')
     166        self.browser.open(self.container_path + '/DOC1/file.pdf')
    167167        self.assertEqual(
    168168            self.browser.headers['content-type'], 'application/pdf')
     169        # The name of the downloaded file will be different
     170        self.assertEqual(
     171            self.browser.headers['Content-Disposition'],
     172            'attachment; filename="DOC1.pdf')
    169173
    170174        # Transitions can be performed
     
    186190        # File has been removed too
    187191        file = getUtility(IExtFileStore).getFileByContext(
    188             document, attr='sample.pdf')
     192            document, attr='file.pdf')
    189193        self.assertTrue(file is None)
    190194
     
    204208            % document.document_id in logcontent)
    205209        self.assertTrue(
    206             'INFO - zope.mgr - documents.browser.DocumentManageFormPage - %s - uploaded: sample.pdf (my_sample_scan.pdf)'
     210            'INFO - zope.mgr - documents.browser.DocumentManageFormPage - %s - uploaded: file.pdf (my_sample_scan.pdf)'
    207211            % document.document_id in logcontent)
    208212        self.assertTrue(
Note: See TracChangeset for help on using the changeset viewer.