Merge "Don't mask the filter built-in"

This commit is contained in:
Jenkins 2014-01-26 06:11:39 +00:00 committed by Gerrit Code Review
commit 99051778fa
3 changed files with 27 additions and 27 deletions

View File

@ -212,7 +212,7 @@ class Assignment(sql.Base, assignment.Driver):
def list_projects(self, hints):
with sql.transaction() as session:
query = session.query(Project)
project_refs = self.filter(Project, query, hints)
project_refs = self.filter_query(Project, query, hints)
return [project_ref.to_dict() for project_ref in project_refs]
def list_projects_in_domain(self, domain_id):
@ -531,7 +531,7 @@ class Assignment(sql.Base, assignment.Driver):
def list_domains(self, hints):
with sql.transaction() as session:
query = session.query(Domain)
refs = self.filter(Domain, query, hints)
refs = self.filter_query(Domain, query, hints)
return [ref.to_dict() for ref in refs]
def _get_domain(self, session, domain_id):
@ -584,7 +584,7 @@ class Assignment(sql.Base, assignment.Driver):
def list_roles(self, hints):
with sql.transaction() as session:
query = session.query(Role)
refs = self.filter(Role, query, hints)
refs = self.filter_query(Role, query, hints)
return [ref.to_dict() for ref in refs]
def _get_role(self, session, role_id):

View File

@ -168,12 +168,12 @@ class Base(object):
:returns query: query, updated with any filters satisfied
"""
def inexact_filter(model, query, filter, hints):
def inexact_filter(model, query, filter_, hints):
"""Applies an inexact filter to a query.
:param model: the table model in question
:param query: query to apply filters to
:param filter: the dict that describes this filter
:param filter_: the dict that describes this filter
:param hints: contains the list of filters yet to be satisfied.
Any filters satisfied here will be removed so that
the caller will know if any filters remain.
@ -182,7 +182,7 @@ class Base(object):
satisfy
"""
column_attr = getattr(model, filter['name'])
column_attr = getattr(model, filter_['name'])
# TODO(henry-nash): Sqlalchemy 0.7 defaults to case insensitivity
# so once we find a way of changing that (maybe on a call-by-call
@ -190,28 +190,28 @@ class Base(object):
# the filters below. For now, these case sensitive versions will
# be handled at the controller level.
if filter['case_sensitive']:
if filter_['case_sensitive']:
return query
if filter['comparator'] == 'contains':
query_term = column_attr.ilike('%%%s%%' % filter['value'])
elif filter['comparator'] == 'startswith':
query_term = column_attr.ilike('%s%%' % filter['value'])
elif filter['comparator'] == 'endswith':
query_term = column_attr.ilike('%%%s' % filter['value'])
if filter_['comparator'] == 'contains':
query_term = column_attr.ilike('%%%s%%' % filter_['value'])
elif filter_['comparator'] == 'startswith':
query_term = column_attr.ilike('%s%%' % filter_['value'])
elif filter_['comparator'] == 'endswith':
query_term = column_attr.ilike('%%%s' % filter_['value'])
else:
# It's a filter we don't understand, so let the caller
# work out if they need to do something with it.
return query
hints.remove(filter)
hints.remove(filter_)
return query.filter(query_term)
def exact_filter(model, filter, cumlative_filter_dict, hints):
def exact_filter(model, filter_, cumlative_filter_dict, hints):
"""Applies an exact filter to a query.
:param model: the table model in question
:param filter: the dict that describes this filter
:param filter_: the dict that describes this filter
:param cumlative_filter_dict: a dict that describes the set of
exact filters built up so far
:param hints: contains the list of filters yet to be satisfied.
@ -221,23 +221,23 @@ class Base(object):
:returns cumlative_filter_dict: updated cumulative dict
"""
key = filter['name']
key = filter_['name']
if isinstance(getattr(model, key).property.columns[0].type,
sql.types.Boolean):
filter_dict[key] = utils.attr_as_boolean(filter['value'])
filter_dict[key] = utils.attr_as_boolean(filter_['value'])
else:
filter_dict[key] = filter['value']
hints.remove(filter)
filter_dict[key] = filter_['value']
hints.remove(filter_)
return filter_dict
filter_dict = {}
for filter in hints.filters():
for filter_ in hints.filters():
# TODO(henry-nash): Check if name is valid column, if not skip
if filter['comparator'] == 'equals':
filter_dict = exact_filter(model, filter, filter_dict, hints)
if filter_['comparator'] == 'equals':
filter_dict = exact_filter(model, filter_, filter_dict, hints)
else:
query = inexact_filter(model, query, filter, hints)
query = inexact_filter(model, query, filter_, hints)
# Apply any exact filters we built up
if filter_dict:
@ -245,7 +245,7 @@ class Base(object):
return query
def filter(self, model, query, hints):
def filter_query(self, model, query, hints):
"""Applies filtering to a query.
:param model: table model

View File

@ -123,7 +123,7 @@ class Identity(sql.Base, identity.Driver):
def list_users(self, hints):
session = db_session.get_session()
query = session.query(User)
user_refs = self.filter(User, query, hints)
user_refs = self.filter_query(User, query, hints)
return [identity.filter_user(x.to_dict()) for x in user_refs]
def _get_user(self, session, user_id):
@ -255,7 +255,7 @@ class Identity(sql.Base, identity.Driver):
def list_groups(self, hints):
session = db_session.get_session()
query = session.query(Group)
refs = self.filter(Group, query, hints)
refs = self.filter_query(Group, query, hints)
return [ref.to_dict() for ref in refs]
def _get_group(self, session, group_id):