[forms/widgets] fix relation field not sorting its vocabulary, revert hack on Select widget tls-sprint
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Wed, 29 Apr 2009 19:52:56 +0200
branchtls-sprint
changeset 1562 e6d2c07c0c58
parent 1561 85752d14c15d
child 1563 b130c6cec8c2
[forms/widgets] fix relation field not sorting its vocabulary, revert hack on Select widget
web/formfields.py
web/formwidgets.py
--- a/web/formfields.py	Wed Apr 29 19:51:10 2009 +0200
+++ b/web/formfields.py	Wed Apr 29 19:52:56 2009 +0200
@@ -94,9 +94,9 @@
         Field.__creation_rank += 1
 
     def __unicode__(self):
-        return u'<%s name=%r label=%r id=%r initial=%r @%x>' % (
+        return u'<%s name=%r label=%r id=%r initial=%r visible=%r @%x>' % (
             self.__class__.__name__, self.name, self.label,
-            self.id, self.initial, id(self))
+            self.id, self.initial, self.is_visible(), id(self))
 
     def __repr__(self):
         return self.__unicode__().encode('utf-8')
@@ -407,7 +407,10 @@
             relatedvocab = [(e.view('combobox'), e.eid) for e in rset.entities()]
         else:
             relatedvocab = []
-        return res + form.form_field_vocabulary(self) + relatedvocab
+        vocab = res + form.form_field_vocabulary(self) + relatedvocab
+        if self.sort:
+            vocab = sorted(vocab)
+        return vocab
 
     def format_single_value(self, req, value):
         return value
--- a/web/formwidgets.py	Wed Apr 29 19:51:10 2009 +0200
+++ b/web/formwidgets.py	Wed Apr 29 19:52:56 2009 +0200
@@ -159,20 +159,16 @@
 
 class Select(FieldWidget):
     """<select>, for field having a specific vocabulary"""
-    def __init__(self, attrs=None, multiple=False, sort=False):
+    def __init__(self, attrs=None, multiple=False):
         super(Select, self).__init__(attrs)
         self._multiple = multiple
-        self._sort = sort
 
     def render(self, form, field):
         name, curvalues, attrs = self._render_attrs(form, field)
         if not 'size' in attrs and self._multiple:
             attrs['size'] = '5'
         options = []
-        vocab = field.vocabulary(form)
-        if self._sort:
-            vocab = sorted(vocab)
-        for label, value in vocab:
+        for label, value in field.vocabulary(form):
             if value is None:
                 # handle separator
                 options.append(u'<optgroup label="%s"/>' % (label or ''))