Commit 98fff37e authored by Vincent Pelletier's avatar Vincent Pelletier

Make Query and ComplexQuery hashable, so that they can be used as dictionnary...

Make Query and ComplexQuery hashable, so that they can be used as dictionnary key. It is valid as long as nobody use direct access to properties - there is no setter defined - and that extra care is taken not modify variants members which are provided at construction.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15457 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 09eaa6c7
...@@ -258,6 +258,13 @@ class Query(QueryMixin): ...@@ -258,6 +258,13 @@ class Query(QueryMixin):
def __call__(self): def __call__(self):
self.asSQLExpression() self.asSQLExpression()
def __hash__(self):
value = self.value
if isinstance(value, list):
value = tuple(value)
return hash((self.format, self.operator, self.range, self.search_mode,
self.table_alias_list, self.key, value, self.type))
def getRange(self): def getRange(self):
return self.range return self.range
...@@ -454,6 +461,10 @@ class ComplexQuery(QueryMixin): ...@@ -454,6 +461,10 @@ class ComplexQuery(QueryMixin):
def __call__(self): def __call__(self):
self.asSQLExpression() self.asSQLExpression()
def __hash__(self):
subquery_hash = hash(tuple([hash(x) for x in self.getQueryList()]))
return hash((subquery_hash, self.operator))
def getQueryList(self): def getQueryList(self):
return self.query_list return self.query_list
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment