web/facet.py
branchstable
changeset 7279 eb73ce823622
parent 7249 86bbf174e463
child 7280 571b29842ef1
equal deleted inserted replaced
7270:5a1e9b90b5c4 7279:eb73ce823622
   449 
   449 
   450     def support_and(self):
   450     def support_and(self):
   451         return False
   451         return False
   452 
   452 
   453 
   453 
   454 def encode(obj, encoding):
       
   455     if isinstance(obj, unicode):
       
   456         return obj.encode(encoding)
       
   457     return unicode(obj).encode(encoding)
       
   458 
       
   459 class RelationFacet(VocabularyFacet):
   454 class RelationFacet(VocabularyFacet):
   460     """Base facet to filter some entities according to other entities to which
   455     """Base facet to filter some entities according to other entities to which
   461     they are related. Create concret facet by inheriting from this class an then
   456     they are related. Create concret facet by inheriting from this class an then
   462     configuring it by setting class attribute described below.
   457     configuring it by setting class attribute described below.
   463 
   458 
   608                                           self.role, select_target_entity=True)
   603                                           self.role, select_target_entity=True)
   609             else:
   604             else:
   610                 insert_attr_select_relation(
   605                 insert_attr_select_relation(
   611                     rqlst, self.filtered_variable, self.rtype, self.role, self.target_attr,
   606                     rqlst, self.filtered_variable, self.rtype, self.role, self.target_attr,
   612                     select_target_entity=False)
   607                     select_target_entity=False)
   613             encoding = self._cw.encoding
   608             values = [unicode(x) for x, in self.rqlexec(rqlst.as_string())]
   614             values = [encode(x, encoding) for x, in self.rqlexec(rqlst.as_string())]
       
   615         except:
   609         except:
   616             self.exception('while computing values for %s', self)
   610             self.exception('while computing values for %s', self)
   617             return []
   611             return []
   618         finally:
   612         finally:
   619             rqlst.recover()
   613             rqlst.recover()