Index: /main/waeup.sirp/branches/ulif-extimgstore/src/waeup/sirp/applicants/browser.py
===================================================================
--- /main/waeup.sirp/branches/ulif-extimgstore/src/waeup/sirp/applicants/browser.py	(revision 7054)
+++ /main/waeup.sirp/branches/ulif-extimgstore/src/waeup/sirp/applicants/browser.py	(revision 7055)
@@ -54,5 +54,4 @@
     ManageActionButton, PrimaryNavTab, LeftSidebarLink
     )
-from waeup.sirp.image.image import createWAeUPImageFile
 from waeup.sirp.interfaces import (
     IWAeUPObject, ILocalRolesAssignable, IExtFileStore, IFileStoreNameChooser)
@@ -425,5 +424,6 @@
         # If application has ended and applicant record doesn't exist,
         # logout without marking AC as used
-        if not pin in self.context.keys() and self.context.enddate < date.today():
+        if not pin in self.context.keys() and (
+            self.context.enddate < date.today()):
             self.flash('Application has ended.')
             auth = getUtility(IAuthentication)
@@ -433,7 +433,5 @@
 
         # Mark AC as used (this also fires a pin related transition)
-        if get_access_code(pin).state == USED:
-            pass
-        else:
+        if get_access_code(pin).state != USED:
             comment = u"AC invalidated"
             # Here we know that the ac is in state initialized so we do not
@@ -514,6 +512,5 @@
             applicant_object = get_applicant_data(access_code)
             return absoluteURL(applicant_object, self.request) + self.target
-        #else:
-        #    return ''
+        return ''
 
 class AccessCodeEditLink(AccessCodeViewLink):
@@ -534,6 +531,5 @@
                 return ''
             return absoluteURL(applicant_object, self.request) + self.target
-        #else:
-        #    return ''
+        return ''
 
 class AccessCodeSlipLink(AccessCodeViewLink):
@@ -550,6 +546,4 @@
     form_fields = grok.AutoFields(IApplicant).omit(
         'locked').omit('course_admitted')
-    #form_fields['fst_sit_results'].custom_widget = list_results_display_widget
-    #form_fields['passport'].custom_widget = ThumbnailWidget
     form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le')
     label = 'Applicant'
@@ -586,5 +580,4 @@
 class PDFActionButton(ManageActionButton):
     grok.context(IApplicant)
-    #grok.view(DisplayApplicant)
     grok.require('waeup.manageApplications')
     icon = 'actionicon_pdf.png'
@@ -628,9 +621,4 @@
 
     def render(self):
-        # (0,0),(-1,-1) = whole table
-        # (0,0),(0,-1) = first column
-        # (-1,0),(-1,-1) = last column
-        # (0,0),(-1,0) = first row
-        # (0,-1),(-1,-1) = last row
         SLIP_STYLE = TableStyle(
             [('VALIGN',(0,0),(-1,-1),'TOP')]
@@ -705,4 +693,13 @@
     target = 'edit_full'
 
+def handle_img_upload(upload, context):
+    """Handle upload of applicant image.
+    """
+    store = getUtility(IExtFileStore)
+    file_id = IFileStoreNameChooser(context).chooseName()
+    store.createFile(file_id, upload)
+    upload.seek(0) # XXX: really neccessary?
+    return
+
 class EditApplicantFull(WAeUPEditFormPage):
     """A full edit view for applicant data.
@@ -712,5 +709,4 @@
     grok.require('waeup.manageApplications')
     form_fields = grok.AutoFields(IApplicant)
-    #form_fields['passport'].custom_widget = EncodingImageFileWidget
     form_fields['date_of_birth'].custom_widget = FriendlyDateWidget('le-year')
     grok.template('form_edit')
@@ -725,30 +721,5 @@
         if upload:
             # We got a fresh upload
-            #from waeup.sirp.interfaces import IExtFileStorage
-            #from zope.component import queryUtility
-            #storage = queryUtility(IExtFileStorage)
-            # filename = '__img_appl__' + str(self.context.reg_no) #upload.filename
-            store = getUtility(IExtFileStore)
-            file_id = IFileStoreNameChooser(self.context).chooseName()
-            store.createFile(file_id, upload)
-            #filename = '__img_appl__' + str(
-            #    self.context.access_code) + '.jpg' #upload.filename
-            print "FILENAME: ", file_id
-            # image = createWAeUPImageFile(upload.filename, upload)
-            #image = createWAeUPImageFile(filename, upload)
-            # This would normally be totally illegal. We set context
-            # data without the complete form data being
-            # verified. Normally data is set in methods like `save`
-            # only, which is only called when all form data is correct
-            # (and if not, the context is not touched). With images
-            # and their uploads the problem then is, that the uploaded
-            # image won't be shown in a partially erranous form
-            # because the new uploaded image is still not part of the
-            # context obeject and the image widget cannot work around
-            # that (it has no access to the new data). For this reason
-            # we set the image here and not in 'save()' or other
-            # methods.
-            #self.context.passport = image
-            upload.seek(0)
+            handle_img_upload(upload, self.context)
             self.passport_changed = True
         return
@@ -778,5 +749,6 @@
         changed_fields = self.applyData(self.context, **data)
         changed_fields = changed_fields.values()
-        fields_string = '+'.join(' + '.join(str(i) for i in b) for b in changed_fields)
+        fields_string = '+'.join(
+            ' + '.join(str(i) for i in b) for b in changed_fields)
         self.context._p_changed = True
         form = self.request.form
@@ -800,5 +772,4 @@
         'screening_score',
         )
-    #form_fields['passport'].custom_widget = EncodingImageFileWidget
     form_fields['date_of_birth'].custom_widget = FriendlyDateWidget('le-year')
     grok.template('form_edit')
@@ -806,5 +777,4 @@
     title = u'Your Application Form'
 
-
     def emitLockMessage(self):
         self.flash('The requested form is locked (read-only).')
@@ -820,19 +790,5 @@
         if upload:
             # We got a fresh upload
-            image = createWAeUPImageFile(upload.filename, upload)
-            # This would normally be totally illegal. We set context
-            # data without the complete form data being
-            # verified. Normally data is set in methods like `save`
-            # only, which is only called when all form data is correct
-            # (and if not, the context is not touched). With images
-            # and their uploads the problem then is, that the uploaded
-            # image won't be shown in a partially erranous form
-            # because the new uploaded image is still not part of the
-            # context obeject and the image widget cannot work around
-            # that (it has no access to the new data). For this reason
-            # we set the image here and not in 'save()' or other
-            # methods.
-            self.context.passport = image
-            upload.seek(0)
+            handle_img_upload(upload, self.context)
             self.passport_changed = True
         super(EditApplicantStudent, self).update()
@@ -842,13 +798,8 @@
         if not self.request.form.get('confirm_passport', False):
             return 'Passport confirmation box not ticked.'
-        #if len(self.errors) > 0:
-        #    return 'Form has errors.'
         return False
 
     @grok.action('Save')
     def save(self, **data):
-        #if self.context.locked:
-        #    self.emitLockMessage()
-        #    return
         self.applyData(self.context, **data)
         self.context._p_changed = True
@@ -858,7 +809,4 @@
     @grok.action('Final Submit')
     def finalsubmit(self, **data):
-        #if self.context.locked:
-        #    self.emitLockMessage()
-        #    return
         self.applyData(self.context, **data)
         self.context._p_changed = True
@@ -897,7 +845,5 @@
         # A filename chooser turns a context into a filename suitable
         # for file storage.
-        chooser = IFileStoreNameChooser(self.context)
-        file_id = chooser.chooseName()
-        image = getUtility(IExtFileStore).getFile(file_id)
+        image = getUtility(IExtFileStore).getFileByContext(self.context)
         self.response.setHeader(
             'Content-Type', 'image/jpeg')
