1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
57 from logilab.common.graph import has_path |
57 from logilab.common.graph import has_path |
58 from logilab.common.decorators import cached, cachedproperty |
58 from logilab.common.decorators import cached, cachedproperty |
59 from logilab.common.date import datetime2ticks, ustrftime, ticks2datetime |
59 from logilab.common.date import datetime2ticks, ustrftime, ticks2datetime |
60 from logilab.common.compat import all |
60 from logilab.common.compat import all |
61 from logilab.common.deprecation import deprecated |
61 from logilab.common.deprecation import deprecated |
|
62 from logilab.common.registry import yes |
62 |
63 |
63 from rql import nodes, utils |
64 from rql import nodes, utils |
64 |
65 |
65 from cubicweb import Unauthorized, typed_eid |
66 from cubicweb import Unauthorized, typed_eid |
66 from cubicweb.schema import display_name |
67 from cubicweb.schema import display_name |
67 from cubicweb.uilib import css_em_num_value |
68 from cubicweb.uilib import css_em_num_value |
68 from cubicweb.utils import make_uid |
69 from cubicweb.utils import make_uid |
69 from cubicweb.selectors import match_context_prop, partial_relation_possible, yes |
70 from cubicweb.predicates import match_context_prop, partial_relation_possible |
70 from cubicweb.appobject import AppObject |
71 from cubicweb.appobject import AppObject |
71 from cubicweb.web import RequestError, htmlwidgets |
72 from cubicweb.web import RequestError, htmlwidgets |
72 |
73 |
73 |
74 |
74 def rtype_facet_title(facet): |
75 def rtype_facet_title(facet): |
1385 value = self._cw.form.get(self.__regid__) |
1386 value = self._cw.form.get(self.__regid__) |
1386 if not value: |
1387 if not value: |
1387 return |
1388 return |
1388 if isinstance(value, list): |
1389 if isinstance(value, list): |
1389 value = reduce(lambda x, y: int(x) | int(y), value) |
1390 value = reduce(lambda x, y: int(x) | int(y), value) |
|
1391 else: |
|
1392 value = int(value) |
1390 attr_var = self.select.make_variable() |
1393 attr_var = self.select.make_variable() |
1391 self.select.add_relation(self.filtered_variable, self.rtype, attr_var) |
1394 self.select.add_relation(self.filtered_variable, self.rtype, attr_var) |
1392 comp = nodes.Comparison('=', nodes.Constant(value, 'Int')) |
1395 comp = nodes.Comparison('=', nodes.Constant(value, 'Int')) |
1393 comp.append(nodes.MathExpression('&', nodes.variable_ref(attr_var), |
1396 if value == 0: |
1394 nodes.Constant(value, 'Int'))) |
1397 comp.append(nodes.variable_ref(attr_var)) |
|
1398 else: |
|
1399 comp.append(nodes.MathExpression('&', nodes.variable_ref(attr_var), |
|
1400 nodes.Constant(value, 'Int'))) |
1395 having = self.select.having |
1401 having = self.select.having |
1396 if having: |
1402 if having: |
1397 self.select.replace(having[0], nodes.And(having[0], comp)) |
1403 self.select.replace(having[0], nodes.And(having[0], comp)) |
1398 else: |
1404 else: |
1399 self.select.set_having([comp]) |
1405 self.select.set_having([comp]) |
1400 |
1406 |
1401 def rset_vocabulary(self, rset): |
1407 def rset_vocabulary(self, rset): |
1402 mask = reduce(lambda x, y: x | (y[0] or 0), rset, 0) |
1408 mask = reduce(lambda x, y: x | (y[0] or 0), rset, 0) |
1403 return sorted([(self._cw._(label), val) for label, val in self.choices |
1409 return sorted([(self._cw._(label), val) for label, val in self.choices |
1404 if val & mask]) |
1410 if not val or val & mask]) |
1405 |
1411 |
1406 def possible_values(self): |
1412 def possible_values(self): |
1407 return [unicode(val) for label, val in self.vocabulary()] |
1413 return [unicode(val) for label, val in self.vocabulary()] |
1408 |
1414 |
1409 |
1415 |