Skip to content

[Scorecards] Added year comparison question page #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: 2025-scorecards
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions caps/templates/caps/icons/arrow-down.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<svg width="{{ width | default:'1em' }}" height="{{ height | default:'1em' }}" viewBox="0 0 30 30" class="bi {{ classes }}" {% if role %}role="{{ role }}"{% endif %} fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M29 15L15 29L1 15L9.84211 15L9.84211 1L20.1579 1L20.1579 15L29 15Z" fill="white" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
2 changes: 2 additions & 0 deletions caps/templates/caps/icons/arrow-up.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<svg width="{{ width | default:'1em' }}" height="{{ height | default:'1em' }}" viewBox="0 0 30 30" class="bi {{ classes }}" {% if role %}role="{{ role }}"{% endif %} fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M1 15L15 1L29 15H20.1579V29H9.84211V15H1Z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
12 changes: 9 additions & 3 deletions caps/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.test import TestCase, Client

from unittest.mock import patch

from django.test import Client, TestCase
from django.urls import reverse

from caps.models import Council, Promise, PlanDocument, EmergencyDeclaration
from caps.models import Council, EmergencyDeclaration, PlanDocument, Promise
from scoring.models import PlanYear


class TestPageRenders(TestCase):
Expand All @@ -14,6 +14,8 @@ def setUp(self):
name="Borsetshire", slug="borsetshire", country=Council.ENGLAND
)

PlanYear.objects.create(year=2023, is_current=True)

def test_home_page(self):
url = reverse("home")
response = self.client.get(url)
Expand Down Expand Up @@ -75,6 +77,8 @@ def setUp(self):
combined_authority=felpersham,
)

PlanYear.objects.create(year=2023, is_current=True)

@patch("caps.mapit.session")
def test_postcode_to_one_council_redirects_to_council(self, mapit_session):
mapit_session.get.return_value.json.return_value = {
Expand Down Expand Up @@ -158,6 +162,8 @@ def setUp(self):
target_year="2045",
)

PlanYear.objects.create(year=2023, is_current=True)

def test_council_has_promise(self):
url = reverse("council", args=["borsetshire"])
response = self.client.get(url)
Expand Down
9 changes: 5 additions & 4 deletions caps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from caps.search_funcs import condense_highlights
from caps.utils import file_size, is_valid_postcode
from charting import ChartCollection
from scoring.models import PlanScore, PlanSection, PlanSectionScore
from scoring.models import PlanScore, PlanSection, PlanSectionScore, PlanYear


def add_context_for_plans_download_and_search(context):
Expand Down Expand Up @@ -181,7 +181,8 @@ def get_scorecard_context(self, council: Council) -> dict[str, Any]:
"""
context = {}
try:
plan_score = PlanScore.objects.get(council=council, year=2023)
plan_year = PlanYear.objects.get(is_current=True)
plan_score = PlanScore.objects.get(council=council, year=plan_year.year)

group = council.get_scoring_group()

Expand All @@ -193,12 +194,12 @@ def get_scorecard_context(self, council: Council) -> dict[str, Any]:
).aggregate(average_score=Avg("weighted_total"))

sections = PlanSectionScore.sections_for_council(
council=council, plan_year=settings.PLAN_YEAR
council=council, plan_year=plan_year.year
)

# get average section scores for authorities of the same type
section_avgs = PlanSectionScore.get_all_section_averages(
council_group=group, plan_year=settings.PLAN_YEAR
council_group=group, plan_year=plan_year.year
)

for section in section_avgs.all():
Expand Down
10 changes: 10 additions & 0 deletions scoring/fixtures/test_answers.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
[
{
"model": "scoring.planyear",
"pk": 1,
"fields": {
"year": 2023,
"new_council_date": "2023-01-01",
"old_council_date": "2021-04-01",
"is_current": true
}
},
{
"model": "caps.council",
"pk": 1,
Expand Down
10 changes: 10 additions & 0 deletions scoring/fixtures/test_homepage.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
[
{
"model": "scoring.planyear",
"pk": 1,
"fields": {
"year": 2023,
"new_council_date": "2023-01-01",
"old_council_date": "2021-04-01",
"is_current": true
}
},
{
"model": "caps.council",
"pk": 1,
Expand Down
20 changes: 20 additions & 0 deletions scoring/fixtures/test_previous_years_answers.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
[
{
"model": "scoring.planyear",
"pk": 1,
"fields": {
"year": 2023,
"new_council_date": "2023-01-01",
"old_council_date": "2021-04-01",
"is_current": false
}
},
{
"model": "scoring.planyear",
"pk": 2,
"fields": {
"year": 2025,
"new_council_date": "2024-01-01",
"old_council_date": "2023-01-01",
"is_current": true
}
},
{
"model": "caps.council",
"pk": 1,
Expand Down
10 changes: 10 additions & 0 deletions scoring/fixtures/test_top_performers.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
[
{
"model": "scoring.planyear",
"pk": 1,
"fields": {
"year": 2023,
"new_council_date": "2023-01-01",
"old_council_date": "2021-04-01",
"is_current": true
}
},
{
"model": "caps.council",
"pk": 1,
Expand Down
29 changes: 22 additions & 7 deletions scoring/middleware.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from django.conf import settings
from django.http import Http404, HttpResponseServerError

from scoring.models import PlanYear


class AddYearMiddleware:
Expand All @@ -10,11 +13,23 @@ def __call__(self, request):
return response

def process_view(self, request, view_func, view_args, view_kwargs):
year = settings.PLAN_YEAR
if view_kwargs.get("year") is not None:
try:
year = int(view_kwargs["year"])
except ValueError:
year = settings.PLAN_YEAR
if request.host.name == "scoring":
year = None
if view_kwargs.get("year") is not None:
try:
year = int(view_kwargs["year"])
except ValueError:
year = None

if year is not None:
try:
plan_year = PlanYear.objects.get(year=year)
except PlanYear.DoesNotExist:
raise Http404("No such year")
else:
try:
plan_year = PlanYear.objects.get(is_current=True)
except PlanYear.DoesNotExist:
raise HttpResponseServerError("No current Plan Year found")

request.year = year
request.year = plan_year
50 changes: 50 additions & 0 deletions scoring/static/scoring/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,53 @@ document.querySelectorAll('.js-social-graphic-download').forEach(function(el) {
});
});
});

// Question display improved or worsened councils
// Function to update table visibility based on checkbox states
function updateTableVisibility() {
var improvedChecked = document.querySelector('.js-checkbox-improved-councils').checked;
var worsenedChecked = document.querySelector('.js-checkbox-worsened-councils').checked;

// If no checkboxes are checked, show all rows
var showAll = !improvedChecked && !worsenedChecked;

// Update visibility for rows with year-difference-status
forEachElement('tr[year-difference-status]', function(row) {
var status = row.getAttribute('year-difference-status');

// Show the row if:
// 1. No filters are active (show all)
// 2. The row's status matches the active filter
if (showAll ||
(improvedChecked && status === 'improved') ||
(worsenedChecked && status === 'worsened')) {
row.style.display = '';
} else {
row.style.display = 'none';
}
});
}

forEachElement('.js-checkbox-improved-councils', function(checkbox) {
checkbox.addEventListener('change', function() {
// If this checkbox is checked, uncheck the other one
if (this.checked) {
forEachElement('.js-checkbox-worsened-councils', function(otherCheckbox) {
otherCheckbox.checked = false;
});
}
updateTableVisibility();
});
});

forEachElement('.js-checkbox-worsened-councils', function(checkbox) {
checkbox.addEventListener('change', function() {
// If this checkbox is checked, uncheck the other one
if (this.checked) {
forEachElement('.js-checkbox-improved-councils', function(otherCheckbox) {
otherCheckbox.checked = false;
});
}
updateTableVisibility();
});
});
14 changes: 13 additions & 1 deletion scoring/static/scoring/scss/table-question-council.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
.question-summary-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(10rem, 10rem));
column-gap: 1rem;
row-gap: 1rem;

@include media-breakpoint-up(lg) {
grid-template-columns: repeat(auto-fill, minmax(12.5rem, 13.5rem));
column-gap: 2rem;
}
}

.table-question-council,
.section-question-table,
.table-council-question-performance {
th {
vertical-align: top;
vertical-align: middle;
}

th, td {
Expand Down
2 changes: 2 additions & 0 deletions scoring/static/scoring/scss/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ $form-select-indicator: url("../img/bootstrap/form-select-indicator.svg");
$form-feedback-icon-valid: url("../img/bootstrap/form-feedback-icon-valid.svg");
$form-feedback-icon-invalid: url("../img/bootstrap/form-feedback-icon-invalid.svg");

$form-check-input-border: 1px solid rgba($black, .5);

// Form validation

// Z-index master list
Expand Down
Loading
Loading