Changeset 10105 for main/waeup.futminna


Ignore:
Timestamp:
29 Apr 2013, 08:18:41 (12 years ago)
Author:
Henrik Bettermann
Message:

Make provision for uploading the referee's form. Rename form extension.

Location:
main/waeup.futminna/trunk/src/waeup/futminna/applicants
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.futminna/trunk/src/waeup/futminna/applicants/browser.py

    r10096 r10105  
    8282        html = ''
    8383        pdf = getUtility(IExtFileStore).getFileByContext(
    84             self.context, attr='formextension.pdf')
     84            self.context, attr='extraform.pdf')
    8585        if pdf:
    86             html += '<a href="formextension.pdf">Offline Form Extension</a>'
     86            html += '<a href="extraform.pdf">Extra Applicant Information Form</a>, '
     87        pdf = getUtility(IExtFileStore).getFileByContext(
     88            self.context, attr='refereeform.pdf')
     89        if pdf:
     90            html += '<a href="refereeform.pdf">Referee\'s Form</a>'
    8791        return html
    8892
     
    113117    def update(self):
    114118        super(CustomApplicantDisplayFormPage, self).update()
    115         self.formextension_url = self.url(self.context, 'formextension.pdf')
     119        self.extraform_url = self.url(self.context, 'extraform.pdf')
     120        self.referreeform_url = self.url(self.context, 'refereeform.pdf')
    116121        return
    117122
     
    161166    def update(self):
    162167        super(CustomApplicantManageFormPage, self).update()
    163         upload_formextension = self.request.form.get('form.formextension', None)
    164         if upload_formextension:
    165             # We got a fresh formextension upload
    166             self.upload_success = handle_file_upload(
    167                 upload_formextension, self.context, self, attr='formextension.pdf')
    168             if self.upload_success:
    169                 self.context.writeLogMessage(self, 'saved: formextension')
     168        upload_extraform = self.request.form.get('form.extraform', None)
     169        if upload_extraform:
     170            # We got a fresh extraform upload
     171            success = handle_file_upload(
     172                upload_extraform, self.context, self, attr='extraform.pdf')
     173            if success:
     174                self.context.writeLogMessage(self, 'saved: extraform')
     175            else:
     176                self.upload_success = False
     177        upload_refereeform = self.request.form.get('form.refereeform', None)
     178        if upload_refereeform:
     179            # We got a fresh refereeform upload
     180            success = handle_file_upload(
     181                upload_refereeform, self.context, self, attr='refereeform.pdf')
     182            if success:
     183                self.context.writeLogMessage(self, 'saved: refereeform')
     184            else:
     185                self.upload_success = False
    170186        self.max_file_upload_size = string_from_bytes(MAX_FILE_UPLOAD_SIZE)
    171187        return
     
    195211        if not store.getFileByContext(self.context, attr=u'passport.jpg'):
    196212            return _('No passport picture uploaded.')
    197         if not store.getFileByContext(self.context, attr=u'formextension.pdf'):
    198             return _('No form extension pdf file uploaded.')
     213        if not store.getFileByContext(self.context, attr=u'extraform.pdf'):
     214            return _('No extra information form pdf file uploaded.')
     215        if not store.getFileByContext(self.context, attr=u'refereeform.pdf'):
     216            return _('No referee form pdf file uploaded.')
    199217        if not self.request.form.get('confirm_passport', False):
    200218            return _('Passport picture confirmation box not ticked.')
     
    208226            return
    209227        super(CustomApplicantEditFormPage, self).update()
    210         upload_formextension = self.request.form.get('form.formextension', None)
    211         if upload_formextension:
    212             # We got a fresh formextension upload
    213             self.upload_success = handle_file_upload(
    214                 upload_formextension, self.context, self, attr='formextension.pdf')
     228        upload_extraform = self.request.form.get('form.extraform', None)
     229        if upload_extraform:
     230            # We got a fresh extraform upload
     231            success = handle_file_upload(
     232                upload_extraform, self.context, self, attr='extraform.pdf')
     233            if not success:
     234                self.upload_success = False
     235        upload_refereeform = self.request.form.get('form.refereeform', None)
     236        if upload_refereeform:
     237            # We got a fresh refereeform upload
     238            success = handle_file_upload(
     239                upload_refereeform, self.context, self, attr='refereeform.pdf')
     240            if not success:
     241                self.upload_success = False
    215242        self.max_file_upload_size = string_from_bytes(MAX_FILE_UPLOAD_SIZE)
    216243        return
    217244
    218 class FormExtension(grok.View):
     245class ExtraForm(grok.View):
    219246    """Renders the pdf form extension for applicants.
    220247    """
    221     grok.name('formextension.pdf')
     248    grok.name('extraform.pdf')
    222249    grok.context(ICustomApplicant)
    223250    grok.require('waeup.viewApplication')
     
    225252    def render(self):
    226253        pdf = getUtility(IExtFileStore).getFileByContext(
    227             self.context, attr='formextension.pdf')
     254            self.context, attr='extraform.pdf')
    228255        self.response.setHeader('Content-Type', 'application/pdf')
    229256        return pdf
     257
     258class RefereeForm(grok.View):
     259    """Renders the pdf referee's form for applicants.
     260    """
     261    grok.name('refereeform.pdf')
     262    grok.context(ICustomApplicant)
     263    grok.require('waeup.viewApplication')
     264
     265    def render(self):
     266        pdf = getUtility(IExtFileStore).getFileByContext(
     267            self.context, attr='refereeform.pdf')
     268        self.response.setHeader('Content-Type', 'application/pdf')
     269        return pdf
  • main/waeup.futminna/trunk/src/waeup/futminna/applicants/browser_templates/applicanteditpage.pt

    r10096 r10105  
    1818      Download, fill, scan and re-upload the following forms:
    1919    </span>
    20     <a href="https://futminna.waeup.org/downloads/ApplicationFormExtension.pdf"
     20        <a href="https://futminna.waeup.org/downloads/ExtraApplicantInformationForm.pdf"
    2121        i18n:translate="">
    22       Offline Form Extension
     22      Extra Applicant Information Form</a>,
     23    <a href="https://futminna.waeup.org/downloads/RefereeForm.pdf"
     24        i18n:translate="">
     25      Referee's Form
    2326    </a><br /><br />
    2427  </div>
     
    4851      <tr>
    4952        <td class="fieldname" i18n:translate="">
    50           Offline Form Extension:
     53          Extra Applicant Information Form:
    5154        </td>
    5255        <td>
    53           <p tal:condition="python: view.file_exists('formextension.pdf')">
    54             <a href="formextension.pdf"
     56          <p tal:condition="python: view.file_exists('extraform.pdf')">
     57            <a href="extraform.pdf"
    5558               i18n:translate="">
    5659              Download pdf file
    5760            </a>
    5861          </p>
    59           <input type="file" name="form.formextension" />
     62          <input type="file" name="form.extraform" />
     63          <br />
     64          <span i18n:translate="">
     65            Max. file size:
     66          </span>
     67          <span tal:replace="view/max_file_upload_size">10 KB</span>
     68      </tr>
     69      <tr>
     70        <td class="fieldname" i18n:translate="">
     71          Referee's Form:
     72        </td>
     73        <td>
     74          <p tal:condition="python: view.file_exists('refereeform.pdf')">
     75            <a href="refereeform.pdf"
     76               i18n:translate="">
     77              Download pdf file
     78            </a>
     79          </p>
     80          <input type="file" name="form.refereeform" />
    6081          <br />
    6182          <span i18n:translate="">
  • main/waeup.futminna/trunk/src/waeup/futminna/applicants/tests/test_browser.py

    r10096 r10105  
    6565        self.assertTrue(img is None)
    6666
    67     def test_upload_formextension_by_student(self):
     67    def test_upload_extraform_by_student(self):
    6868        self.login()
    6969        self.browser.open(self.edit_path)
     
    7171        pdf_content = 'A' * 1024 * 600  # A string of 600 KB size
    7272        pseudo_pdf = StringIO(pdf_content)
    73         ctrl = self.browser.getControl(name='form.formextension')
     73        ctrl = self.browser.getControl(name='form.extraform')
    7474        file_ctrl = ctrl.mech_control
    7575        file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
     
    8181        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
    8282        pseudo_pdf = StringIO(pdf_content)
    83         ctrl = self.browser.getControl(name='form.formextension')
    84         file_ctrl = ctrl.mech_control
    85         file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
    86         self.browser.getControl("Save").click() # submit form
    87         # Even though the form could not be saved ...
    88         self.assertTrue('Required input is missing' in self.browser.contents)
    89         # ... the file has been successfully uploaded
    90         pdf_url = self.edit_path.replace('edit', 'formextension.pdf')
     83        ctrl = self.browser.getControl(name='form.extraform')
     84        file_ctrl = ctrl.mech_control
     85        file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
     86        self.browser.getControl("Save").click() # submit form
     87        # Even though the form could not be saved ...
     88        self.assertTrue('Required input is missing' in self.browser.contents)
     89        # ... the file has been successfully uploaded
     90        pdf_url = self.edit_path.replace('edit', 'extraform.pdf')
    9191        self.browser.open(pdf_url)
    9292        self.assertEqual(
     
    9696        storage = getUtility(IExtFileStore)
    9797        file_id = IFileStoreNameChooser(self.applicant).chooseName(
    98             attr='formextension.pdf')
    99         # The stored file can be fetched
    100         fd = storage.getFile(file_id)
    101         file_len = len(fd.read())
    102         self.assertEqual(file_len, 307200)
    103         # A file link is displayed on the edit view ...
    104         self.browser.open(self.edit_path)
    105         self.assertTrue('<a href="formextension.pdf">' in self.browser.contents)
    106         # ... and on the dislay view
    107         self.browser.open(self.view_path)
    108         self.assertTrue('<a href="formextension.pdf">Offline Form Extension</a>'
    109             in self.browser.contents)
    110 
    111     def test_upload_formextension_by_manager(self):
     98            attr='extraform.pdf')
     99        # The stored file can be fetched
     100        fd = storage.getFile(file_id)
     101        file_len = len(fd.read())
     102        self.assertEqual(file_len, 307200)
     103        # A file link is displayed on the edit view ...
     104        self.browser.open(self.edit_path)
     105        self.assertTrue('<a href="extraform.pdf">' in self.browser.contents)
     106        # ... and on the dislay view
     107        self.browser.open(self.view_path)
     108        self.assertTrue('<a href="extraform.pdf">Extra Applicant Information Form</a>'
     109            in self.browser.contents)
     110
     111    def test_upload_extraform_by_manager(self):
    112112        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    113113        self.browser.open(self.manage_path)
     
    115115        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
    116116        pseudo_pdf = StringIO(pdf_content)
    117         ctrl = self.browser.getControl(name='form.formextension')
    118         file_ctrl = ctrl.mech_control
    119         file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
    120         self.browser.getControl("Save").click() # submit form
    121         # Even though the form could not be saved ...
    122         self.assertTrue('Required input is missing' in self.browser.contents)
    123         # ... the file has been successfully uploaded
    124         pdf_url = self.manage_path.replace('manage', 'formextension.pdf')
     117        ctrl = self.browser.getControl(name='form.extraform')
     118        file_ctrl = ctrl.mech_control
     119        file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
     120        self.browser.getControl("Save").click() # submit form
     121        # Even though the form could not be saved ...
     122        self.assertTrue('Required input is missing' in self.browser.contents)
     123        # ... the file has been successfully uploaded
     124        pdf_url = self.manage_path.replace('manage', 'extraform.pdf')
    125125        self.browser.open(pdf_url)
    126126        self.assertEqual(
     
    130130        storage = getUtility(IExtFileStore)
    131131        file_id = IFileStoreNameChooser(self.applicant).chooseName(
    132             attr='formextension.pdf')
    133         # The stored file can be fetched
    134         fd = storage.getFile(file_id)
    135         file_len = len(fd.read())
    136         self.assertEqual(file_len, 307200)
    137         # A file link is displayed on the edit view ...
    138         self.browser.open(self.manage_path)
    139         self.assertTrue('<a href="formextension.pdf">' in self.browser.contents)
    140         # ... and on the dislay view
    141         self.browser.open(self.view_path)
    142         self.assertTrue('<a href="formextension.pdf">Offline Form Extension</a>'
     132            attr='extraform.pdf')
     133        # The stored file can be fetched
     134        fd = storage.getFile(file_id)
     135        file_len = len(fd.read())
     136        self.assertEqual(file_len, 307200)
     137        # A file link is displayed on the edit view ...
     138        self.browser.open(self.manage_path)
     139        self.assertTrue('<a href="extraform.pdf">' in self.browser.contents)
     140        # ... and on the dislay view
     141        self.browser.open(self.view_path)
     142        self.assertTrue('<a href="extraform.pdf">Extra Applicant Information Form</a>'
    143143            in self.browser.contents)
    144144        # Adding file is properly logged
     
    148148        self.assertTrue(
    149149            'zope.mgr - waeup.futminna.applicants.browser.CustomApplicantManageFormPage'
    150             ' - %s - saved: formextension'
     150            ' - %s - saved: extraform'
    151151            % (self.applicant.applicant_id)
    152152            in logcontent)
     153
     154    def test_upload_refereeform_by_student(self):
     155        self.login()
     156        self.browser.open(self.edit_path)
     157        # Create a pseudo file and select it to be uploaded in form
     158        pdf_content = 'A' * 1024 * 600  # A string of 600 KB size
     159        pseudo_pdf = StringIO(pdf_content)
     160        ctrl = self.browser.getControl(name='form.refereeform')
     161        file_ctrl = ctrl.mech_control
     162        file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
     163        self.browser.getControl("Save").click() # submit form
     164        # We get a warning message
     165        self.assertTrue(
     166            'Uploaded file is too big' in self.browser.contents)
     167        # Create a pseudo file with acceptable size
     168        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
     169        pseudo_pdf = StringIO(pdf_content)
     170        ctrl = self.browser.getControl(name='form.refereeform')
     171        file_ctrl = ctrl.mech_control
     172        file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
     173        self.browser.getControl("Save").click() # submit form
     174        # Even though the form could not be saved ...
     175        self.assertTrue('Required input is missing' in self.browser.contents)
     176        # ... the file has been successfully uploaded
     177        pdf_url = self.edit_path.replace('edit', 'refereeform.pdf')
     178        self.browser.open(pdf_url)
     179        self.assertEqual(
     180            self.browser.headers['content-type'], 'application/pdf')
     181        self.assertEqual(len(self.browser.contents), 307200)
     182        # There is really a file stored for the applicant
     183        storage = getUtility(IExtFileStore)
     184        file_id = IFileStoreNameChooser(self.applicant).chooseName(
     185            attr='refereeform.pdf')
     186        # The stored file can be fetched
     187        fd = storage.getFile(file_id)
     188        file_len = len(fd.read())
     189        self.assertEqual(file_len, 307200)
     190        # A file link is displayed on the edit view ...
     191        self.browser.open(self.edit_path)
     192        self.assertTrue('<a href="refereeform.pdf">' in self.browser.contents)
     193        # ... and on the dislay view
     194        self.browser.open(self.view_path)
     195        self.assertTrue('<a href="refereeform.pdf">Referee\'s Form</a>'
     196            in self.browser.contents)
     197
     198    def test_upload_refereeform_by_manager(self):
     199        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     200        self.browser.open(self.manage_path)
     201        # Create a pseudo file with acceptable size
     202        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
     203        pseudo_pdf = StringIO(pdf_content)
     204        ctrl = self.browser.getControl(name='form.refereeform')
     205        file_ctrl = ctrl.mech_control
     206        file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
     207        self.browser.getControl("Save").click() # submit form
     208        # Even though the form could not be saved ...
     209        self.assertTrue('Required input is missing' in self.browser.contents)
     210        # ... the file has been successfully uploaded
     211        pdf_url = self.manage_path.replace('manage', 'refereeform.pdf')
     212        self.browser.open(pdf_url)
     213        self.assertEqual(
     214            self.browser.headers['content-type'], 'application/pdf')
     215        self.assertEqual(len(self.browser.contents), 307200)
     216        # There is rally a file stored for the applicant
     217        storage = getUtility(IExtFileStore)
     218        file_id = IFileStoreNameChooser(self.applicant).chooseName(
     219            attr='refereeform.pdf')
     220        # The stored file can be fetched
     221        fd = storage.getFile(file_id)
     222        file_len = len(fd.read())
     223        self.assertEqual(file_len, 307200)
     224        # A file link is displayed on the edit view ...
     225        self.browser.open(self.manage_path)
     226        self.assertTrue('<a href="refereeform.pdf">' in self.browser.contents)
     227        # ... and on the dislay view
     228        self.browser.open(self.view_path)
     229        self.assertTrue('<a href="refereeform.pdf">Referee\'s Form</a>'
     230            in self.browser.contents)
     231        # Adding file is properly logged
     232        logfile = os.path.join(
     233            self.app['datacenter'].storage, 'logs', 'applicants.log')
     234        logcontent = open(logfile).read()
     235        self.assertTrue(
     236            'zope.mgr - waeup.futminna.applicants.browser.CustomApplicantManageFormPage'
     237            ' - %s - saved: refereeform'
     238            % (self.applicant.applicant_id)
     239            in logcontent)
Note: See TracChangeset for help on using the changeset viewer.