Skip to content

Commit

Permalink
Add PPC dataset to WMC23 pages
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-griffen authored and struan committed Jan 11, 2024
1 parent 7804a11 commit 74cceb7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
28 changes: 28 additions & 0 deletions hub/templates/hub/area.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ <h2 class="h5 text-muted">Easy access to the datasets that matter to you</h2>
</aside>

<section class="mb-5 mb-lg-6 area-section" id="mp">
{% if area_type == "WMC" %}
<h2 class="mb-3 text-primary">MP</h2>
<div class="area-data-grid">

Expand Down Expand Up @@ -261,6 +262,33 @@ <h3 class="h5">Date elected</h3>
{% include "hub/includes/icons/chevron-right.html" %}
</a>
</div>
{% elif area_type == "WMC23" %}
<h2 class="mb-3 text-primary">MP</h2>
<div class="area-data-grid">
<div class="card dataset-card area-data--md">
<div class="card-header">
<h5 class="card-title mb-3">Prospective Parliamentary Candidates</h5>
</div>
<div class="card-body">
<table class="table mb-0">
<thead>
<tr>
<th scope="col">PPC</th>
<th scope="col">Party</th>
</tr>
</thead>
<tbody>
{% for row in PPCs %}
<tr>
<th>{{ row.person }}</th>
<td>{{ row.party }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
</section>

{% if categories.opinion %}
Expand Down
12 changes: 11 additions & 1 deletion hub/views/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
AreaData,
AreaType,
DataSet,
DataType,
Person,
PersonData,
UserDataSets,
Expand Down Expand Up @@ -134,13 +135,22 @@ def get_context_data(self, **kwargs):

context["overlap_constituencies"] = self.get_overlap_info()
context["area_type"] = str(self.object.area_type)
if context["area_type"] == "WMC23":
context["PPCs"] = [
{
"person": p,
"party": PersonData.objects.get(
person=p, data_type=DataType.objects.get(name="party")
).value(),
}
for p in Person.objects.filter(area=self.object, person_type="PPC")
]
try:
context["mp"] = {
"person": Person.objects.get(
area=self.object, person_type="MP", end_date__isnull=True
)
}

data = PersonData.objects.filter(
person=context["mp"]["person"]
).select_related("data_type")
Expand Down

0 comments on commit 74cceb7

Please sign in to comment.