Skip to content

Commit

Permalink
Show dataset area types on Data Sources page
Browse files Browse the repository at this point in the history
Includes new AreaType.name_singular and AreaType.name_plural shortcuts.
  • Loading branch information
zarino authored and struan committed May 21, 2024
1 parent 30e54c5 commit e01d2ea
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
23 changes: 23 additions & 0 deletions hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,34 @@ class AreaType(models.Model):
("single_tier_council", "Single Tier Council"),
("district_council", "District Council"),
]

NAMES_SINGULAR = {
"WMC": "current constituency",
"WMC23": "future constituency",
"STC": "single tier council",
"DIS": "district council",
}

NAMES_PLURAL = {
"WMC": "current constituencies",
"WMC23": "future constituencies",
"STC": "single tier councils",
"DIS": "district councils",
}

name = models.CharField(max_length=50, unique=True)
code = models.CharField(max_length=10, unique=True)
area_type = models.CharField(max_length=50, choices=AREA_TYPES)
description = models.CharField(max_length=300)

@property
def name_singular(self):
return self.NAMES_SINGULAR[self.code]

@property
def name_plural(self):
return self.NAMES_PLURAL[self.code]

def __str__(self):
return self.code

Expand Down
1 change: 1 addition & 0 deletions hub/templates/hub/includes/comma.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% if not forloop.first %}{% if forloop.last %} and {% else %}, {% endif %}{% endif %}
2 changes: 2 additions & 0 deletions hub/templates/hub/sources.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ <h3 class="h5 mb-0">{{ dataset.label }}</h3>
<div class="card-footer bg-gray-100">
<p class="card-text fs-8 text-muted">
<a href="{{ dataset.source }}">{{ dataset.source_label }}</a>
Available for
{% for area_type in dataset.areas_available %}{% include 'hub/includes/comma.html' %}<a href="{% url "explore" %}?area_type={{ area_type.code }}">{{ area_type.name_plural }}</a>{% endfor %}.
{% if dataset.release_date %}
Updated {{ dataset.release_date }}.
{% endif %}
Expand Down
8 changes: 7 additions & 1 deletion hub/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from hub.forms import MailingListSignupForm
from hub.mixins import TitleMixin
from hub.models import Area, DataSet
from hub.models import Area, AreaType, DataSet


class NotFoundPageView(TitleMixin, TemplateView):
Expand Down Expand Up @@ -62,6 +62,11 @@ def get_context_data(self, **kwargs):
}

for dataset in DataSet.objects.all().order_by("label"):
# MP datasets are associated with a Person not an Area,
# so need to default them to WMC.
areas_available = dataset.areas_available.all() or [
AreaType.objects.get(code="WMC")
]
categories[dataset.category or "mp"]["datasets"].append(
{
"name": dataset.name,
Expand All @@ -72,6 +77,7 @@ def get_context_data(self, **kwargs):
"source_label": dataset.source_label,
"release_date": dataset.release_date,
"is_public": dataset.is_public,
"areas_available": areas_available,
}
)

Expand Down

0 comments on commit e01d2ea

Please sign in to comment.