merge tls-sprint
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Tue, 12 May 2009 19:21:42 +0200
branchtls-sprint
changeset 1761 fef5d4b4f511
parent 1760 6b97d286eb5a (current diff)
parent 1755 1bd225376013 (diff)
child 1762 1f7bb0cd950c
merge
--- a/entity.py	Tue May 12 19:17:54 2009 +0200
+++ b/entity.py	Tue May 12 19:21:42 2009 +0200
@@ -130,8 +130,8 @@
                         wdgname = 'TextInput'
                     widget = getattr(formwidgets, wdgname)
                     assert hasattr(widget, 'render')
-                    uicfg.autoform_widget.tag_subject_of((etype, rtype, '*'),
-                                                         widget)
+                    uicfg.autoform_field_kwargs.tag_subject_of(
+                        (etype, rtype, '*'), {'widget': widget})
         return super(_metaentity, mcs).__new__(mcs, name, bases, classdict)
 
 
--- a/web/form.py	Tue May 12 19:17:54 2009 +0200
+++ b/web/form.py	Tue May 12 19:21:42 2009 +0200
@@ -361,12 +361,8 @@
         values found in 1. and 2. are expected te be already some 'display'
         value while those found in 3. and 4. are expected to be correctly typed.
         """
-        qname = self.form_field_name(field)
-        if qname in self.form_previous_values:
-            value = self.form_previous_values[qname]
-        elif qname in self.req.form:
-            value = self.req.form[qname]
-        else:
+        value = self._req_display_value(field)
+        if value is None:
             if field.name in rendervalues:
                 value = rendervalues[field.name]
             else:
@@ -377,6 +373,14 @@
                 value = field.format_value(self.req, value)
         return value
 
+    def _req_display_value(self, field):
+        qname = self.form_field_name(field)
+        if qname in self.form_previous_values:
+            return self.form_previous_values[qname]
+        if qname in self.req.form:
+            return self.req.form[qname]
+        return None
+
     def form_field_value(self, field, load_bytes=False):
         """return field's *typed* value"""
         value = field.initial
@@ -465,6 +469,12 @@
             res.append((entity.view('combobox'), entity.eid))
         return res
 
+    def _req_display_value(self, field):
+        value = super(EntityFieldsForm, self)._req_display_value(field)
+        if value is None:
+            value = self.edited_entity.linked_to(field.name, field.role) or None
+        return value
+
     def _form_field_default_value(self, field, load_bytes):
         defaultattr = 'default_%s' % field.name
         if hasattr(self.edited_entity, defaultattr):
--- a/web/uicfg.py	Tue May 12 19:17:54 2009 +0200
+++ b/web/uicfg.py	Tue May 12 19:21:42 2009 +0200
@@ -217,11 +217,12 @@
 # relations'field class
 autoform_field = RelationTags()
 
-# relations'widget class
-autoform_widget = RelationTags()
-autoform_widget.tag_attribute(('RQLExpression', 'expression'),
-                              formwidgets.TextInput)
-autoform_widget.tag_attribute(('Bookmark', 'path'), formwidgets.TextInput)
+# relations'field explicit kwargs (given to field's __init__)
+autoform_field_kwargs = RelationTags()
+autoform_field_kwargs.tag_attribute(('RQLExpression', 'expression'),
+                                    {'widget': formwidgets.TextInput})
+autoform_field_kwargs.tag_attribute(('Bookmark', 'path'),
+                                    {'widget': formwidgets.TextInput})
 
 
 
--- a/web/views/autoform.py	Tue May 12 19:17:54 2009 +0200
+++ b/web/views/autoform.py	Tue May 12 19:21:42 2009 +0200
@@ -40,7 +40,7 @@
     # don't want them to be reloaded
     rcategories = uicfg.autoform_section
     rfields = uicfg.autoform_field
-    rwidgets = uicfg.autoform_widget
+    rfields_kwargs = uicfg.autoform_field_kwargs
     rinlined = uicfg.autoform_is_inlined
     rpermissions_overrides = uicfg.autoform_permissions_overrides
 
@@ -139,10 +139,10 @@
             fieldcls = cls_or_self.rfields.etype_get(eschema, rschema, role, tschemas[0])
             if fieldcls:
                 return fieldcls(name=name, role=role, eidparam=True)
-            widget = cls_or_self.rwidgets.etype_get(eschema, rschema, role, tschemas[0])
-            if widget:
+            kwargs = cls_or_self.rfields_kwargs.etype_get(eschema, rschema, role, tschemas[0])
+            if kwargs:
                 field = guess_field(eschema, rschema, role,
-                                    eidparam=True, widget=widget)
+                                    eidparam=True, **kwargs)
             else:
                 field = guess_field(eschema, rschema, role, eidparam=True)
             if field is None: