[facets] fix unicode encode error; closes #1625112

authorAurelien Campeas <aurelien.campeas@logilab.fr>
changeset86bbf174e463
branchdefault
phasepublic
hiddenno
parent revision#f20fc41e3f7d [facets] fix RangeFacet get_widget: do no return a widget unless there are at least 2 values; closes #1625203
child revision#fe27390bf2f8 [book] fix documentation + add chpasswd.py script
files modified by this revision
web/facet.py
# HG changeset patch
# User Aurelien Campeas <aurelien.campeas@logilab.fr>
# Date 1303482296 -7200
# Fri Apr 22 16:24:56 2011 +0200
# Node ID 86bbf174e463cf27d97b0526d731ac39eae2ede7
# Parent f20fc41e3f7d758c2a76cf626f7cd236a0b6c021
[facets] fix unicode encode error; closes #1625112

diff --git a/web/facet.py b/web/facet.py
@@ -449,10 +449,15 @@
1 
2      def support_and(self):
3          return False
4 
5 
6 +def encode(obj, encoding):
7 +    if isinstance(obj, unicode):
8 +        return obj.encode(encoding)
9 +    return unicode(obj).encode(encoding)
10 +
11  class RelationFacet(VocabularyFacet):
12      """Base facet to filter some entities according to other entities to which
13      they are related. Create concret facet by inheriting from this class an then
14      configuring it by setting class attribute described below.
15 
@@ -603,11 +608,12 @@
16                                            self.role, select_target_entity=True)
17              else:
18                  insert_attr_select_relation(
19                      rqlst, self.filtered_variable, self.rtype, self.role, self.target_attr,
20                      select_target_entity=False)
21 -            values = [str(x) for x, in self.rqlexec(rqlst.as_string())]
22 +            encoding = self._cw.encoding
23 +            values = [encode(x, encoding) for x, in self.rqlexec(rqlst.as_string())]
24          except:
25              self.exception('while computing values for %s', self)
26              return []
27          finally:
28              rqlst.recover()