web/facet.py
changeset 7249 86bbf174e463
parent 7248 f20fc41e3f7d
child 7279 eb73ce823622
equal deleted inserted replaced
7248:f20fc41e3f7d 7249:86bbf174e463
   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 
   454 class RelationFacet(VocabularyFacet):
   459 class RelationFacet(VocabularyFacet):
   455     """Base facet to filter some entities according to other entities to which
   460     """Base facet to filter some entities according to other entities to which
   456     they are related. Create concret facet by inheriting from this class an then
   461     they are related. Create concret facet by inheriting from this class an then
   457     configuring it by setting class attribute described below.
   462     configuring it by setting class attribute described below.
   458 
   463 
   603                                           self.role, select_target_entity=True)
   608                                           self.role, select_target_entity=True)
   604             else:
   609             else:
   605                 insert_attr_select_relation(
   610                 insert_attr_select_relation(
   606                     rqlst, self.filtered_variable, self.rtype, self.role, self.target_attr,
   611                     rqlst, self.filtered_variable, self.rtype, self.role, self.target_attr,
   607                     select_target_entity=False)
   612                     select_target_entity=False)
   608             values = [str(x) for x, in self.rqlexec(rqlst.as_string())]
   613             encoding = self._cw.encoding
       
   614             values = [encode(x, encoding) for x, in self.rqlexec(rqlst.as_string())]
   609         except:
   615         except:
   610             self.exception('while computing values for %s', self)
   616             self.exception('while computing values for %s', self)
   611             return []
   617             return []
   612         finally:
   618         finally:
   613             rqlst.recover()
   619             rqlst.recover()