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

Remove redundant components and make adjustments to base package.

Location:
main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants
Files:
2 deleted
4 edited

Legend:

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

    r15942 r15947  
    2727    ICustomApplicant, ICustomUGApplicantEdit, ICustomPGApplicantEdit, IPUTMEApplicantEdit)
    2828
    29 @grok.subscribe(ICustomApplicant, grok.IObjectRemovedEvent)
    30 def custom_handle_applicant_removed(applicant, event):
    31     """If an applicant is removed also pdf files of this applicant are removed.
    32     """
    33     file_store = getUtility(IExtFileStore)
    34     file_store.deleteFileByContext(applicant, attr='res_stat.pdf')
    35     return
    36 
    3729class CustomApplicant(NigeriaApplicant):
    3830
  • 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')
  • main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/tests/test_browser.py

    r15942 r15947  
    134134        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
    135135        pseudo_pdf = StringIO(pdf_content)
    136         ctrl = self.browser.getControl(name='form.res_stat')
     136        ctrl = self.browser.getControl(name='res_stat.pdf')
    137137        file_ctrl = ctrl.mech_control
    138138        file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
     
    167167        self.assertTrue(
    168168            'zope.mgr - kofacustom.iuokada.applicants.browser.CustomApplicantManageFormPage'
    169             ' - %s - saved: res_stat'
     169            ' - %s - saved: res_stat.pdf'
    170170            % (self.transapplicant.applicant_id)
    171171            in logcontent)
  • main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/utils.py

    r15942 r15947  
    3030    """
    3131
    32     #: A tuple of names of files to be copied over
    33     #: to students section.
    34     FILENAMES = ('res_stat.pdf',)
     32    ADDITIONAL_FILES = (('Statement of Result','res_stat.pdf'),
     33                 ('JAMB Result','jamb.pdf'))
    3534
    3635    APP_TYPES_DICT = {
Note: See TracChangeset for help on using the changeset viewer.