Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
related to issue #16: removed the need to replicate information about…
Browse files Browse the repository at this point in the history
… the class identified by a relation.
  • Loading branch information
Mario Frasca committed Jan 1, 2015
1 parent 61971b5 commit 0c9717f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bauble/plugins/plants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def init(cls):
context_menu=family_context_menu,
markup_func=family_markup_func)

mapper_search.add_meta(('genus', 'gen', 'genera'), Genus, ['genus'])
mapper_search.add_meta(('genus', 'gen'), Genus, ['genus'])
SearchView.view_meta[Genus].set(children="species",
infobox=GenusInfoBox,
context_menu=genus_context_menu,
Expand Down
21 changes: 14 additions & 7 deletions bauble/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,22 @@ def __repr__(self):
return '.'.join(self.value)

def evaluate(self, env):
"""return pair (query, attribute)
the value associated to the identifier is an altered query where the
joinpoint is the one relative to the attribute, and the attribute
itself.
"""

query = env.session.query(env.domain)
if len(self.value) == 1:
# identifier is an attribute of the table being queried
return getattr(env.domain, self.value[0])
attr = getattr(env.domain, self.value[0])
elif len(self.value) > 1:
# identifier is an attribute of a joined table
domain = env.search_strategy._shorthand.get(self.value[-2], self.value[-2])
domain = env.search_strategy._domains[domain][0]
return getattr(domain, self.value[-1])
query = query.join(*self.value[:-1], aliased=True)
attr = getattr(query._joinpoint['_joinpoint_entity'], self.value[-1])
return query, attr

def needs_join(self, env):
return self.value[:-1]
Expand All @@ -117,9 +125,8 @@ def __repr__(self):
return "(%s %s %s)" % ( self.operands[0], self.op, self.operands[1])

def evaluate(self, env):
clause = lambda x: self.operation(self.operands[0].evaluate(env), x)
q = env.session.query(env.domain)
q = q.join(*self.operands[0].needs_join(env))
q, a = self.operands[0].evaluate(env)
clause = lambda x: self.operation(a, x)
return q.filter(clause(self.operands[1].express()))

def needs_join(self, env):
Expand Down

0 comments on commit 0c9717f

Please sign in to comment.