consider __linkto in form_field_display_value tls-sprint
authorsylvain.thenault@logilab.fr
Tue, 12 May 2009 19:20:49 +0200
branchtls-sprint
changeset 1755 1bd225376013
parent 1754 c9c7618a90de
child 1756 42d87dedd631
child 1761 fef5d4b4f511
consider __linkto in form_field_display_value
web/form.py
--- a/web/form.py	Tue May 12 19:20:23 2009 +0200
+++ b/web/form.py	Tue May 12 19:20:49 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):