Ignore:
Timestamp:
13 Jul 2021, 14:08:06 (3 years ago)
Author:
Henrik Bettermann
Message:

Enable applicants to upload also additional jpg files.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/applicants
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/applicant.py

    r16282 r16545  
    299299            if appl_file is None:
    300300                continue
     301            ext = os.path.splitext(appl_file.name)[1]
    301302            stud_file_id = IFileStoreNameChooser(student).chooseName(
    302                 attr=filename[1])
     303                attr=filename[1] + ext)
    303304            file_store.createFile(stud_file_id, appl_file)
    304305        return
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py

    r16539 r16545  
    4343    IApplicantRefereeReport
    4444    )
    45 from waeup.kofa.utils.helpers import html2dict
     45from waeup.kofa.utils.helpers import (html2dict,
     46    string_from_bytes, file_size, get_fileformat)
    4647from waeup.kofa.applicants.container import (
    4748    ApplicantsContainer, VirtualApplicantsExportJobContainer)
     
    996997        view.flash(_('Uploaded file is too big!'))
    997998        return False
    998     dummy, ext = os.path.splitext(upload.filename)
     999    upload.seek(0)  # file pointer moved when determining size
     1000    dummy,ext = os.path.splitext(upload.filename)
     1001    file_format = get_fileformat(None, upload.read(512))
     1002    upload.seek(0)  # same here
     1003    if file_format is None:
     1004        view.flash(_('Could not determine file type.'), type="danger")
     1005        return False
    9991006    ext.lower()
    1000     if ext != '.pdf':
    1001         view.flash(_('pdf file extension expected.'), type='danger')
     1007    if ext not in ('.pdf', '.jpg'):
     1008        view.flash(_('pdf or jpg file extension expected.'), type='danger')
    10021009        return False
    1003     upload.seek(0) # file pointer moved when determining size
     1010    download_name = attr + '.' + file_format
    10041011    store = getUtility(IExtFileStore)
    1005     file_id = IFileStoreNameChooser(context).chooseName(attr=attr)
     1012    file_id = IFileStoreNameChooser(context).chooseName(attr=download_name)
    10061013    store.createFile(file_id, upload)
    10071014    return True
     
    20742081
    20752082class AdditionalFile(grok.View):
    2076     """Renders additional pdf files for applicants.
     2083    """Renders additional files for applicants.
    20772084    This is a baseclass.
    20782085    """
     
    20822089
    20832090    def render(self):
    2084         pdf = getUtility(IExtFileStore).getFileByContext(
     2091        #image = getUtility(IExtFileStore).getFileByContext(
     2092        #    self.context, attr=self.download_name)
     2093        file = getUtility(IExtFileStore).getFileByContext(
    20852094            self.context, attr=self.__name__)
    2086         self.response.setHeader('Content-Type', 'application/pdf')
    2087         return pdf
     2095        dummy,ext = os.path.splitext(file.name)
     2096        if ext == '.jpg':
     2097            self.response.setHeader('Content-Type', 'image/jpeg')
     2098        elif ext == '.pdf':
     2099            self.response.setHeader('Content-Type', 'application/pdf')
     2100        return file
    20882101
    20892102class TestFile(AdditionalFile):
    2090     """Renders testfile.pdf.
    2091     """
    2092     grok.name('testfile.pdf')
     2103    """Renders testfile.
     2104    """
     2105    grok.name('testfile')
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser_templates/applicanteditpage.pt

    r16133 r16545  
    5454              <p tal:condition="python:view.file_exists(filename[1])">
    5555                <a tal:attributes="href python:filename[1]"i18n:translate="">
    56                   Download pdf file
     56                  Download file
    5757                </a>
    5858              </p>
     
    6767              </div>
    6868              <span i18n:translate="">
    69                 PDF files only. Max. file size:
     69                JPG or PDF files only. Max. file size:
    7070              </span>
    7171              <span tal:replace="view/max_file_upload_size">10 KB</span>
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_applicantcopier.py

    r16228 r16545  
    6767        dummy_file = StringIO('test file')
    6868        testfile_id = IFileStoreNameChooser(
    69             self.applicant).chooseName(attr='testfile.pdf')
     69            self.applicant).chooseName(attr='testfile.jpg')
    7070        test_file = storage.createFile(testfile_id, dummy_file)
    7171        # The stored file can be fetched
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r16526 r16545  
    13221322        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
    13231323        pseudo_pdf = StringIO(pdf_content)
    1324         ctrl = self.browser.getControl(name='testfile.pdf')
     1324        ctrl = self.browser.getControl(name='testfile')
    13251325        file_ctrl = ctrl.mech_control
    1326         file_ctrl.add_file(pseudo_pdf, filename='testfile.pdf')
     1326        file_ctrl.add_file(pseudo_pdf, filename='my_file.pdf')
    13271327        self.browser.getControl("Save").click() # submit form
    13281328        self.assertTrue('Uploaded file is too big!'
    13291329            in self.browser.contents)
    1330         pdf_content = 'A' * 1024 * 200  # A string of 300 KB size
    1331         pseudo_pdf = StringIO(pdf_content)
    1332         ctrl = self.browser.getControl(name='testfile.pdf')
     1330        #pdf_content = 'A' * 1024 * 200  # A string of 300 KB size
     1331        #pseudo_pdf = StringIO(pdf_content)
     1332        image = open(SAMPLE_IMAGE, 'rb')
     1333        ctrl = self.browser.getControl(name='testfile')
    13331334        file_ctrl = ctrl.mech_control
    1334         file_ctrl.add_file(pseudo_pdf, filename='testfile.pdf')
     1335        file_ctrl.add_file(image, filename='my_scan.jpg')
    13351336        self.browser.getControl("Save").click() # submit form
    13361337        # The file has been successfully uploaded
     
    13391340        storage = getUtility(IExtFileStore)
    13401341        file_id = IFileStoreNameChooser(self.applicant).chooseName(
    1341             attr='testfile.pdf')
     1342            attr='testfile.jpg')
    13421343        # The stored file can be fetched
    13431344        fd = storage.getFile(file_id)
    13441345        file_len = len(fd.read())
    1345         self.assertEqual(file_len, 204800)
     1346        self.assertEqual(file_len, 2787)
    13461347        # A file link is displayed on the edit view ...
    13471348        self.browser.open(self.edit_path)
    1348         self.assertTrue('<a href="testfile.pdf">' in self.browser.contents)
     1349        self.assertTrue('<a href="testfile">' in self.browser.contents)
    13491350        # ... and on the dislay view
    13501351        self.browser.open(self.view_path)
    1351         self.assertTrue('testfile.pdf">Test File</a>'
     1352        self.assertTrue('testfile">Test File</a>'
    13521353            in self.browser.contents)
    13531354        # Adding file is properly logged
     
    13571358        self.assertTrue(
    13581359            '%s - applicants.browser.ApplicantEditFormPage'
    1359             ' - %s - saved: testfile.pdf'
     1360            ' - %s - saved: testfile'
    13601361            % (self.applicant.applicant_id, self.applicant.applicant_id)
    13611362            in logcontent)
    1362         # When an applicant is removed, also the pdf files are gone.
     1363        # When an applicant is removed, also the files are gone.
    13631364        del self.applicantscontainer[self.applicant.application_number]
    13641365        fd = storage.getFile(file_id)
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/utils.py

    r16415 r16545  
    5454    #: A tuple of tuple of file names to be uploaded by applicants and copied
    5555    #: over to the students section.
    56     ADDITIONAL_FILES = (('Test File','testfile.pdf'),)
     56    ADDITIONAL_FILES = (('Test File','testfile'),)
    5757
    5858    def setPaymentDetails(self, container, payment, applicant):
Note: See TracChangeset for help on using the changeset viewer.