Index: /WAeUP_SRP/trunk/Widgets.py
===================================================================
--- /WAeUP_SRP/trunk/Widgets.py	(revision 2109)
+++ /WAeUP_SRP/trunk/Widgets.py	(revision 2110)
@@ -3,4 +3,5 @@
 from cgi import escape
 from types import *
+import Globals
 from Globals import InitializeClass
 from ZPublisher.HTTPRequest import FileUpload
@@ -20,7 +21,8 @@
 from Products.WAeUP_SRP.Academics import makeCertificateCode
 #from Products.ExtFile.ExtFile import ExtFile
-from re import compile
-import logging
+import logging,os,re
 import operator
+p_home = Globals.package_home(globals())
+i_home = Globals.INSTANCE_HOME
 
 #from zLOG import LOG, DEBUG
@@ -489,11 +491,14 @@
         d = {}
         for k,v in voc.items():
-            parts = k.split('_')
-            state = parts[0]
-            lga = ' '.join(parts[1:])
+            parts = v.split(' / ')
+            if len(parts) != 2:
+                continue
+            state = parts[0].lower()
+            lga = "_".join(re.split('\W+',parts[1].lower()))
             if state not in states:
                 states.append(state)
             lgas.append(lga)
             d[k] = v
+
         return (d,states,lgas)
 
@@ -522,5 +527,5 @@
                     return 0
             elif widget_id == self.lga_field:
-                if v not in lgas:
+                if "_".join(re.split('\W+',v)) not in lgas:
                     datastructure.setError(widget_id, "'%s' not a valid lga" % v)
                     return 0
@@ -615,5 +620,5 @@
         valid = CPSStringWidget.validate(self, datastructure, **kw)
         id_pat_str = r"\S"
-        inv_id_pat = compile(r"^%s$" % id_pat_str)
+        inv_id_pat = re.compile(r"^%s$" % id_pat_str)
         if not valid:
             return 0
@@ -666,5 +671,5 @@
         value = makeCertificateCode(datastructure[widget_id]).upper()
         id_pat_str = r"\S"
-        inv_id_pat = compile(r"^%s$" % id_pat_str)
+        inv_id_pat = re.compile(r"^%s$" % id_pat_str)
         err = 0
         if len(value.split()) > 1:
@@ -1134,5 +1139,4 @@
         v = datamodel[self.fields[0]]
         widget_id = self.getWidgetId()
-        #import pdb;pdb.set_trace()
         if v and type(v) is StringType:
             try:
@@ -1476,10 +1480,21 @@
 ###)
 
-class ExtFileWidget(CPSFileWidget): ###(
-    """Photo widget."""
-    meta_type = 'Ext File Widget'
-
-    def getFileInfo(self, datastructure): ###(
+class NoZodbImageWidget(CPSImageWidget): ###(
+    """Image widget with filesystem storage."""
+    meta_type = 'No Zodb Image Widget'
+    _properties = CPSImageWidget._properties +\
+    (
+     {'id': 'path', 'type': 'string', 'mode': 'w',
+      'label': 'Relative Path'},
+     {'id': 'id_field', 'type': 'string', 'mode': 'w',
+      'label': 'Field to build the id'},
+    )
+    path = "images"
+    storage_path = "%s/var/%s" % (i_home,path)
+    id_field = "reg_no"
+
+    def getImageInfo(self, datastructure): ###(
         """Get the file info from the datastructure."""
+        import pdb; pdb.set_trace()
         widget_id = self.getWidgetId()
         fileupload = datastructure[widget_id]
@@ -1487,5 +1502,4 @@
         field_id = self.fields[0]
         if fileupload:
-            import pdb; pdb.set_trace()
             empty_file = False
             session_file = isinstance(fileupload, PersistableFileUpload)
@@ -1506,6 +1520,4 @@
             last_modified = ''
 
-        # Find the URL for the file  XXX Refactor this!
-
         # get the adapter
         for adapter in dm._adapters:
@@ -1515,41 +1527,10 @@
             raise ValueError('No schema for field %r' % field_id)
 
-        # get the content_url from the adapter
         content_url = None
-        ob = dm.getProxy()
-        if ob is None:
-            # non proxy case
-            ob = dm.getObject()
-        if ob is None:
-            # Not stored in the ZODB.
-            # StorageAdapters that do not store the object in
-            # ZODB takes the entry_id instead of object.
-            # Get the entry_id from the datamodel context(typically
-            # a directory).
-            id_field = getattr(dm.getContext(), 'id_field', None)
-            if id_field:
-                try:
-                    entry_id = datastructure[id_field]
-                except KeyError:
-                    entry_id = None
-            else:
-                # No object passed, and no id_field
-                entry_id = None
-            if entry_id:
-                # some adapters does not have _getContentUrl
-                if getattr(adapter, '_getContentUrl', None) is not None:
-                    content_url = adapter._getContentUrl(entry_id, field_id)
-        else:
-            if hasattr(adapter,"_getContentUrl"):
-                content_url = adapter._getContentUrl(ob, field_id,
-                                                 current_filename)
-            else:
-                content_url = None
-        # get the mimetype
         registry = getToolByName(self, 'mimetypes_registry')
         mimetype = (registry.lookupExtension(current_filename.lower()) or
                     registry.lookupExtension('file.bin'))
 
-        file_info = {
+        image_info = {
             'empty_file': empty_file,
             'session_file': session_file,
@@ -1560,6 +1541,55 @@
             'mimetype': mimetype,
             }
-
-        return file_info
+        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() 
+            from OFS.Image import getImageInfo
+            image.seek(0)
+            data = image.read(24)
+            ct, width, height = getImageInfo(data)
+            if width < 0:
+                width = None
+            if height < 0:
+                height = None
+
+            if (self.allow_resize
+                and height is not None
+                and width  is not None):
+                z_w = z_h = 1
+                h = int(self.display_height)
+                w = int(self.display_width)
+                if w and h:
+                    if w < width:
+                        z_w = w / float(width)
+                    if h < height:
+                        z_h = h / float(height)
+                    zoom = min(z_w, z_h)
+                    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['height'] = height
+        image_info['width'] = width
+        image_info['image_tag'] = tag
+        return image_info
     ###)
 
@@ -1572,11 +1602,6 @@
             file = None
         else:
-            io = ExtFile(file)
-            if filename is None:
-                filename = ofsfile.title
-            headers = {'content-type': ofsfile.content_type}
-            fs = SimpleFieldStorage(io, filename, headers)
-            FileUpload(fs)
-        datastructure[widget_id] = file
+            import pdb; pdb.set_trace()
+        datastructure[widget_id] = file_name
         datastructure[widget_id + '_choice'] = ''
         if file is not None:
@@ -1657,38 +1682,31 @@
             filename = datamodel[field_id].title
 
+        import pdb;pdb.set_trace()
         # Set/update data
-        import pdb;pdb.set_trace()
+        file_path = "/%s/%s_%s.jpg" % (storage_path,
+                                       datamodel[self.id_field],
+                                       self.field_id,)
         if store:
-            # Create file
-            #file = ExtFile(filename, fileupload, datastructure)
-            table_store = False
-            if not hasattr(datamodel._adapters[0],'_getContentUrl'):
-                table_store = True
-                ref_id = datamodel.get('reg_no')
-                id = "%s_%s" % (ref_id,field_id)
-            self.tempExtFile = ExtFile(id, field_id)
-            if table_store:
-                datastructure[widget_id] = self.tempExtFile
-                self.tempExtFile.manage_file_upload(fileupload,content_type=mimetype)
-            else:
-                self._setObject(id, self.tempExtFile)
-                self._getOb(id).manage_file_upload(fileupload, content_type)
+            file = self.makeFile(filename, fileupload, datastructure)
             # Fixup mimetype
-            if mimetype and self.tempExtFile.content_type != mimetype:
-                self.tempExtFile.content_type = mimetype
-            # Store
-            if not table_store:
-                datamodel[field_id] = file
-        elif datamodel[field_id] is not None:
-            # Change filename
-            if datamodel[field_id].title != filename:
-                datamodel[field_id].title = filename
+            if mimetype and file.content_type != mimetype:
+                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
+
 
         return True
 
 
-InitializeClass(ExtFileWidget)
-
-widgetRegistry.register(ExtFileWidget)
+InitializeClass(NoZodbImageWidget)
+
+widgetRegistry.register(NoZodbImageWidget)
 ###)
 
