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 committed Apr 29, 2024
1 parent a5b8a71 commit 64f51ce
Show file tree
Hide file tree
Showing 4 changed files with 28 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
3 changes: 2 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 @@ -72,6 +72,7 @@ def get_context_data(self, **kwargs):
"source_label": dataset.source_label,
"release_date": dataset.release_date,
"is_public": dataset.is_public,
"areas_available": dataset.areas_available.all() or [AreaType.objects.get(code="WMC")],
}
)

Expand Down

0 comments on commit 64f51ce

Please sign in to comment.