Skip to content

Commit

Permalink
fixup! WIP: Move auto conversion disclaimer into AreaType model
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Jan 16, 2024
1 parent bb9f4fe commit 6f7948e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
18 changes: 9 additions & 9 deletions hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,18 +493,18 @@ def shader_filter(self):

@property
def auto_conversion_disclaimer(self):
# TODO: This is super hacky, and this string should probably be set
# by the import script or at the time of conversion, rather than us
# having to guess the conversion in here.
text = None
if self.auto_converted:
if self.area_type.code == "WMC":
return '<a href="#">This dataset has been automatically converted from 2025 parliamentary constituencies.</a>'
if self.auto_converted_text:
text = self.auto_converted_text

Check warning on line 499 in hub/models.py

View check run for this annotation

Codecov / codecov/patch

hub/models.py#L499

Added line #L499 was not covered by tests
elif self.area_type.code == "WMC":
text = "This dataset has been automatically converted from 2025 parliamentary constituencies."

Check warning on line 501 in hub/models.py

View check run for this annotation

Codecov / codecov/patch

hub/models.py#L501

Added line #L501 was not covered by tests
elif self.area_type.code == "WMC23":
return '<a href="#">This dataset has been automatically converted from 2010 parliamentary constituencies.</a>'
text = "This dataset has been automatically converted from 2010 parliamentary constituencies."

Check warning on line 503 in hub/models.py

View check run for this annotation

Codecov / codecov/patch

hub/models.py#L503

Added line #L503 was not covered by tests
else:
return '<a href="#">This dataset has been automatically converted from a different boundary type.</a>'
else:
return None
text = "This dataset has been automatically converted from a different boundary type."

Check warning on line 505 in hub/models.py

View check run for this annotation

Codecov / codecov/patch

hub/models.py#L505

Added line #L505 was not covered by tests

return text


class UserDataSets(models.Model):
Expand Down
12 changes: 9 additions & 3 deletions hub/templates/hub/area.html
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ <h3 class="h5">{{ dataset.label }}</h3>
<div class="card-footer">
<p class="card-text">
{{ dataset.source }}
{{ dataset.auto_conversion_disclaimer|safe }}
{% if dataset.auto_conversion_disclaimer %}
<a href="{{ auto_conversion_explanation_url|safe }}">{{ dataset.auto_conversion_disclaimer|safe }}</a>
{% endif %}
{% if dataset.release_date %}
Updated {{ dataset.release_date }}.
{% endif %}
Expand Down Expand Up @@ -427,7 +429,9 @@ <h3 class="h5">{{ dataset.label }}</h3>
<div class="card-footer">
<p class="card-text">
{{ dataset.source }}
{{ dataset.auto_conversion_disclaimer|safe }}
{% if dataset.auto_conversion_disclaimer %}
<a href="{{ auto_conversion_explanation_url|safe }}">{{ dataset.auto_conversion_disclaimer|safe }}</a>
{% endif %}
{% if dataset.release_date %}
Updated {{ dataset.release_date }}.
{% endif %}
Expand Down Expand Up @@ -526,7 +530,9 @@ <h3 class="h5">{{ dataset.label }}</h3>
<div class="card-footer">
<p class="card-text">
{{ dataset.source }}
{{ dataset.auto_conversion_disclaimer|safe }}
{% if dataset.auto_conversion_disclaimer %}
<a href="{{ auto_conversion_explanation_url|safe }}">{{ dataset.auto_conversion_disclaimer|safe }}</a>
{% endif %}
{% if dataset.release_date %}
Updated {{ dataset.release_date }}.
{% endif %}
Expand Down
6 changes: 4 additions & 2 deletions hub/views/area.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import defaultdict

from django.conf import settings
from django.db.models import Count
from django.http import JsonResponse
from django.shortcuts import get_object_or_404, redirect
Expand Down Expand Up @@ -67,7 +68,7 @@ def get_auto_convered_datasets(self):
auto_converted = {}

for ds in DataType.objects.filter(area_type=self.object.area_type):
auto_converted[ds.data_set_id] = ds.auto_converted
auto_converted[ds.data_set_id] = ds.auto_conversion_disclaimer

return auto_converted

Expand All @@ -90,7 +91,7 @@ def process_dataset(self, data_set, favs, auto_converted):
"featured": data_set.featured,
"excluded_countries": data_set.exclude_countries,
"release_date": data_set.release_date,
"auto_converted": auto_converted.get(data_set.id, False),
"auto_conversion_disclaimer": auto_converted.get(data_set.id, None),
"is_favourite": favs.get(data_set.id, False),
}
if data_set.is_range:
Expand Down Expand Up @@ -273,6 +274,7 @@ def get_context_data(self, **kwargs):
for item in items:
categories[category_name].remove(item)

context["auto_conversion_explanation_url"] = settings.AUTO_CONVERSION_URL
context["categories"] = categories
context["indexed_categories"] = indexed_categories

Expand Down
2 changes: 2 additions & 0 deletions local_intelligence_hub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
HIDE_DEBUG_TOOLBAR=(bool, False),
GOOGLE_ANALYTICS=(str, ""),
GOOGLE_SITE_VERIFICATION=(str, ""),
AUTO_CONVERSION_URL=(str, ""),
)
environ.Env.read_env(BASE_DIR / ".env")

Expand All @@ -39,6 +40,7 @@
MAPIT_API_KEY = env("MAPIT_API_KEY")
GOOGLE_ANALYTICS = env("GOOGLE_ANALYTICS")
GOOGLE_SITE_VERIFICATION = env("GOOGLE_SITE_VERIFICATION")
AUTO_CONVERSION_URL = env("AUTO_CONVERSION_URL")

# make sure CSRF checking still works behind load balancers
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
Expand Down

0 comments on commit 6f7948e

Please sign in to comment.