Index: /WAeUP_SRP/trunk/WAeUPTool.py
===================================================================
--- /WAeUP_SRP/trunk/WAeUPTool.py	(revision 2113)
+++ /WAeUP_SRP/trunk/WAeUPTool.py	(revision 2114)
@@ -684,4 +684,13 @@
     ###)
 
+    security.declarePublic('showFsPicture') ###(
+    def showFsPicture(self,path):
+        """return a picture from the filesystem"""
+        picture_path = "%s/var/%s" % (i_home,path)
+        if os.path.exists(picture_path):
+            return open(picture_path).read()
+        
+    ###)
+
     security.declareProtected(ModifyPortalContent,'deleteAllCourses') ###(
     def deleteAllCourses(self,department="All"):
Index: /WAeUP_SRP/trunk/Widgets.py
===================================================================
--- /WAeUP_SRP/trunk/Widgets.py	(revision 2113)
+++ /WAeUP_SRP/trunk/Widgets.py	(revision 2114)
@@ -1496,22 +1496,60 @@
     def getImageInfo(self, datastructure): ###(
         """Get the file info from the datastructure."""
-        import pdb; pdb.set_trace()
+        #import pdb; pdb.set_trace()
         widget_id = self.getWidgetId()
         fileupload = datastructure[widget_id]
         dm = datastructure.getDataModel()
         field_id = self.fields[0]
-        if fileupload:
-            empty_file = False
-            session_file = isinstance(fileupload, PersistableFileUpload)
-            current_filename = generateFileName(fileupload.filename)
-            fileupload.seek(0, 2) # end of file
-            size = fileupload.tell()
-            fileupload.seek(0)
-            file = dm[field_id] # last stored file
-            if file is not None:
-                last_modified = str(file._p_mtime or '')
-            else:
-                last_modified = ''
-        else:
+        # if isinstance(fileupload, PersistableFileUpload):
+        #     empty_file = False
+        #     session_file = isinstance(fileupload, PersistableFileUpload)
+        #     current_filename = generateFileName(fileupload.filename)
+        #     fileupload.seek(0, 2) # end of file
+        #     size = fileupload.tell()
+        #     fileupload.seek(0)
+        #     last_modified = ''
+        # else:
+        #     empty_file = True
+        #     session_file = False
+        #     current_filename = ''
+        #     size = 0
+        #     last_modified = ''
+        # get the adapter
+        # for adapter in dm._adapters:
+        #     if adapter.getSchema().has_key(field_id):
+        #         break # Note: 'adapter' is still the right one
+        # else:
+        #     raise ValueError('No schema for field %r' % field_id)
+
+        content_url = "/uniben/viewimage?path=%s/%s_%s.jpg" %\
+                                 (self.path,
+                                  datastructure[self.id_field],
+                                  self.getWidgetId(),
+                                  )
+        # registry = getToolByName(self, 'mimetypes_registry')
+        # mimetype = (registry.lookupExtension(current_filename.lower()) or
+        #             registry.lookupExtension('file.bin'))
+
+        # image_info = {
+        #     'empty_file': empty_file,
+        #     'session_file': session_file,
+        #     'current_filename': current_filename,
+        #     'size': size,
+        #     'last_modified': last_modified,
+        #     'content_url': content_url,
+        #     'mimetype': mimetype,
+        #     }
+        # if image_info['empty_file']:
+        #     tag = ''
+        #     height = 0
+        #     width = 0
+        # else:
+        current_filename = "%s_%s.jpg" % (datastructure[self.id_field],
+                                          field_id,)
+        file_path = "/%s/%s" % (self.storage_path,
+                                      current_filename)
+        
+        # read the file from the filesystem
+        if not os.path.exists(file_path):
             empty_file = True
             session_file = False
@@ -1519,48 +1557,20 @@
             size = 0
             last_modified = ''
-
-        # get the adapter
-        for adapter in dm._adapters:
-            if adapter.getSchema().has_key(field_id):
-                break # Note: 'adapter' is still the right one
-        else:
-            raise ValueError('No schema for field %r' % field_id)
-
-        content_url = None
-        registry = getToolByName(self, 'mimetypes_registry')
-        mimetype = (registry.lookupExtension(current_filename.lower()) or
-                    registry.lookupExtension('file.bin'))
-
-        image_info = {
-            'empty_file': empty_file,
-            'session_file': session_file,
-            'current_filename': current_filename,
-            'size': size,
-            'last_modified': last_modified,
-            'content_url': content_url,
-            'mimetype': mimetype,
-            }
-        if image_info['empty_file']:
-            tag = ''
-            height = 0
-            width = 0
-        else:
-            file_path = "/%s/%s_%s.jpg" % (self.storage_path,
-                                           datamodel[self.id_field],
-                                           self.field_id,)
-            # read the file from the filesystem
-            if not os.path.exists(file_path):
-                image = None
-            else:
-                image = open(file_path).read() 
+        else:
+            image = open(file_path)
             from OFS.Image import getImageInfo
             image.seek(0)
             data = image.read(24)
-            ct, width, height = getImageInfo(data)
+            size = len(data)
+            empty_file = size == 0
+            session_file = False
+            last_modified = ''
+            image.close()
+            mimetype, width, height = getImageInfo(data)
             if width < 0:
                 width = None
             if height < 0:
                 height = None
-
+    
             if (self.allow_resize
                 and height is not None
@@ -1577,14 +1587,24 @@
                     width = int(zoom * width)
                     height = int(zoom * height)
-
-            title = image_info['current_filename']
-            alt = title or ''
-            if height is None or width is None:
-                tag = renderHtmlTag('img', src=image_info['content_url'],
-                                    alt=alt, title=title)
-            else:
-                tag = renderHtmlTag('img', src=image_info['content_url'],
-                                    width=str(width), height=str(height),
-                                    alt=alt, title=title)
+        image_info = {
+            'empty_file': empty_file,
+            'session_file': session_file,
+            'current_filename': current_filename,
+            'size': size,
+            'last_modified': last_modified,
+            'content_url': content_url,
+            'mimetype': mimetype,
+            }
+        title = image_info['current_filename']
+        alt = title or ''
+        height = int(self.display_height)
+        width = int(self.display_width)
+        if height is None or width is None:
+            tag = renderHtmlTag('img', src=image_info['content_url'],
+                                alt=alt, title=title)
+        else:
+            tag = renderHtmlTag('img', src=image_info['content_url'],
+                                width=str(width), height=str(height),
+                                alt=alt, title=title)
 
         image_info['height'] = height
@@ -1594,4 +1614,22 @@
     ###)
 
+    # def getFileName(self, fileupload, datastructure, choice, old_filename=''):
+    #     #filename = datastructure[self.getWidgetId()+'_filename'].strip()
+    #     ext ='jpg'
+    #     filename = "%s_%s.%s" % (datastructure[self.id_field],
+    #                              self.getWidgetId(),
+    #                              ext)
+    #     if choice == 'change' and filename == old_filename:
+    #         # if upload with input field unchanged, use fileupload filename
+    #         filename = cookId('', '', fileupload)[0].strip()
+    #     #filename = cleanFileName(filename or 'file.bin')
+    #     return filename
+
+    def checkFileName(self, filename, mimetype):
+        return '', {}
+        if mimetype and mimetype.startswith('image'):
+            return '', {}
+        return 'cpsschemas_err_image', {}
+
     def prepare(self, datastructure, **kw): ###(
         """Prepare datastructure from datamodel."""
@@ -1599,33 +1637,30 @@
         widget_id = self.getWidgetId()
         file_name = datamodel[self.fields[0]]
-        if not file_name:
-            file = None
-        else:
-            import pdb; pdb.set_trace()
         datastructure[widget_id] = file_name
-        datastructure[widget_id + '_choice'] = ''
-        if file is not None:
-            title = file.title
-        else:
-            title = ''
+        datastructure[widget_id + '_choice'] = 'change'
+        title = 'Passport Foto'
         datastructure[widget_id + '_filename'] = title
     ###)
 
-    def validate(self, datastructure, **kw):
+    def validate(self, datastructure, **kw): ###(
         """Update datamodel from user data in datastructure.
         """
+        #import pdb; pdb.set_trace()
         datamodel = datastructure.getDataModel()
         field_id = self.fields[0]
         widget_id = self.getWidgetId()
-        choice = datastructure[widget_id+'_choice']
         store = False
         fileupload = None
         mimetype = None
         old_file = datamodel[field_id]
-        if old_file is not None:
-            old_filename = old_file.title
-        else:
-            old_filename = ''
-
+        # if old_file is not None:
+        #     old_filename = old_file.title
+        # else:
+        #     old_filename = ''
+        choice = datastructure[widget_id+'_choice']
+        fileupload = datastructure[widget_id]
+        is_upload = isinstance(fileupload, FileUpload)
+        if not is_upload:
+            return True
         if choice == 'delete':
             if self.is_required:
@@ -1639,11 +1674,10 @@
                 # actually want to store it.
                 store = True
-            else:
-                # Nothing to change, don't pollute datastructure
-                # with something costly already stored, which therefore
-                # doesn't need to be kept in the session.
-                self.unprepare(datastructure)
-        elif choice == 'change':
-            fileupload = datastructure[widget_id]
+            # else:
+            #     # Nothing to change, don't pollute datastructure
+            #     # with something costly already stored, which therefore
+            #     # doesn't need to be kept in the session.
+            #     self.unprepare(datastructure)
+        elif choice == 'change' and is_upload:
             if not fileupload:
                 return self.validateError('cpsschemas_err_file_empty', {},
@@ -1667,25 +1701,19 @@
 
         # Find filename
-        if fileupload is not None:
-            filename = self.getFileName(fileupload, datastructure, choice,
-                                        old_filename)
-            if filename != old_filename:
-                registry = getToolByName(self, 'mimetypes_registry')
-                mimetype = registry.lookupExtension(filename.lower())
-                if mimetype is not None:
-                    mimetype = str(mimetype) # normalize
-                err, err_mapping = self.checkFileName(filename, mimetype)
-                if err:
-                    return self.validateError(err, err_mapping, datastructure)
-        elif datamodel[field_id] is not None:
-            # FIXME: not correct in the case of change=='resize' (CPSPhotoWidget)
-            filename = datamodel[field_id].title
-
-        import pdb;pdb.set_trace()
-        # Set/update data
-        file_path = "/%s/%s_%s.jpg" % (storage_path,
-                                       datamodel[self.id_field],
-                                       self.field_id,)
+        if is_upload:
+            ext ='jpg'
+            filename = "%s_%s.%s" % (datastructure[self.id_field],
+                                 self.getWidgetId(),
+                                 ext)
+            registry = getToolByName(self, 'mimetypes_registry')
+            mimetype = registry.lookupExtension(filename.lower())
+            if mimetype is not None:
+                mimetype = str(mimetype) # normalize
+
         if store:
+            # Set/update data
+            file_path = "%s_%s.jpg" % (datamodel[self.id_field],
+                                       field_id,)
+            full_path = "%s/%s" % (self.storage_path, file_path)
             file = self.makeFile(filename, fileupload, datastructure)
             # Fixup mimetype
@@ -1693,16 +1721,26 @@
                 file.content_type = mimetype
             # Store the file in the filesystem
-            if not os.path.exists(storage_path):
-                os.mkdir(storage_path) 
-            open(file_path,"w").write(file)
-            datamodel[field_id] = file_path
-        # elif datamodel[field_id] is not None:
-        #     # Change filename
-        #     if datamodel[field_id].title != filename:
-        #         datamodel[field_id].title = filename
+            if not os.path.exists(self.storage_path):
+                os.mkdir(self.storage_path) 
+            #import pdb;pdb.set_trace()
+            pict = open(full_path,"w")
+            fileupload.seek(0)
+            pict.write(fileupload.read())
+            pict.close()
 
 
         return True
 
+###)
+
+    def render(self, mode, datastructure, **kw): ###(
+        render_method = 'widget_passport_render'
+        meth = getattr(self, render_method, None)
+        if meth is None:
+            raise RuntimeError("Unknown Render Method %s for widget type %s"
+                               % (render_method, self.getId()))
+        img_info = self.getImageInfo(datastructure)
+        return meth(mode=mode, datastructure=datastructure, **img_info)
+    ###)
 
 InitializeClass(NoZodbImageWidget)
Index: /WAeUP_SRP/trunk/skins/waeup_default/widget_passport_render.pt
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_default/widget_passport_render.pt	(revision 2114)
+++ /WAeUP_SRP/trunk/skins/waeup_default/widget_passport_render.pt	(revision 2114)
@@ -0,0 +1,49 @@
+<tal:block define="mode options/mode;
+  id here/getWidgetId;
+  fields here/fields;
+  current_filename options/current_filename;
+  empty_file options/empty_file;
+  session_file options/session_file;
+  mimetype options/mimetype;
+  size options/size;
+  content_url options/content_url;
+  last_modified options/last_modified;
+  image_width options/width;
+  image_height options/height;
+  image_tag options/image_tag;"
+  >
+  <span tal:condition="python:0" >
+    <img tal:condition="python: mode == 'view' and not empty_file"
+         tal:replace="structure image_tag" />
+  </span>
+  <span tal:condition="python: mode == 'view' and not empty_file">
+    <img tal:condition="python:not empty_file and not session_file"
+         tal:replace="structure image_tag" />
+  </span>
+  <tal:block condition="python: mode == 'edit'">
+    <metal:block use-macro="here/widget_file_render/macros/file_size_max_view" />
+    <metal:block define-macro="image_title_edit">
+      <span tal:condition="python:0">
+        <metal:block use-macro="here/widget_file_render/macros/file_title_edit">
+        </metal:block>
+      </span>
+    </metal:block>
+    <img tal:condition="python:not empty_file and not session_file"
+         tal:replace="structure image_tag" />
+    <metal:block define-macro="image_edit">
+      <metal:block use-macro="here/widget_file_render/macros/file_edit">
+        <metal:block fill-slot="keep_file" />
+        <metal:block fill-slot="change_file">
+          <input type="file" name="." size="24"
+                 tal:attributes="name name;
+                 onclick string:document.getElementById('${radio_name}_change').checked='checked'" 
+                 />
+          <tal:block condition="python:1">
+            <input type="hidden" value="img_auto_size" 
+                   tal:attributes="name string:${name}_resize" />
+          </tal:block>
+        </metal:block>
+      </metal:block>
+    </metal:block>
+  </tal:block>
+</tal:block>
Index: /WAeUP_SRP/trunk/skins/waeup_student/apply_pume.py
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_student/apply_pume.py	(revision 2113)
+++ /WAeUP_SRP/trunk/skins/waeup_student/apply_pume.py	(revision 2114)
@@ -50,12 +50,12 @@
         for field in context.applicants_catalog.schema():
             object[field] = getattr(brains[0],field,None)
+        if not object['passport']:
+            object['passport'] = ''
         if object['status'] == "submitted":
             submitted = True
-        #set_trace()
         if not create and pin != object['pin']:
             return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
 if slip:
     mode = "view_slip"
-
 res,psm,ds = lt.renderLayout(layout_id= 'application',
                              schema_id= 'application',
@@ -91,11 +91,11 @@
     pass
 data = {}
+dm = ds.getDataModel()
+#set_trace()
 for field in context.applicants_catalog.schema():
-    if ds.has_key(field) and request.has_key("widget__%s" % field):
-        data[field] = ds.get(field)
+    if dm.has_key("%s" % field):
+        data[field] = dm.get(field)
 data['reg_no'] = reg_no
-
 if apply_pume:
-
     if submitted:
         mode = "view"
@@ -143,4 +143,5 @@
                                 )
 elif edit:
+    #set_trace()
     if submitted:
         mode = "view"
Index: /WAeUP_SRP/trunk/skins/waeup_student/apply_pume_form.pt
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_student/apply_pume_form.pt	(revision 2113)
+++ /WAeUP_SRP/trunk/skins/waeup_student/apply_pume_form.pt	(revision 2114)
@@ -12,4 +12,5 @@
         <h3 tal:condition="python:mode=='view'">Your PUME Application Record</h3>
         <br />
+        <img tal:condition="python:0" src="/uniben/viewimage?path=images/72921580DJ_passport.jpg" alt="" title="image/jpeg" />
         <form action="" id="editForm" method="post" 
               enctype="multipart/form-data" class="workflow"
Index: /WAeUP_SRP/trunk/skins/waeup_utilities/viewimage.py
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_utilities/viewimage.py	(revision 2114)
+++ /WAeUP_SRP/trunk/skins/waeup_utilities/viewimage.py	(revision 2114)
@@ -0,0 +1,20 @@
+## Script (Python) "viewimage"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=path
+##title=
+##
+# $Id$
+"""
+"""
+try:
+    from Products.zdb import set_trace
+except:
+    def set_trace():
+        pass
+return context.waeup_tool.showFsPicture(path)
+#import logging
+#logger = logging.getLogger('Skins.viewimage')
