Skip to content

Add grants to individuals to org pages #993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: live
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dataload/charity_names.json

This file was deleted.

58 changes: 58 additions & 0 deletions grantnav/frontend/org_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,61 @@ def new_org_ids(org_result):
org_ids.append(org_id)

return org_ids


class OrgNotFoundError(Exception):
pass


orgs_cache = {"funder": {}, "recipient": {}}


def get_org(org_id, org_type):
""" org_type: recipient, funder
returns an organisation match
"""
# Don't allow the memory cache to grow infinitely
if len(orgs_cache[org_type].keys()) > 300000:
orgs_cache[org_type] = {}

try:
org = orgs_cache[org_type][org_id]
return org
except KeyError:
pass

query = {
"query": {
"bool": {
"filter": [
{"term": {"orgIDs": org_id}}
]
}
}
}

try:
org = get_results(query, data_type=org_type)["hits"]["hits"][0]["_source"]
# Save the org to the cache
orgs_cache[org_type][org_id] = org
return org
except (IndexError, KeyError):
# Failed to find org
raise OrgNotFoundError


def get_recipient_individuals(org_id):
query = {"query": {
"bool": {
"filter": [
{"term": {"fundingOrganization.id": org_id}},
{"term": {"additional_data.TSGRecipientType": "Individual"}},
]
},
},
"aggs": {
"recipient_count": {"cardinality": {"field": "recipientIndividual.id", "precision_threshold": 40000}},
}
}

return get_results(query)
2 changes: 1 addition & 1 deletion grantnav/frontend/tests_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def browser(request):
# no-sandbox prevents an error when running as the root user
chrome_options.add_argument("--no-sandbox")
# uncomment this if "DevToolsActivePort" error
# chrome_options.add_argument("--remote-debugging-port=9222")
chrome_options.add_argument("--remote-debugging-port=9222")

browser = webdriver.Chrome(options=chrome_options)
elif BROWSER == "Firefox":
Expand Down
7 changes: 6 additions & 1 deletion grantnav/frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from grantnav.index import get_index
from grantnav.frontend.search_helpers import get_results, get_request_type_and_size, get_terms_facets, get_data_from_path
import grantnav.frontend.search_helpers as helpers
from grantnav.frontend.org_utils import new_ordered_names, new_org_ids, new_stats_by_currency
from grantnav.frontend.org_utils import new_ordered_names, new_org_ids, new_stats_by_currency, get_recipient_individuals


BASIC_FILTER = [
Expand Down Expand Up @@ -1040,6 +1040,9 @@ def org(request, org_id):

funder_results = get_results(org_query, data_type="funder")
recipient_results = get_results(org_query, data_type="recipient")
recipient_ind_results = get_recipient_individuals(org_id)

# TODO recipient_ind_results

org_types = []
org_names = []
Expand All @@ -1065,6 +1068,8 @@ def org(request, org_id):
recipient["grant_search_parameters"] = urlencode(parameters)
recipient_funders = get_recipient_funders(org_ids)



ftc_data = None
publisher_prefix = None

Expand Down