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

Reorganize file upload. Each viewlet gets an upload and a delete button and writes its own log message. Thus there is one line per file deletion or file upload in the log file. The save action does no longer upload the files.

It works perfectly in the UI but I have still some problems with the browser test.

File:
1 edited

Legend:

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

    r7107 r7108  
    88from waeup.sirp.browser import DEFAULT_IMAGE_PATH
    99from waeup.sirp.students.browser import (
    10     StudentClearanceDisplayFormPage, StudentClearanceManageFormPage)
     10    StudentClearanceDisplayFormPage, StudentClearanceManageFormPage,
     11    write_log_message)
    1112from waeup.sirp.students.interfaces import IStudentClearance
    1213
     
    205206    store = getUtility(IExtFileStore)
    206207    store.deleteFileByContext(context, attr=download_name)
     208    write_log_message(view, 'deleted: %s' % download_name)
    207209    view.flash('File %s deleted.' % download_name)
    208210    return
     
    227229    ext.lower()
    228230    if ext != expected_ext:
    229         view.flash('%s extension expected.' % expected_ext)
     231        view.flash('%s file extension expected.' % expected_ext)
    230232        return False
    231233    size = file_size(upload)
     
    237239    file_id = IFileStoreNameChooser(context).chooseName(attr=download_name)
    238240    store.createFile(file_id, upload)
     241    write_log_message(view, 'uploaded: %s (%s)' % (download_name,upload.filename))
     242    view.flash('File %s uploaded.' % download_name)
    239243    return True
    240244
     
    276280    grok.require('waeup.manageStudents')
    277281    mus = 1024 * 150
    278     input_name = u'form.filename'
     282    input_name = u'filename'
    279283
    280284    def update(self):
    281285        self.max_upload_size = string_from_bytes(self.mus)
    282         delete = self.request.form.get('delete', None)
    283         if delete:
    284             self.view.files_deleted += self.download_name
     286        delete_button = self.request.form.get('delete', None)
     287        if delete_button:
    285288            handle_file_delete(
    286289                context=self.context, view=self.view,
     
    289292                self.view.url(self.context, self.view.__name__))
    290293            return
    291         upload = self.request.form.get(self.input_name, None)
    292         if upload:
    293             # We got a fresh upload
    294             file_changed = handle_file_upload(
    295                 upload, self.context, self.view, self.mus, self.download_name)
    296             if file_changed is False:  # False is not None!
    297                 self.view.redirect(
    298                     self.view.url(self.context, self.view.__name__))
    299                 return # error during file upload. Ignore other values
    300             else:
    301                 self.view.files_changed += self.download_name
     294        upload_button = self.request.form.get('upload', None)
     295        if upload_button:
     296            upload = self.request.form.get(self.input_name, None)
     297            if upload:
     298                # We got a fresh upload
     299                file_changed = handle_file_upload(
     300                    upload, self.context, self.view, self.mus, self.download_name)
     301                if file_changed is False:  # False is not None!
     302                    self.view.redirect(
     303                        self.view.url(self.context, self.view.__name__))
     304                    return # error during file upload. Ignore other values
    302305        return
    303306
     
    313316    """
    314317    grok.order(1)
    315     label = u'Birth Certificate (jpeg image):'
     318    label = u'Birth Certificate (jpg only):'
    316319    mus = 1024 * 150
    317320    download_name = u'birth_certificate.jpg'
    318     input_name = u'form.birth_certificate'
     321    input_name = u'birth_certificate'
    319322
    320323class Image(grok.View):
Note: See TracChangeset for help on using the changeset viewer.