Changeset 7102


Ignore:
Timestamp:
13 Nov 2011, 09:18:36 (13 years ago)
Author:
Henrik Bettermann
Message:

Use given file name extension provided by original uploaded file instead.

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

Legend:

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

    r7099 r7102  
    182182        *Example:*
    183183
    184         For a student with student id ``'A123456'`` and
    185         with attr ``'nice_image'`` stored in
     184        For a student with student id ``'A123456'``,
     185        with attr ``'nice_image'`` and an uploaded file named
     186        `'anybasename.JPG'`` to be stored in
    186187        the students container this chooser would create:
    187188
     
    194195
    195196        """
     197        ext = u''
     198        if name and name.count('.') == 1:
     199            basename, ext = os.path.splitext(name)
     200        ext.lower()
    196201        stud_id = self.context.student_id
    197         marked_filename = '__%s__%s/%s/%s_%s.jpg' % (
    198             STUDENT_FILE_STORE_NAME, stud_id[0], stud_id, attr, stud_id)
     202        marked_filename = '__%s__%s/%s/%s_%s%s' % (
     203            STUDENT_FILE_STORE_NAME, stud_id[0], stud_id, attr, stud_id, ext)
    199204        return marked_filename
    200205
  • main/waeup.sirp/trunk/src/waeup/sirp/students/viewlets.py

    r7100 r7102  
    198198        return self.view.application_url() + rel_link
    199199
    200 def handle_img_upload(upload, context, view, max_size, attr=None):
     200def handle_file_upload(upload, context, view, max_size, attr=None):
    201201    """Handle upload of applicant image.
    202202
     
    212212    upload.seek(0) # file pointer moved when determining size
    213213    store = getUtility(IExtFileStore)
    214     file_id = IFileStoreNameChooser(context).chooseName(attr=attr)
     214    file_id = IFileStoreNameChooser(
     215        context).chooseName(attr=attr, name=upload.filename)
    215216    store.createFile(file_id, upload)
    216217    return True
     
    252253        if upload:
    253254            # We got a fresh upload
    254             file_changed = handle_img_upload(
     255            file_changed = handle_file_upload(
    255256                upload, self.context, self.view, self.mus, self.attr)
    256257            if file_changed is False:  # False is not None!
Note: See TracChangeset for help on using the changeset viewer.