Ignore:
Timestamp:
12 Jan 2015, 09:24:58 (10 years ago)
Author:
Henrik Bettermann
Message:

Remove redundant code and set download_filename for pdf files.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/templates/filedisplay.pt

    r11254 r12447  
    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.kofa/trunk/src/waeup/kofa/browser/templates/fileupload.pt

    r11569 r12447  
    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.kofa/trunk/src/waeup/kofa/documents/fileviewlets.py

    r12438 r12447  
    4444    tab_redirect = '#tab2'
    4545
     46    @property
     47    def download_filename(self):
     48        return u"%s.pdf" % self.context.document_id
     49
    4650
    4751class PDFScanDisplay(FileDisplay):
     
    5660    download_name = u'sample.pdf'
    5761
     62    @property
     63    def download_filename(self):
     64        return u"%s.pdf" % self.context.document_id
     65
    5866
    5967class PDFScanImage(UtilityView, Image):
     
    6674    download_name = u'sample.pdf'
    6775
     76    @property
     77    def download_filename(self):
     78        return self.context.document_id
     79
    6880    def update(self):
    6981        if self.context.state != PUBLISHED:
  • main/waeup.kofa/trunk/src/waeup/kofa/documents/tests/test_browser.py

    r12441 r12447  
    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/sample.pdf">DOC1.pdf</a>'
    151151            in self.browser.contents)
    152152        # The file can be found in the file system
     
    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'
     
    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
  • main/waeup.kofa/trunk/src/waeup/kofa/students/fileviewlets.py

    r12438 r12447  
    120120    label = _(u'File')
    121121    title = _(u'Scan')
    122     download_name = u'filename.jpg'
     122
     123    @property
     124    def download_filename(self):
     125        return self.download_name
    123126
    124127    @property
     
    241244    """
    242245    grok.baseclass()
    243     grok.name('none.jpg')
    244246    grok.context(IStudent)
    245247    grok.require('waeup.viewStudent')
    246     download_name = u'none.jpg'
     248
     249    @property
     250    def download_filename(self):
     251        return self.download_name
    247252
    248253    def render(self):
     
    262267        elif ext == '.png':
    263268            self.response.setHeader('Content-Type', 'image/png')
     269        elif ext == '.tif':
     270            self.response.setHeader('Content-Type', 'image/tiff')
    264271        elif ext == '.pdf':
    265272            self.response.setHeader('Content-Type', 'application/pdf')
    266         elif ext == '.tif':
    267             self.response.setHeader('Content-Type', 'image/tiff')
     273            self.response.setHeader('Content-Disposition',
     274                'attachment; filename="%s.pdf' % self.download_filename)
    268275        return image
    269276
Note: See TracChangeset for help on using the changeset viewer.