web/facet.py
branchtls-sprint
changeset 742 99115e029dca
parent 722 50a99184cf47
child 782 01801a10c567
equal deleted inserted replaced
739:39721e56b56d 742:99115e029dca
    17 from logilab.common.compat import all
    17 from logilab.common.compat import all
    18 
    18 
    19 from rql import parse, nodes
    19 from rql import parse, nodes
    20 
    20 
    21 from cubicweb import Unauthorized, typed_eid
    21 from cubicweb import Unauthorized, typed_eid
       
    22 from cubicweb.vregistry import objectify_selector
    22 from cubicweb.selectors import match_context_prop, one_has_relation
    23 from cubicweb.selectors import match_context_prop, one_has_relation
    23 from cubicweb.appobject import AppRsetObject
    24 from cubicweb.appobject import AppRsetObject
    24 from cubicweb.common.registerers import priority_registerer
    25 from cubicweb.common.registerers import priority_registerer
    25 from cubicweb.web.htmlwidgets import HTMLWidget
    26 from cubicweb.web.htmlwidgets import HTMLWidget
    26 
    27 
   331         except Unauthorized:
   332         except Unauthorized:
   332             return []
   333             return []
   333 
   334 
   334 
   335 
   335 class RelationFacet(VocabularyFacet):
   336 class RelationFacet(VocabularyFacet):
   336     __selectors__ = (one_has_relation, match_context_prop)
   337     # XXX find a way to generalize access to cls.rtype
   337     # class attributes to configure the relation facet
   338     @objectify_selector
       
   339     def my_selector(cls, req, rset, row=None, col=0, **kwargs):
       
   340         selector = (relation_possible(cls.rtype, role(cls))
       
   341                     & match_context_prop())
       
   342         return selector(cls, req, rset, row, col, **kwargs)
       
   343     
       
   344     __select__ = my_selector()
       
   345     # class attributes to configure the rel ation facet
   338     rtype = None
   346     rtype = None
   339     role = 'subject'
   347     role = 'subject' 
   340     target_attr = 'eid'
   348     target_attr = 'eid'
   341     # set this to a stored procedure name if you want to sort on the result of
   349     # set this to a stored procedure name if you want to sort on the result of
   342     # this function's result instead of direct value
   350     # this function's result instead of direct value
   343     sortfunc = None
   351     sortfunc = None
   344     # ascendant/descendant sorting
   352     # ascendant/descendant sorting