Skip to content

Commit

Permalink
Improving matching project org_types.
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrae committed Dec 21, 2015
1 parent 6304da7 commit bb59ccd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from flask import Flask, make_response, request, jsonify, render_template
import requests
from flask.ext.heroku import Heroku
from sqlalchemy import desc
from sqlalchemy import desc, or_
from sqlalchemy.sql.expression import func
from sqlalchemy.orm import defer
from dictalchemy import make_class_dictable
Expand Down Expand Up @@ -564,7 +564,9 @@ def get_projects(id=None):
# Support searching for multiple org_types
if "," in value:
values = [unicode(item) for item in value.split(",")]
query = query.join(Project.organization).filter(getattr(Organization, org_attr).in_(values))
# build a list of ilike queries to match on
ilike_values = [getattr(Organization, org_attr).ilike(format_ilike_term(value)) for value in values]
query = query.join(Project.organization).filter(or_(*ilike_values))
else:
query = query.join(Project.organization).filter(getattr(Organization, org_attr).ilike(format_ilike_term(value)))
elif 'q' in attr:
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def test_project_organzation_type_filter(self):
'''
Test searching for projects from certain types of organizations.
'''
brigade = OrganizationFactory(name=u'Brigade Org', type=u'Brigade')
brigade = OrganizationFactory(name=u'Brigade Org', type=u'Brigade, midwest')
code_for_all = OrganizationFactory(name=u'Code for All Org', type=u'Code for All')
gov_org = OrganizationFactory(name=u'Gov Org', type=u'Government')

Expand Down

0 comments on commit bb59ccd

Please sign in to comment.