Changeset 6598


Ignore:
Timestamp:
12 Aug 2011, 15:23:23 (13 years ago)
Author:
uli
Message:

Workaround for freshly uploaded images not being displayed in
otherwise erraneous applicants forms.

File:
1 edited

Legend:

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

    r6595 r6598  
    5454    ThumbnailWidget, EncodingImageFileWidget,
    5555    )
     56from waeup.sirp.image.image import createWAeUPImageFile
    5657from waeup.sirp.interfaces import IWAeUPObject, ILocalRolesAssignable
    5758from waeup.sirp.permissions import get_users_with_local_roles
     
    708709        super(EditApplicantFull, self).update()
    709710        self.wf_info = IWorkflowInfo(self.context)
     711        upload = self.request.form.get('form.passport', None)
     712        if upload:
     713            # We got a fresh upload
     714            image = createWAeUPImageFile(upload.filename, upload)
     715            # This would normally be totally illegal. We set context
     716            # data without the complete form data being
     717            # verified. Normally data is set in methods like `save`
     718            # only, which is only called when all form data is correct
     719            # (and if not, the context is not touched). With images
     720            # and their uploads the problem then is, that the uploaded
     721            # image won't be shown in a partially erranous form
     722            # because the new uploaded image is still not part of the
     723            # context obeject and the image widget cannot work around
     724            # that (it has no access to the new data). For this reason
     725            # we set the image here and not in 'save()' or other
     726            # methods.
     727            self.context.passport = image
     728            upload.seek(0)
     729            self.passport_changed = True
    710730        return
    711731
     
    769789    def update(self):
    770790        if self.context.locked:
    771             #import pdb; pdb.set_trace()
    772791            self.emitLockMessage()
    773792            return
    774793        datepicker.need() # Enable jQuery datepicker in date fields.
     794        upload = self.request.form.get('form.passport', None)
     795        if upload:
     796            # We got a fresh upload
     797            image = createWAeUPImageFile(upload.filename, upload)
     798            # This would normally be totally illegal. We set context
     799            # data without the complete form data being
     800            # verified. Normally data is set in methods like `save`
     801            # only, which is only called when all form data is correct
     802            # (and if not, the context is not touched). With images
     803            # and their uploads the problem then is, that the uploaded
     804            # image won't be shown in a partially erranous form
     805            # because the new uploaded image is still not part of the
     806            # context obeject and the image widget cannot work around
     807            # that (it has no access to the new data). For this reason
     808            # we set the image here and not in 'save()' or other
     809            # methods.
     810            self.context.passport = image
     811            upload.seek(0)
     812            self.passport_changed = True
    775813        super(EditApplicantStudent, self).update()
    776814        return
Note: See TracChangeset for help on using the changeset viewer.