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

Include permission waeup.uploadStudentFile to handle file uploads.

Fix pagetemplate filesuploadpage.pt.

Rearrange fileupload.pt

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

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r7116 r7127  
    15051505    def update(self):
    15061506        super(StudentPasswordFormPage, self).update()
    1507         self.wf_info = IWorkflowInfo(self.context)
     1507        #self.wf_info = IWorkflowInfo(self.context)
    15081508        return
    15091509
     
    15371537    grok.context(IStudent)
    15381538    grok.name('change_portrait')
    1539     grok.require('waeup.handleStudent')
     1539    grok.require('waeup.uploadStudentFile')
    15401540    grok.template('filesuploadpage')
    15411541    label = 'Upload portrait'
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/filesuploadpage.pt

    r7114 r7127  
    33    tal:content="view/label">Label</h2>
    44
    5 <table class="zebra">
    6   <tbody>
    7     <tal:files content="structure provider:files" />
    8   </tbody>
    9 </table>
     5<form action="." tal:attributes="action request/URL" method="post"
     6      class="edit-form" enctype="multipart/form-data">
     7  <table class="zebra">
     8    <tbody>
     9      <tal:files content="structure provider:files" />
     10    </tbody>
     11  </table>
     12</form>
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/fileupload.pt

    r7111 r7127  
    77  <td class="field">
    88    <span class="widget">
     9
    910      <tal:file tal:condition="viewlet/file_exists">
    1011        <a tal:attributes="href viewlet/download_name"
    11            tal:content="viewlet/download_name"
     12           tal:content="viewlet/title"
    1213           target="image">
    1314          LINK
    1415        </a>
    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 />
    2016      </tal:file>
     17      <br />
    2118      <input type="file" tal:attributes="name viewlet/input_name"/>
     19      <br />
     20      <input type="submit" tal:condition="viewlet/file_exists"
     21             tal:attributes="id python:('delete_%s' % viewlet.input_name);
     22                name python:('delete_%s' % viewlet.input_name)"
     23             value="Delete attachment" class="button" />
    2224      <input type="submit"
    2325               tal:attributes="id python:('upload_%s' % viewlet.input_name);
    2426                  name python:('upload_%s' % viewlet.input_name)"
    25                value="Upload" class="button" />
    26       <br />
     27               value="Upload new file" class="button" />
    2728      <span i18n:translate="">
    2829        Max. file size:
     
    3031      </span>
    3132    </span>
     33    <br />
    3234  </td>
    3335</tr>
  • main/waeup.sirp/trunk/src/waeup/sirp/students/permissions.py

    r6930 r7127  
    3030    grok.name('waeup.payStudent')
    3131
     32class UploadStudentFile(grok.Permission):
     33    grok.name('waeup.uploadStudentFile')
     34
    3235class ManageStudents(grok.Permission):
    3336    grok.name('waeup.manageStudents')
     
    3740    grok.name('waeup.local.StudentRecordOwner')
    3841    grok.title(u'Student Record Owner')
    39     grok.permissions('waeup.handleStudent',
     42    grok.permissions('waeup.handleStudent', 'waeup.uploadStudentFile',
    4043                     'waeup.viewStudent', 'waeup.payStudent')
    4144
     
    5053    grok.permissions('waeup.View', 'waeup.Public',
    5154                     'waeup.viewStudent', 'waeup.manageStudents',
    52                      'waeup.payStudent')
     55                     'waeup.payStudent', 'waeup.uploadStudentFile')
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r7124 r7127  
    357357        return
    358358
    359     def test_upload_file(self):
     359    def test_manage_upload_file(self):
    360360        # Managers can upload a file via the StudentClearanceManageFormPage
    361361        # The image is stored even if form has errors
     
    372372        self.browser.open(self.edit_clearance_student_path)
    373373        pseudo_image = StringIO('I pretend to be a graphics file')
    374         ctrl = self.browser.getControl(name='birthcertificateuploadmanage')
     374        ctrl = self.browser.getControl(name='birthcertificateupload')
    375375        file_ctrl = ctrl.mech_control
    376376        file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.jpg')
     
    382382        # ... but the correct upload submit button does
    383383        pseudo_image = StringIO('I pretend to be a graphics file')
    384         ctrl = self.browser.getControl(name='birthcertificateuploadmanage')
     384        ctrl = self.browser.getControl(name='birthcertificateupload')
    385385        file_ctrl = ctrl.mech_control
    386386        file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.jpg')
    387387        self.browser.getControl(
    388             name='upload_birthcertificateuploadmanage').click()
     388            name='upload_birthcertificateupload').click()
    389389        # There is a correct <img> link included
    390390        self.assertTrue(
     
    401401        photo_content = 'A' * 1024 * 151  # A string of 21 KB size
    402402        pseudo_image = StringIO(photo_content)
    403         ctrl = self.browser.getControl(name='birthcertificateuploadmanage')
     403        ctrl = self.browser.getControl(name='birthcertificateupload')
    404404        file_ctrl = ctrl.mech_control
    405405        file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.jpg')
    406406        self.browser.getControl(
    407             name='upload_birthcertificateuploadmanage').click()
     407            name='upload_birthcertificateupload').click()
    408408        self.assertTrue(
    409409            'Uploaded file is too big' in self.browser.contents)
    410410        # File names must meet several conditions
    411411        pseudo_image = StringIO('I pretend to be a graphics file')
    412         ctrl = self.browser.getControl(name='birthcertificateuploadmanage')
     412        ctrl = self.browser.getControl(name='birthcertificateupload')
    413413        file_ctrl = ctrl.mech_control
    414414        file_ctrl.add_file(pseudo_image, filename='my.photo.jpg')
    415415        self.browser.getControl(
    416             name='upload_birthcertificateuploadmanage').click()
     416            name='upload_birthcertificateupload').click()
    417417        self.assertTrue('File name contains more than one dot'
    418418            in self.browser.contents)
    419         ctrl = self.browser.getControl(name='birthcertificateuploadmanage')
     419        ctrl = self.browser.getControl(name='birthcertificateupload')
    420420        file_ctrl = ctrl.mech_control
    421421        file_ctrl.add_file(pseudo_image, filename='my_birth_certificate')
    422422        self.browser.getControl(
    423             name='upload_birthcertificateuploadmanage').click()
     423            name='upload_birthcertificateupload').click()
    424424        self.assertTrue('File name has no extension' in self.browser.contents)
    425         ctrl = self.browser.getControl(name='birthcertificateuploadmanage')
     425        ctrl = self.browser.getControl(name='birthcertificateupload')
    426426        file_ctrl = ctrl.mech_control
    427427        file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.bmp')
    428428        self.browser.getControl(
    429             name='upload_birthcertificateuploadmanage').click()
     429            name='upload_birthcertificateupload').click()
    430430        self.assertTrue('Only the following extension are allowed'
    431431            in self.browser.contents)
    432432        # Managers can delete files
    433         self.browser.getControl(name='delete_birthcertificateuploadmanage').click()
     433        self.browser.getControl(name='delete_birthcertificateupload').click()
    434434        self.assertTrue(
    435435            'birth_certificate deleted' in self.browser.contents)
     
    437437        self.browser.open(self.edit_clearance_student_path)
    438438        pseudo_image = StringIO('I pretend to be a graphics file')
    439         ctrl = self.browser.getControl(name='birthcertificateuploadmanage')
     439        ctrl = self.browser.getControl(name='birthcertificateupload')
    440440        file_ctrl = ctrl.mech_control
    441441        file_ctrl.add_file(pseudo_image, filename='my_acceptance_letter.jpg')
    442442        self.browser.getControl(
    443             name='upload_acceptanceletteruploadmanage').click()
     443            name='upload_acceptanceletterupload').click()
    444444        self.assertFalse(
    445445            '<a target="image" href="acceptance_letter">'
    446446            in self.browser.contents)
    447         ctrl = self.browser.getControl(name='acceptanceletteruploadmanage')
     447        ctrl = self.browser.getControl(name='acceptanceletterupload')
    448448        file_ctrl = ctrl.mech_control
    449449        file_ctrl.add_file(pseudo_image, filename='my_acceptance_letter.jpg')
    450450        self.browser.getControl(
    451             name='upload_acceptanceletteruploadmanage').click()
     451            name='upload_acceptanceletterupload').click()
    452452        self.assertTrue(
    453453            '<a target="image" href="acceptance_letter">'
    454454            in self.browser.contents)
    455455        self.browser.getControl(
    456             name='delete_acceptanceletteruploadmanage').click()
     456            name='delete_acceptanceletterupload').click()
    457457        self.assertTrue(
    458458            'acceptance_letter deleted'
     
    738738        self.browser.getControl(name="form.password").value = 'spwd'
    739739        self.browser.getControl("Login").click()
     740        # Student can upload a passport picture
     741        self.browser.open(self.student_path + '/change_portrait')
     742        pseudo_image = StringIO('I pretend to be a graphics file')
     743        ctrl = self.browser.getControl(name='passportuploadedit')
     744        file_ctrl = ctrl.mech_control
     745        file_ctrl.add_file(pseudo_image, filename='my_photo.jpg')
     746        self.browser.getControl(
     747            name='upload_passportuploadedit').click()
     748        self.assertTrue(
     749            '<img align="middle" height="125px" src="passport.jpg" />'
     750            in self.browser.contents)
    740751        # Student can view the clearance data
    741752        self.browser.getLink("Clearance Data").click()
  • main/waeup.sirp/trunk/src/waeup/sirp/students/viewlets.py

    r7123 r7127  
    265265    grok.require('waeup.viewStudent')
    266266    label = u'File:'
     267    title = u'Scan'
    267268    download_name = u'filename.jpg'
    268269
     
    284285    grok.view(StudentClearanceManageFormPage)
    285286    grok.template('fileupload')
    286     grok.require('waeup.manageStudents')
     287    grok.require('waeup.uploadStudentFile')
    287288    mus = 1024 * 150
    288289
     
    345346    """
    346347    grok.view(StudentFilesUploadPage)
    347     grok.require('waeup.handleStudent')
     348    grok.require('waeup.uploadStudentFile')
    348349
    349350class BirthCertificateDisplay(FileDisplay):
     
    352353    grok.order(1)
    353354    label = u'Birth Certificate:'
     355    title = u'Birth Certificate Scan'
    354356    download_name = u'birth_certificate'
    355357
    356 class BirthCertificateUploadManage(FileUpload):
     358class BirthCertificateUpload(FileUpload):
    357359    """Birth Certificate upload viewlet.
    358360    """
    359361    grok.order(1)
    360362    label = u'Birth Certificate:'
     363    title = u'Birth Certificate Scan'
    361364    mus = 1024 * 150
    362365    download_name = u'birth_certificate'
     
    367370    grok.order(1)
    368371    label = u'Acceptance Letter:'
     372    title = u'Acceptance Letter Scan'
    369373    download_name = u'acceptance_letter'
    370374
    371 class AcceptanceLetterUploadManage(FileUpload):
     375class AcceptanceLetterUpload(FileUpload):
    372376    """AcceptanceLetter upload viewlet.
    373377    """
    374378    grok.order(2)
    375379    label = u'Acceptance Letter:'
     380    title = u'Acceptance Letter Scan'
    376381    mus = 1024 * 150
    377382    download_name = u'acceptance_letter'
    378 
    379 class BirthCertificateUploadEdit(BirthCertificateUploadManage):
    380     """Birth Certificate upload viewlet for student.
    381     """
    382     grok.require('waeup.handleStudent')
    383 
    384 class AcceptanceLetterUploadEdit(AcceptanceLetterUploadManage):
    385     """AcceptanceLetter upload viewlet for student.
    386     """
    387     grok.require('waeup.handleStudent')
    388383
    389384class Image(grok.View):
Note: See TracChangeset for help on using the changeset viewer.