cubicweb #933771 RelationField patch proposition [resolved]

RelationField format_single_value method returns eid as int, which is not consistent with other fields, that return unicode, leading to frequent errors when writing "choices" methods for forms : return unicode when not using RelationField, int otherwise...

Applying following patch fixes the problem:

diff -r 7be2e2cb9244 web/formfields.py
--- a/web/formfields.py Thu Apr 15 19:38:24 2010 +0200
+++ b/web/formfields.py Mon May 03 12:58:51 2010 +0200
@@ -748,7 +748,7 @@
     # vocabulary doesn't include current values, add them
     if entity.has_eid():
         rset = entity.related(rtype, role)
-        vocab += [(e.view('combobox'), e.eid) for e in rset.entities()]
+        vocab += [(e.view('combobox'), unicode(e.eid)) for e in rset.entities()]
     return vocab

 def relvoc_unrelated(entity, rtype, role, limit=None):
@@ -779,7 +779,7 @@
         if entity.eid in done:
             continue
         done.add(entity.eid)
-        res.append((entity.view('combobox'), entity.eid))
+        res.append((entity.view('combobox'), unicode(entity.eid)))
     return res


@@ -834,7 +834,7 @@
             form.formvalues[(self, form)] = value

     def format_single_value(self, req, value):
-        return value
+        return unicode(value)

     def process_form_value(self, form):
         """process posted form and return correctly typed value"""
priorityimportant
typebug
done in3.9.0
load0.300
load left0.000
closed by<not specified>