Skip to content
Closed
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
49 changes: 44 additions & 5 deletions dataload/import_to_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
ES_INDEX = os.environ.get("ES_INDEX", "threesixtygiving")
ELASTICSEARCH_HOST = os.environ.get("ELASTICSEARCH_HOST", "localhost")

UNITED_KINGDOM_COUNTRIES = ["Wales", "Scotland", "Northern Ireland", "England"]
UNITED_KINGDOM_ISO_NM = "United Kingdom of Great Britain and Northern Ireland"


def initialise_org_cache():
# Initialise organisation cache
Expand Down Expand Up @@ -310,6 +313,15 @@ def maybe_create_index(index_name=ES_INDEX):
"GNRecipientOrgCountyName": {
"type": "keyword",
},
"GNBestCountryName": {
"type": "keyword",
},
"GNBeneficiaryCountryName": {
"type": "keyword",
},
"GNRecipientOrgCountryName": {
"type": "keyword",
}
}
},
# Additional funding/recipient organisation mappings
Expand Down Expand Up @@ -447,6 +459,9 @@ def process_grant(grant, grants_file_path):
# grant.additional_data.GNBestCountyName (utlanm)
# grant.additional_data.GNBeneficiaryCountyName (utlanm)
# grant.additional_data.GNRecipientOrgCountyName (utlanm)
# grant.additional_data.GNBestCountryName (iso country name)
# grant.additional_data.GNRecipientCountryName (iso country name)
# grant.additional_data.GNBeneficiaryCountryName (iso country name)
update_doc_with_other_locations(grant)
# update_doc_with_undetermined needs to go last
update_doc_with_undetermined(grant)
Expand Down Expand Up @@ -613,14 +628,18 @@ def to_band(value, bins, labels):


def update_doc_with_other_locations(grant):
""" This flattens out some embedded data for easier indexing """
""" This flattens/maps out some embedded location data for easier indexing"""

# Check the country code list look up for the country name
if country := grant["additional_data"]["codeListLookup"].get("recipientOrg_location_countryCode"):
grant["additional_data"]["GNRecipientOrgCountryName"] = country

if country := grant["additional_data"]["codeListLookup"].get("beneficiaryLocation_countryCode"):
grant["additional_data"]["GNBeneficiaryCountryName"] = country

# Prior versions of additional_data may not have this field
# or if locationLookup failed entirely for this grant
if not grant["additional_data"].get("locationLookup"):
return

for location in grant["additional_data"]["locationLookup"]:
for location in grant["additional_data"].get("locationLookup", []):
# beneficiaryLocation
if location["source"] == "beneficiaryLocation":

Expand Down Expand Up @@ -649,6 +668,11 @@ def update_doc_with_other_locations(grant):
except KeyError:
pass

# If we couldn't get country code from codelist look up check if it's UK&NI
if not grant["additional_data"].get("GNBeneficiaryCountryName"):
if location["ctrynm"] in UNITED_KINGDOM_COUNTRIES:
grant["additional_data"]["GNBeneficiaryCountryName"] = UNITED_KINGDOM_ISO_NM

# recipientOrganizationLocation
if location["source"] == "recipientOrganizationLocation" or location["source"] == "recipientOrganizationPostcode":

Expand Down Expand Up @@ -677,6 +701,11 @@ def update_doc_with_other_locations(grant):
except KeyError:
pass

# If we couldn't get country code from codelist above look up check if it's UK&NI
if not grant["additional_data"].get("GNRecipientOrgCountryName"):
if location["ctrynm"] in UNITED_KINGDOM_COUNTRIES:
grant["additional_data"]["GNRecipientOrgCountryName"] = UNITED_KINGDOM_ISO_NM

# Best County name - Prefer beneficiary then recipient org
if not grant["additional_data"].get("GNBestCountyName"):
try:
Expand All @@ -689,6 +718,13 @@ def update_doc_with_other_locations(grant):

# End looping over locations

# Best Country name - Prefer beneficiary then recipient org
if not grant["additional_data"].get("GNBestCountryName"):
if country := grant["additional_data"].get("GNBeneficiaryCountryName"):
grant["additional_data"]["GNBestCountryName"] = country
elif country := grant["additional_data"].get("GNRecipientOrgCountryName"):
grant["additional_data"]["GNBestCountryName"] = country


def update_doc_with_undetermined(grant):
""" Checks certain additional data fields and assigns them to the value of "Undetermined"
Expand All @@ -703,6 +739,9 @@ def update_doc_with_undetermined(grant):
"GNBestCountyName",
"GNRecipientOrgCountyName",
"GNBeneficiaryCountyName",
"GNBeneficiaryCountryName",
"GNBestCountryName",
"GNRecipientOrgCountryName",
"recipientDistrictGeoCode",
"recipientDistrictName",
"recipientRegionName",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,24 @@

<div class="filter-group_contents-wrapper">
<div id="geo-type-best" class="geo-type-switcher">
{% include 'components/filters/lists/filter-list-generic-checkboxes.html' with open=True aggregate_data=results.aggregations.recipientRegionName filter_title="Country and Region" %}
{% include 'components/filters/lists/filter-list-generic-checkboxes.html' with open=False finder=True finder_class="best_county" aggregate_data=results.aggregations.bestCountyName filter_title="County" %}
{% include 'components/filters/lists/filter-list-district.html' with open=True %}
{% include 'components/filters/lists/filter-list-generic-checkboxes.html' with open=False finder=True finder_class="best_country" finder_placeholder="country" aggregate_data=results.aggregations.bestCountryName filter_title="All Countries" filter_id="bestCountryName" %}
{% include 'components/filters/lists/filter-list-generic-checkboxes.html' with open=True aggregate_data=results.aggregations.recipientRegionName filter_title="UK Country and Region" %}
{% include 'components/filters/lists/filter-list-generic-checkboxes.html' with open=False finder=True finder_class="best_county" finder_placeholder="UK county" aggregate_data=results.aggregations.bestCountyName filter_title="UK County" %}
{% include 'components/filters/lists/filter-list-district.html' with open=True %}
</div>

<div id="geo-type-recipient" class="hidden geo-type-switcher">
{% include 'components/filters/lists/filter-list-generic-checkboxes.html' with open=True aggregate_data=results.aggregations.recipientOrgRegionName filter_title="Country and Region" %}
{% include 'components/filters/lists/filter-list-generic-checkboxes.html' with open=False finder=True finder_class="recipient_county" aggregate_data=results.aggregations.recipientOrgCountyName filter_title="County" %}
{% include 'components/filters/lists/filter-list-generic-include-exclude.html' with open=True aggregate_data=results.aggregations.recipientOrgDistrictName filter_title="District" filter_id="recipientOrgDistrictName" %}
{% include 'components/filters/lists/filter-list-generic-checkboxes.html' with open=False finder=True finder_class="recipient_country" finder_placeholder="country" aggregate_data=results.aggregations.recipientOrgCountryName filter_title="All Countries" filter_id="recipientOrgCountryName" %}
{% include 'components/filters/lists/filter-list-generic-checkboxes.html' with open=True aggregate_data=results.aggregations.recipientOrgRegionName filter_title="UK Country and Region" %}
{% include 'components/filters/lists/filter-list-generic-checkboxes.html' with open=False finder=True finder_class="recipient_county" finder_placeholder="UK district" aggregate_data=results.aggregations.recipientOrgCountyName filter_title="UK County" %}
{% include 'components/filters/lists/filter-list-generic-include-exclude.html' with open=True aggregate_data=results.aggregations.recipientOrgDistrictName filter_title="UK District" filter_id="recipientOrgDistrictName" %}
</div>

<div id="geo-type-beneficiary" class="hidden geo-type-switcher">
{% include 'components/filters/lists/filter-list-generic-checkboxes.html' with open=True aggregate_data=results.aggregations.beneficiaryRegionName filter_title="Country and Region" %}
{% include 'components/filters/lists/filter-list-generic-checkboxes.html' with open=False finder=True finder_class="beneficiary_county" aggregate_data=results.aggregations.beneficiaryCountyName filter_title="County" %}
{% include 'components/filters/lists/filter-list-generic-include-exclude.html' with open=True aggregate_data=results.aggregations.beneficiaryDistrictName filter_title="District" filter_id="beneficiaryDistrictName" %}
{% include 'components/filters/lists/filter-list-generic-checkboxes.html' with open=False finder=True finder_class="beneficiary_country" finder_placeholder="country" aggregate_data=results.aggregations.beneficiaryCountryName filter_title="All Countries" filter_id="beneficiaryCountryName" %}
{% include 'components/filters/lists/filter-list-generic-checkboxes.html' with open=True aggregate_data=results.aggregations.beneficiaryRegionName filter_title="UK Country and Region" %}
{% include 'components/filters/lists/filter-list-generic-checkboxes.html' with open=False finder=True finder_class="beneficiary_county" finder_placeholder="UK county" aggregate_data=results.aggregations.beneficiaryCountyName filter_title="UK County" %}
{% include 'components/filters/lists/filter-list-generic-include-exclude.html' with open=True aggregate_data=results.aggregations.beneficiaryDistrictName filter_title="UK District" filter_id="beneficiaryDistrictName" %}
</div>

</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="filter-list filter-list--with-checkboxes">
<details id="filter-accordion-district" class="filter-list__accordion" {% if results.aggregations.recipientDistrictName.clear_url or open %} open{% endif %}>
<summary class="filter-list__label">
<div>District {% if results.aggregations.recipientDistrictName.clear_url %} <a href={{results.aggregations.recipientDistrictName.clear_url}}> <small>(clear)</small></a> {% endif%}</div>
<div>UK District {% if results.aggregations.recipientDistrictName.clear_url %} <a href={{results.aggregations.recipientDistrictName.clear_url}}> <small>(clear)</small></a> {% endif%}</div>
{% include 'tokens/accordion-toggle-icon.html' %}
</summary>
<div class="filter-list__contents-wrapper facet-multiselect">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="filter-list filter-list--with-checkboxes">
<details id="filter-accordion-funding-org" class="filter-list__accordion" {% if results.aggregations.fundingOrganization.clear_url or True %} open{% endif %}>
<summary class="filter-list__label">
<div>Funding Organisations {% if results.aggregations.fundingOrganization.clear_url %} <a href={{results.aggregations.fundingOrganization.clear_url}}> <small>(clear)</small></a> {% endif%}</div>
<div>Funding Organisation {% if results.aggregations.fundingOrganization.clear_url %} <a href={{results.aggregations.fundingOrganization.clear_url}}> <small>(clear)</small></a> {% endif%}</div>
{% include 'tokens/accordion-toggle-icon.html' %}
</summary>
<div class="filter-list__contents-wrapper facet-multiselect">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{# This requires the filterElements callback defined in search.html #}
{# margin-right style is for pixel alignment with include/exclude select2 input boxes #}
<div class="search-box-wrapper padding-left:05 padding-right:05 padding-top:05 padding-bottom:05" style="margin-right: 7px" >
<input type="text" style="width: 100%" class="form-control" onkeyup="filterElements(event, '.filter-list-{{finder_class}}')" placeholder="Search for a county" />
<input type="text" style="width: 100%" class="form-control" onkeyup="filterElements(event, '.filter-list-{{finder_class}}')" placeholder="Search for a {{finder_placeholder}}" />
</div>
{% endif %}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="filter-list filter-list--with-checkboxes">
<details id="filter-accordion-recipient-org" class="filter-list__accordion" {% if results.aggregations.recipientOrganization.clear_url %} open{% endif %}>
<summary class="filter-list__label">
<div>Recipient Organisations {% if results.aggregations.recipientOrganization.clear_url %} <a href={{results.aggregations.recipientOrganization.clear_url}}> <small>(clear)</small></a> {% endif%}</div>
<div>Recipient Organisation {% if results.aggregations.recipientOrganization.clear_url %} <a href={{results.aggregations.recipientOrganization.clear_url}}> <small>(clear)</small></a> {% endif%}</div>
{% include 'tokens/accordion-toggle-icon.html' %}
</summary>
<div class="filter-list__contents-wrapper facet-multiselect">
Expand Down
43 changes: 24 additions & 19 deletions grantnav/frontend/templates/components/grant-search-result.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,41 @@
</time>
</div>

<div class="grant-search-result__data-item">
<span class="grant-search-result__data-item--label">Funder:</span>
<span><a href="{% url 'org' result.source.fundingOrganization.0.id %}">{{ result.source.fundingOrganization.0 | get_name }}</a></span>
</div>

<div class="grant-search-result__data-item">
<span class="grant-search-result__data-item--label">Amount:</span>
<span>{{result.source|get_currency}}{{result.source.amountAwarded|get_amount}}</span>
</div>

<div class="grant-search-result__data-item">
<span class="grant-search-result__data-item--label">Funder:</span>
<span><a href="{% url 'org' result.source.fundingOrganization.0.id %}">{{ result.source.fundingOrganization.0 | get_name }}</a></span>
<span class="grant-search-result__data-item--label">
Recipient{% if result.source.recipientOrganization %} Organisation{% endif %}:
</span>
<span>
{% if result.source.recipientOrganization %}
<br />Name: <a href="{% url 'org' result.source.recipientOrganization.0.id %}">{{ result.source.recipientOrganization.0|get_name|truncatechars:60 }}</a>
{% else %}
Individual
{% endif %}
</span>
</div>

<div class="grant-search-result__data-item">
<span class="grant-search-result__data-item--label">Recipient:</span>
{% if result.source.recipientOrganization %}
<span><a href="{% url 'org' result.source.recipientOrganization.0.id %}">{{ result.source.recipientOrganization.0|get_name|truncatechars:40 }}</a></span>
{% else %}
<span>Individual</span>
{% endif %}
{% if result.source.additional_data.locationLookup.0.source == "beneficiaryLocation" %}
<span class="grant-search-result__data-item--label">Grant Location:</span>
{% elif "recipient" in result.source.additional_data.locationLookup.0.source %}
<!-- <span class="grant-search-result__data-item--label">UK Organisation Location:</span> -->
{% endif %}
<div class="grant-search-result__data-item">
UK Region: <a href="{% url 'region' result.source.additional_data.recipientRegionName %}">{{ result.source.additional_data.recipientRegionName }}</a>
</div>

{% if result.source.additional_data.recipientRegionName %}
<div class="grant-search-result__data-item">
<span class="grant-search-result__data-item--label">Region:</span>
<span><a href="{% url 'region' result.source.additional_data.recipientRegionName %}">{{ result.source.additional_data.recipientRegionName }}</a></span>
</div>
{% endif %}
{% if result.source.additional_data.recipientDistrictName %}
<div class="grant-search-result__data-item">
<span class="grant-search-result__data-item--label">District:</span>
<span><a href="{% url 'district' result.source.additional_data.recipientDistrictName %}">{{ result.source.additional_data.recipientDistrictName }}</a></span>
UK District: <a href="{% url 'district' result.source.additional_data.recipientDistrictName %}">{{ result.source.additional_data.recipientDistrictName }}</a>
</div>
</div>
{% endif %}
</div>
</div>
Loading
Loading