entity.py
branchtls-sprint
changeset 1008 f54b4309a3f5
parent 985 6a25c58a1c23
child 1031 1a89683cb687
--- a/entity.py	Wed Mar 04 17:27:01 2009 +0100
+++ b/entity.py	Wed Mar 04 17:27:21 2009 +0100
@@ -9,6 +9,7 @@
 from logilab.common import interface
 from logilab.common.compat import all
 from logilab.common.decorators import cached
+from logilab.common.deprecation import obsolete
 from logilab.mtconverter import TransformData, TransformError, html_escape
 
 from rql.utils import rqlvar_maker
@@ -788,6 +789,7 @@
     
     # generic vocabulary methods ##############################################
 
+    @obsolete('see new form api')
     def vocabulary(self, rtype, role='subject', limit=None):
         """vocabulary functions must return a list of couples
         (label, eid) that will typically be used to fill the
@@ -796,16 +798,11 @@
         If `eid` is None in one of these couples, it should be
         interpreted as a separator in case vocabulary results are grouped
         """
-        try:
-            vocabfunc = getattr(self, '%s_%s_vocabulary' % (role, rtype))
-        except AttributeError:
-            vocabfunc = getattr(self, '%s_relation_vocabulary' % role)
-        # NOTE: it is the responsibility of `vocabfunc` to sort the result
-        #       (direclty through RQL or via a python sort). This is also
-        #       important because `vocabfunc` might return a list with
-        #       couples (label, None) which act as separators. In these
-        #       cases, it doesn't make sense to sort results afterwards.
-        return vocabfunc(rtype, limit)
+        from cubicweb.web.form import EntityFieldsForm
+        from logilab.common.testlib import mock_object
+        form = EntityFieldsForm(self.req, entity=self)
+        field = mock_object(name=rtype, role=role)
+        return form.form_field_vocabulary(field)
             
     def unrelated_rql(self, rtype, targettype, role, ordermethod=None,
                       vocabconstraints=True):