web/facet.py
branchstable
changeset 5006 871269e5e020
parent 4719 aaed3f813ef8
child 5016 b3b0b808a0ed
child 5225 9ff0dee81eb2
equal deleted inserted replaced
5005:b04ec1b6f7da 5006:871269e5e020
   336             return []
   336             return []
   337 
   337 
   338 
   338 
   339 class RelationFacet(VocabularyFacet):
   339 class RelationFacet(VocabularyFacet):
   340     __select__ = partial_relation_possible() & match_context_prop()
   340     __select__ = partial_relation_possible() & match_context_prop()
   341     # class attributes to configure the rel ation facet
   341     # class attributes to configure the relation facet
   342     rtype = None
   342     rtype = None
   343     role = 'subject'
   343     role = 'subject'
   344     target_attr = 'eid'
   344     target_attr = 'eid'
       
   345     target_type = None
   345     # set this to a stored procedure name if you want to sort on the result of
   346     # set this to a stored procedure name if you want to sort on the result of
   346     # this function's result instead of direct value
   347     # this function's result instead of direct value
   347     sortfunc = None
   348     sortfunc = None
   348     # ascendant/descendant sorting
   349     # ascendant/descendant sorting
   349     sortasc = True
   350     sortasc = True
   363             sort = None # will be sorted on label
   364             sort = None # will be sorted on label
   364         else:
   365         else:
   365             sort = self.sortasc
   366             sort = self.sortasc
   366         try:
   367         try:
   367             mainvar = self.filtered_variable
   368             mainvar = self.filtered_variable
   368             insert_attr_select_relation(rqlst, mainvar, self.rtype, self.role,
   369             var = insert_attr_select_relation(
   369                                         self.target_attr, self.sortfunc, sort)
   370                 rqlst, mainvar, self.rtype, self.role, self.target_attr,
       
   371                 self.sortfunc, sort)
       
   372             if self.target_type is not None:
       
   373                 rqlst.add_type_restriction(var, self.target_type)
   370             try:
   374             try:
   371                 rset = self.rqlexec(rqlst.as_string(), self.cw_rset.args, self.cw_rset.cachekey)
   375                 rset = self.rqlexec(rqlst.as_string(), self.cw_rset.args, self.cw_rset.cachekey)
   372             except:
   376             except:
   373                 self.exception('error while getting vocabulary for %s, rql: %s',
   377                 self.exception('error while getting vocabulary for %s, rql: %s',
   374                                self, rqlst.as_string())
   378                                self, rqlst.as_string())