Ignore:
Timestamp:
14 Nov 2011, 12:17:54 (13 years ago)
Author:
Henrik Bettermann
Message:

Add second file upload viewlet, add tests and repair FileUpload? methods. Each button must get a dedicated id and name.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/students
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/fileupload.pt

    r7108 r7111  
    1313          LINK
    1414        </a>
    15         <input type="submit" id="delete"
    16                name="delete" value="Delete" class="button" />
    17         <br /><br />
     15        <input type="submit"
     16               tal:attributes="id python:('delete_%s' % viewlet.input_name);
     17                  name python:('delete_%s' % viewlet.input_name)"
     18               value="Delete" class="button" />
     19        <br />
    1820      </tal:file>
    1921      <input type="file" tal:attributes="name viewlet/input_name"/>
    20       <input type="submit" id="upload"
    21              name="upload" value="Upload" class="button" />
     22      <input type="submit"
     23               tal:attributes="id python:('upload_%s' % viewlet.input_name);
     24                  name python:('upload_%s' % viewlet.input_name)"
     25               value="Upload" class="button" />
    2226      <br />
    2327      <span i18n:translate="">
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r7110 r7111  
    374374        ctrl = self.browser.getControl(name='birth_certificate')
    375375        file_ctrl = ctrl.mech_control
    376         file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
     376        file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.jpg')
    377377        # The Save action does not upload files
    378378        self.browser.getControl("Save (no upload)").click() # submit form
     
    380380            '<a target="image" href="birth_certificate.jpg">'
    381381            in self.browser.contents)
    382         # ... but the Upload submit button does
     382        # ... but the correct upload submit button does
    383383        pseudo_image = StringIO('I pretend to be a graphics file')
    384384        ctrl = self.browser.getControl(name='birth_certificate')
    385385        file_ctrl = ctrl.mech_control
    386         file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
    387         self.browser.getControl("Upload").click()
     386        file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.jpg')
     387        self.browser.getControl(name='upload_birth_certificate').click()
    388388        # There is a correct <img> link included
    389389        self.assertTrue(
     
    401401        ctrl = self.browser.getControl(name='birth_certificate')
    402402        file_ctrl = ctrl.mech_control
    403         file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
    404         self.browser.getControl("Upload").click()
     403        file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.jpg')
     404        self.browser.getControl(name='upload_birth_certificate').click()
    405405        self.assertTrue(
    406406            'Uploaded file is too big' in self.browser.contents)
     
    410410        file_ctrl = ctrl.mech_control
    411411        file_ctrl.add_file(pseudo_image, filename='my.photo.jpg')
    412         self.browser.getControl("Upload").click()
     412        self.browser.getControl(name='upload_birth_certificate').click()
    413413        self.assertTrue('File name contains more than one dot'
    414414            in self.browser.contents)
    415415        ctrl = self.browser.getControl(name='birth_certificate')
    416416        file_ctrl = ctrl.mech_control
    417         file_ctrl.add_file(pseudo_image, filename='myphoto')
    418         self.browser.getControl("Upload").click()
     417        file_ctrl.add_file(pseudo_image, filename='my_birth_certificate')
     418        self.browser.getControl(name='upload_birth_certificate').click()
    419419        self.assertTrue('File name has no extension' in self.browser.contents)
    420420        ctrl = self.browser.getControl(name='birth_certificate')
    421421        file_ctrl = ctrl.mech_control
    422         file_ctrl.add_file(pseudo_image, filename='myphoto.bmp')
    423         self.browser.getControl("Upload").click()
     422        file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.bmp')
     423        self.browser.getControl(name='upload_birth_certificate').click()
    424424        self.assertTrue('.jpg file extension expected' in self.browser.contents)
    425425        # Managers can delete files
    426         self.browser.getControl("Delete").click()
     426        self.browser.getControl(name='delete_birth_certificate').click()
    427427        self.assertTrue(
    428428            'File birth_certificate.jpg deleted'
     429            in self.browser.contents)
     430        # Managers can add and delete second file
     431        self.browser.open(self.edit_clearance_student_path)
     432        pseudo_image = StringIO('I pretend to be a graphics file')
     433        ctrl = self.browser.getControl(name='birth_certificate')
     434        file_ctrl = ctrl.mech_control
     435        file_ctrl.add_file(pseudo_image, filename='my_acceptance_letter.jpg')
     436        self.browser.getControl(name='upload_acceptance_letter').click()
     437        self.assertFalse(
     438            '<a target="image" href="acceptance_letter.jpg">'
     439            in self.browser.contents)
     440        ctrl = self.browser.getControl(name='acceptance_letter')
     441        file_ctrl = ctrl.mech_control
     442        file_ctrl.add_file(pseudo_image, filename='my_acceptance_letter.jpg')
     443        self.browser.getControl(name='upload_acceptance_letter').click()
     444        self.assertTrue(
     445            '<a target="image" href="acceptance_letter.jpg">'
     446            in self.browser.contents)
     447        self.browser.getControl(name='delete_acceptance_letter').click()
     448        self.assertTrue(
     449            'File acceptance_letter.jpg deleted'
    429450            in self.browser.contents)
    430451
  • main/waeup.sirp/trunk/src/waeup/sirp/students/viewlets.py

    r7110 r7111  
    278278    def update(self):
    279279        self.max_upload_size = string_from_bytes(self.mus)
    280         delete_button = self.request.form.get('delete', None)
     280        delete_button = self.request.form.get('delete_%s' % self.input_name, None)
     281        upload_button = self.request.form.get('upload_%s' % self.input_name, None)
    281282        if delete_button:
    282283            handle_file_delete(
     
    286287                self.view.url(self.context, self.view.__name__))
    287288            return
    288         upload_button = self.request.form.get('upload', None)
    289289        if upload_button:
    290290            upload = self.request.form.get(self.input_name, None)
    291291            if upload:
    292292                # We got a fresh upload
    293                 file_changed = handle_file_upload(
    294                     upload, self.context, self.view, self.mus, self.download_name)
    295                 if file_changed is False:  # False is not None!
    296                     self.view.redirect(
    297                         self.view.url(self.context, self.view.__name__))
    298                     return # error during file upload. Ignore other values
     293                handle_file_upload(upload,
     294                    self.context, self.view, self.mus, self.download_name)
     295                self.view.redirect(
     296                    self.view.url(self.context, self.view.__name__))
    299297        return
    300298
     
    314312    download_name = u'birth_certificate.jpg'
    315313    input_name = u'birth_certificate'
     314
     315class AcceptanceLetterDisplay(FileDisplay):
     316    """Acceptance Letter upload viewlet.
     317    """
     318    grok.order(1)
     319    label = u'Acceptance Letter:'
     320    download_name = u'acceptance_letter.jpg'
     321
     322class AcceptanceLetterUpload(FileUpload):
     323    """AcceptanceLetter upload viewlet.
     324    """
     325    grok.order(1)
     326    label = u'Acceptance Letter (jpg only):'
     327    mus = 1024 * 150
     328    download_name = u'acceptance_letter.jpg'
     329    input_name = u'acceptance_letter'
    316330
    317331class Image(grok.View):
     
    338352
    339353class BirthCertificateImage(Image):
    340     """Renders birth certificate jpeg image.
     354    """Renders birth certificate jpeg scan.
    341355    """
    342356    grok.name('birth_certificate.jpg')
    343357    download_name = u'birth_certificate.jpg'
     358
     359class AcceptanceLetterImage(Image):
     360    """Renders acceptance letter jpeg scan.
     361    """
     362    grok.name('acceptance_letter.jpg')
     363    download_name = u'acceptance_letter.jpg'
Note: See TracChangeset for help on using the changeset viewer.