Author: jmorliaguet
Date: Mon Jun 26 22:03:58 2006
New Revision: 3527

Modified:
   cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py

Log:

- added a submit form handler for locations - not very generic though



Modified: cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py 
(original)
+++ cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py Mon Jun 
26 22:03:58 2006
@@ -20,7 +20,7 @@
 from zope.component import getUtility
 from zope.formlib import form
 from zope.schema import getFields
-from zope.schema.interfaces import IVocabularyFactory
+from zope.schema.interfaces import IVocabularyFactory, IVocabularyTokenized
 
 from cpsskins import minjson as json
 from cpsskins.locations import Location
@@ -152,7 +152,7 @@
                 info[root][location.path] = {
                     'path': location.path,
                     'data': location.data,
-                    'scope': scopes.getTerm(location.scope).token,
+                    'scope': scopes.getTerm(location.scope).title,
                     'object': location,
                 }
         return info
@@ -160,16 +160,16 @@
     def getLocationWidgets(self, path, root):
         locations = self.getLocationInfo()
         location = locations[root][path][u'object']
-        return LocationForm(location, self.request)()
+        return LocationForm(location, self.request).widgets
 
     def submitLocation(self):
         request = self.request
-        form = request.form
-        root = form[u'root']
-        path = form[u'location_path']
+        form_data = request.form
+        root = form_data[u'root']
+        path = form_data[u'location_path']
         locations = getThemeManager(self.context).getLocationStorage()
 
-        action = form[u'action']
+        action = form_data[u'action']
 
         if action == u'delete':
             location = locations.getLocation(root, path)
@@ -181,9 +181,7 @@
 
         elif action == u'edit':
             location = locations.getLocation(root, path)
-            location.path = form[u'form.path']
-            location.data = form[u'form.data']
-            location.scope = form[u'form.scope']
+            LocationForm(location, request).submit(form_data)
 
         self.request.response.setHeader('content-type', 'text/x-json')
         return json.write({'form': {'section': root}})
@@ -192,12 +190,27 @@
     form_fields = form.Fields(ILocation, omit_readonly=True,
                               render_context=True)
 
+    prefix = u'form'
+
     def __init__(self, context, request):
         self.context = context
         self.request = request
 
-    def __call__(self):
-        widgets = form.setUpWidgets(self.form_fields, 'form', self.context,
-                                    self.request)
-        return widgets
+        self.widgets = form.setUpWidgets(self.form_fields, self.prefix,
+                                         context, request)
+
+    def submit(self, data):
+        context = self.context
+        scopes_factory = getUtility(IVocabularyFactory, u'location scopes')
+        scopes = scopes_factory(context)
+        for form_field in self.form_fields:
+            field = form_field.field
+            name = form_field.__name__
+            value = data[u'%s.%s' % (self.prefix, name)]
+            if name == u'scope':
+                value = scopes.getTermByToken(value).value
+                field.validate(value)
+            else:
+                value = field.fromUnicode(value)
+            field.set(context, value)
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to