Ignore:
Timestamp:
16 Nov 2011, 21:31:38 (13 years ago)
Author:
Henrik Bettermann
Message:

Let applicants cooperate with new imagestorage. Fix tests.

Extend permissions for PortalManager?.

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

Legend:

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

    r6907 r7122  
    6969                     'waeup.managePortalConfiguration',
    7070                     'waeup.manageApplications', 'waeup.handleApplication',
    71                      'waeup.viewStudents', 'waeup.manageStudents')
     71                     'waeup.viewStudent', 'waeup.manageStudents',
     72                     'waeup.viewHostels', 'waeup.manageHostels')
    7273
    7374def getRoles():
  • main/waeup.sirp/trunk/src/waeup/sirp/students/student.py

    r7106 r7122  
    223223        """
    224224        marker, filename, basename, ext = store.extractMarker(file_id)
    225         return os.path.join(root, 'students', filename)
     225        sub_root = os.path.join(root, 'students')
     226        return super(StudentFileStoreHandler, self).pathFromFileID(
     227            store, sub_root, basename)
    226228
    227229    def createFile(self, store, root, filename, file_id, file):
    228230        """Create a browsable file-like object.
    229231        """
    230         # possible other actions: check for jpeg format
    231         path = self.pathFromFileID(store, root, file_id)
    232         return file, path, WAeUPImageFile(filename, file_id)
     232        ext = os.path.splitext(filename)[1].lower()
     233        if ext not in ['.jpg', '.png']:
     234            raise ValueError('Only .jpg and .png allowed')
     235        # call super method to ensure that any old files with
     236        # different filename extension are deleted.
     237        file, path, file_obj =  super(
     238            StudentFileStoreHandler, self).createFile(
     239            store, root,  filename, file_id, file)
     240        return file, path, WAeUPImageFile(
     241            file_obj.filename, file_obj.data)
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r7111 r7122  
    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='birth_certificate')
     374        ctrl = self.browser.getControl(name='birthcertificateuploadmanage')
    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='birth_certificate')
     384        ctrl = self.browser.getControl(name='birthcertificateuploadmanage')
    385385        file_ctrl = ctrl.mech_control
    386386        file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.jpg')
    387         self.browser.getControl(name='upload_birth_certificate').click()
     387        self.browser.getControl(
     388            name='upload_birthcertificateuploadmanage').click()
    388389        # There is a correct <img> link included
    389390        self.assertTrue(
    390391            '<a target="image" href="birth_certificate.jpg">'
    391392            in self.browser.contents)
     393
    392394        # Browsing the link shows a real image
    393395        self.browser.open('birth_certificate.jpg')
     
    399401        photo_content = 'A' * 1024 * 151  # A string of 21 KB size
    400402        pseudo_image = StringIO(photo_content)
    401         ctrl = self.browser.getControl(name='birth_certificate')
     403        ctrl = self.browser.getControl(name='birthcertificateuploadmanage')
    402404        file_ctrl = ctrl.mech_control
    403405        file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.jpg')
    404         self.browser.getControl(name='upload_birth_certificate').click()
     406        self.browser.getControl(
     407            name='upload_birthcertificateuploadmanage').click()
    405408        self.assertTrue(
    406409            'Uploaded file is too big' in self.browser.contents)
    407410        # File names must meet several conditions
    408411        pseudo_image = StringIO('I pretend to be a graphics file')
    409         ctrl = self.browser.getControl(name='birth_certificate')
     412        ctrl = self.browser.getControl(name='birthcertificateuploadmanage')
    410413        file_ctrl = ctrl.mech_control
    411414        file_ctrl.add_file(pseudo_image, filename='my.photo.jpg')
    412         self.browser.getControl(name='upload_birth_certificate').click()
     415        self.browser.getControl(
     416            name='upload_birthcertificateuploadmanage').click()
    413417        self.assertTrue('File name contains more than one dot'
    414418            in self.browser.contents)
    415         ctrl = self.browser.getControl(name='birth_certificate')
     419        ctrl = self.browser.getControl(name='birthcertificateuploadmanage')
    416420        file_ctrl = ctrl.mech_control
    417421        file_ctrl.add_file(pseudo_image, filename='my_birth_certificate')
    418         self.browser.getControl(name='upload_birth_certificate').click()
     422        self.browser.getControl(
     423            name='upload_birthcertificateuploadmanage').click()
    419424        self.assertTrue('File name has no extension' in self.browser.contents)
    420         ctrl = self.browser.getControl(name='birth_certificate')
     425        ctrl = self.browser.getControl(name='birthcertificateuploadmanage')
    421426        file_ctrl = ctrl.mech_control
    422427        file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.bmp')
    423         self.browser.getControl(name='upload_birth_certificate').click()
     428        self.browser.getControl(
     429            name='upload_birthcertificateuploadmanage').click()
    424430        self.assertTrue('.jpg file extension expected' in self.browser.contents)
    425431        # Managers can delete files
    426         self.browser.getControl(name='delete_birth_certificate').click()
     432        self.browser.getControl(name='delete_birthcertificateuploadmanage').click()
    427433        self.assertTrue(
    428434            'File birth_certificate.jpg deleted'
     
    431437        self.browser.open(self.edit_clearance_student_path)
    432438        pseudo_image = StringIO('I pretend to be a graphics file')
    433         ctrl = self.browser.getControl(name='birth_certificate')
     439        ctrl = self.browser.getControl(name='birthcertificateuploadmanage')
    434440        file_ctrl = ctrl.mech_control
    435441        file_ctrl.add_file(pseudo_image, filename='my_acceptance_letter.jpg')
    436         self.browser.getControl(name='upload_acceptance_letter').click()
     442        self.browser.getControl(
     443            name='upload_acceptanceletteruploadmanage').click()
    437444        self.assertFalse(
    438445            '<a target="image" href="acceptance_letter.jpg">'
    439446            in self.browser.contents)
    440         ctrl = self.browser.getControl(name='acceptance_letter')
     447        ctrl = self.browser.getControl(name='acceptanceletteruploadmanage')
    441448        file_ctrl = ctrl.mech_control
    442449        file_ctrl.add_file(pseudo_image, filename='my_acceptance_letter.jpg')
    443         self.browser.getControl(name='upload_acceptance_letter').click()
     450        self.browser.getControl(
     451            name='upload_acceptanceletteruploadmanage').click()
    444452        self.assertTrue(
    445453            '<a target="image" href="acceptance_letter.jpg">'
    446454            in self.browser.contents)
    447         self.browser.getControl(name='delete_acceptance_letter').click()
     455        self.browser.getControl(
     456            name='delete_acceptanceletteruploadmanage').click()
    448457        self.assertTrue(
    449458            'File acceptance_letter.jpg deleted'
Note: See TracChangeset for help on using the changeset viewer.