entity.py
branchtls-sprint
changeset 1008 f54b4309a3f5
parent 985 6a25c58a1c23
child 1031 1a89683cb687
equal deleted inserted replaced
1007:34e92a8d9167 1008:f54b4309a3f5
     7 __docformat__ = "restructuredtext en"
     7 __docformat__ = "restructuredtext en"
     8 
     8 
     9 from logilab.common import interface
     9 from logilab.common import interface
    10 from logilab.common.compat import all
    10 from logilab.common.compat import all
    11 from logilab.common.decorators import cached
    11 from logilab.common.decorators import cached
       
    12 from logilab.common.deprecation import obsolete
    12 from logilab.mtconverter import TransformData, TransformError, html_escape
    13 from logilab.mtconverter import TransformData, TransformError, html_escape
    13 
    14 
    14 from rql.utils import rqlvar_maker
    15 from rql.utils import rqlvar_maker
    15 
    16 
    16 from cubicweb import Unauthorized
    17 from cubicweb import Unauthorized
   786             rql = '%s ORDERBY Z DESC WHERE X modification_date Z, %s' % args
   787             rql = '%s ORDERBY Z DESC WHERE X modification_date Z, %s' % args
   787         return rql
   788         return rql
   788     
   789     
   789     # generic vocabulary methods ##############################################
   790     # generic vocabulary methods ##############################################
   790 
   791 
       
   792     @obsolete('see new form api')
   791     def vocabulary(self, rtype, role='subject', limit=None):
   793     def vocabulary(self, rtype, role='subject', limit=None):
   792         """vocabulary functions must return a list of couples
   794         """vocabulary functions must return a list of couples
   793         (label, eid) that will typically be used to fill the
   795         (label, eid) that will typically be used to fill the
   794         edition view's combobox.
   796         edition view's combobox.
   795         
   797         
   796         If `eid` is None in one of these couples, it should be
   798         If `eid` is None in one of these couples, it should be
   797         interpreted as a separator in case vocabulary results are grouped
   799         interpreted as a separator in case vocabulary results are grouped
   798         """
   800         """
   799         try:
   801         from cubicweb.web.form import EntityFieldsForm
   800             vocabfunc = getattr(self, '%s_%s_vocabulary' % (role, rtype))
   802         from logilab.common.testlib import mock_object
   801         except AttributeError:
   803         form = EntityFieldsForm(self.req, entity=self)
   802             vocabfunc = getattr(self, '%s_relation_vocabulary' % role)
   804         field = mock_object(name=rtype, role=role)
   803         # NOTE: it is the responsibility of `vocabfunc` to sort the result
   805         return form.form_field_vocabulary(field)
   804         #       (direclty through RQL or via a python sort). This is also
       
   805         #       important because `vocabfunc` might return a list with
       
   806         #       couples (label, None) which act as separators. In these
       
   807         #       cases, it doesn't make sense to sort results afterwards.
       
   808         return vocabfunc(rtype, limit)
       
   809             
   806             
   810     def unrelated_rql(self, rtype, targettype, role, ordermethod=None,
   807     def unrelated_rql(self, rtype, targettype, role, ordermethod=None,
   811                       vocabconstraints=True):
   808                       vocabconstraints=True):
   812         """build a rql to fetch `targettype` entities unrelated to this entity
   809         """build a rql to fetch `targettype` entities unrelated to this entity
   813         using (rtype, role) relation
   810         using (rtype, role) relation