Ignore:
Timestamp:
23 Jan 2020, 14:35:44 (5 years ago)
Author:
Henrik Bettermann
Message:

Remove redundant components and make adjustments to base package.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/browser.py

    r15942 r15947  
    2626from waeup.kofa.utils.helpers import string_from_bytes, file_size, now
    2727from waeup.kofa.applicants.browser import (
    28     ApplicantRegistrationPage, ApplicantsContainerPage)
     28    ApplicantRegistrationPage, ApplicantsContainerPage, AdditionalFile)
    2929from waeup.kofa.applicants.interfaces import (
    3030    ISpecialApplicant, IApplicantsContainer)
     
    7878    'aggregate')
    7979
    80 def handle_file_upload(upload, context, view, attr=None):
    81     """Handle upload of applicant files.
    82 
    83     Returns `True` in case of success or `False`.
    84 
    85     Please note that file pointer passed in (`upload`) most probably
    86     points to end of file when leaving this function.
    87     """
    88     size = file_size(upload)
    89     if size > MAX_FILE_UPLOAD_SIZE:
    90         view.flash(_('Uploaded file is too big!'))
    91         return False
    92     dummy, ext = os.path.splitext(upload.filename)
    93     ext.lower()
    94     if ext != '.pdf':
    95         view.flash(_('pdf file extension expected.'))
    96         return False
    97     upload.seek(0) # file pointer moved when determining size
    98     store = getUtility(IExtFileStore)
    99     file_id = IFileStoreNameChooser(context).chooseName(attr=attr)
    100     store.createFile(file_id, upload)
    101     return True
    102 
    10380class CustomApplicantsContainerPage(ApplicantsContainerPage):
    10481    """The standard view for regular applicant containers.
     
    12198    """A display view for applicant data.
    12299    """
    123 
    124     @property
    125     def file_links(self):
    126         html = ''
    127         pdf = getUtility(IExtFileStore).getFileByContext(
    128             self.context, attr='res_stat.pdf')
    129         if pdf:
    130             html += '<a href="%s">Statement of Result</a>' % self.url(
    131                 self.context, 'res_stat.pdf')
    132         return html
    133100
    134101    @property
     
    172139        return form_fields
    173140
    174     def update(self):
    175         super(CustomApplicantManageFormPage, self).update()
    176         upload_res_stat = self.request.form.get('form.res_stat', None)
    177         if upload_res_stat:
    178             # We got a fresh res_stat upload
    179             success = handle_file_upload(
    180                 upload_res_stat, self.context, self, attr='res_stat.pdf')
    181             if success:
    182                 self.context.writeLogMessage(self, 'saved: res_stat')
    183             else:
    184                 self.upload_success = False
    185         self.max_file_upload_size = string_from_bytes(MAX_FILE_UPLOAD_SIZE)
    186         return
    187 
    188141class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
    189142    """An applicant-centered edit view for applicant data.
    190143    """
     144
     145    def display_fileupload(self, filename):
     146        if filename[1] == 'res_stat.pdf':
     147            if self.context.subtype != 'transfer':
     148                return False
     149        return True
    191150
    192151    def dataNotComplete(self, data):
     
    217176        return form_fields
    218177
    219     def update(self):
    220         if self.context.locked or (
    221             self.context.__parent__.expired and
    222             self.context.__parent__.strict_deadline):
    223             self.emit_lock_message()
    224             return
    225         super(CustomApplicantEditFormPage, self).update()
    226         upload_res_stat = self.request.form.get('form.res_stat', None)
    227         if upload_res_stat:
    228             # We got a fresh res_stat upload
    229             success = handle_file_upload(
    230                 upload_res_stat, self.context, self, attr='res_stat.pdf')
    231             if not success:
    232                 self.upload_success = False
    233         self.max_file_upload_size = string_from_bytes(MAX_FILE_UPLOAD_SIZE)
    234         return
    235 
    236178class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
    237179
     
    256198        return form_fields
    257199
    258 class ResultStatement(grok.View):
     200class ResultStatement(AdditionalFile):
    259201    """Renders the pdf form extension for applicants.
    260202    """
    261203    grok.name('res_stat.pdf')
    262     grok.context(ICustomApplicant)
    263     grok.require('waeup.viewApplication')
    264 
    265     def render(self):
    266         pdf = getUtility(IExtFileStore).getFileByContext(
    267             self.context, attr='res_stat.pdf')
    268         self.response.setHeader('Content-Type', 'application/pdf')
    269         return pdf
     204
     205class JAMBResult(AdditionalFile):
     206    """Renders the pdf form extension for applicants.
     207    """
     208    grok.name('jamb.pdf')
Note: See TracChangeset for help on using the changeset viewer.