diff --git a/caps/dataframe/la.py b/caps/dataframe/la.py index 3b91d4d2d..58176a49f 100644 --- a/caps/dataframe/la.py +++ b/caps/dataframe/la.py @@ -3,6 +3,7 @@ local authority data """ + from functools import lru_cache from typing import Callable, Optional, List import string diff --git a/caps/forms.py b/caps/forms.py index fe253e7bb..f152189d6 100644 --- a/caps/forms.py +++ b/caps/forms.py @@ -2,7 +2,6 @@ Forms for the CAPS app """ - from django.forms import CharField, ChoiceField, ModelChoiceField, RadioSelect, Select from haystack.forms import SearchForm from haystack.inputs import Exact diff --git a/caps/management/commands/import_emissions_data.py b/caps/management/commands/import_emissions_data.py index 317059027..0aac9d62a 100644 --- a/caps/management/commands/import_emissions_data.py +++ b/caps/management/commands/import_emissions_data.py @@ -1,6 +1,7 @@ """ Import local authority_emissions """ + import pandas as pd from caps.models import Council, DataPoint, DataType from django.core.management.base import BaseCommand diff --git a/caps/management/commands/import_polling_data.py b/caps/management/commands/import_polling_data.py index cbc1c7863..6e28975f7 100644 --- a/caps/management/commands/import_polling_data.py +++ b/caps/management/commands/import_polling_data.py @@ -1,6 +1,7 @@ """ Import local authority_emissions """ + import pandas as pd from caps.models import Council, DataPoint, DataType from django.core.management.base import BaseCommand diff --git a/caps/search_funcs.py b/caps/search_funcs.py index e61201b13..6a17ec5b9 100644 --- a/caps/search_funcs.py +++ b/caps/search_funcs.py @@ -1,6 +1,7 @@ """ Functions for use by the semantic search features """ + import re from collections import namedtuple from itertools import groupby diff --git a/caps/views.py b/caps/views.py index fb733c790..716a22099 100755 --- a/caps/views.py +++ b/caps/views.py @@ -108,9 +108,9 @@ def get_context_data(self, **kwargs): ) context = add_context_for_plans_download_and_search(context) context["page_title"] = "Local Climate Assemblies - CAPE" - context[ - "page_description" - ] = "Search and view reports from local climate assemblies." + context["page_description"] = ( + "Search and view reports from local climate assemblies." + ) return context @@ -156,9 +156,9 @@ def get_emissions_context(self, council: Council) -> dict[str, Any]: latest_year_total_emissions = council_emissions_data.get( year=latest_year, data_type__name="Total Emissions" ).value - context[ - "latest_year_per_capita_emissions" - ] = latest_year_per_capita_emissions + context["latest_year_per_capita_emissions"] = ( + latest_year_per_capita_emissions + ) context["latest_year_per_km2_emissions"] = latest_year_per_km2_emissions context["latest_year_total_emissions"] = latest_year_total_emissions context["emissions_data"] = True @@ -166,9 +166,9 @@ def get_emissions_context(self, council: Council) -> dict[str, Any]: pass if context["emissions_data"]: - context[ - "current_emissions_breakdown" - ] = council.current_emissions_breakdown(year=latest_year) + context["current_emissions_breakdown"] = ( + council.current_emissions_breakdown(year=latest_year) + ) multi_emission_chart = charts.multi_emissions_chart(council, latest_year) context["chart_collection"] = ChartCollection() context["chart_collection"].register(multi_emission_chart) @@ -231,9 +231,9 @@ def get_scorecard_context(self, council: Council) -> dict[str, Any]: "num_sections": len(top_scoring_sections), } if len(top_scoring_sections) > 0: - context["scoring_accolades"][ - "example_section" - ] = top_scoring_sections[0]["description"] + context["scoring_accolades"]["example_section"] = ( + top_scoring_sections[0]["description"] + ) context["scoring_hidden"] = getattr(settings, "SCORECARDS_PRIVATE", False) diff --git a/scoring/views.py b/scoring/views.py index 90907b3f1..5424e25e6 100644 --- a/scoring/views.py +++ b/scoring/views.py @@ -1159,12 +1159,12 @@ def get_context_data(self, **kwargs): context["methodology_year"] = methodology_year context["toc_template"] = f"scoring/methodology/{methodology_year}/_toc.html" - context[ - "intro_template" - ] = f"scoring/methodology/{methodology_year}/_intro.html" - context[ - "details_template" - ] = f"scoring/methodology/{methodology_year}/_details.html" + context["intro_template"] = ( + f"scoring/methodology/{methodology_year}/_intro.html" + ) + context["details_template"] = ( + f"scoring/methodology/{methodology_year}/_details.html" + ) questions = ( PlanQuestion.objects.filter(section__year=methodology_year) diff --git a/scoring2022/views.py b/scoring2022/views.py index 6d98ff0e0..84b76d468 100644 --- a/scoring2022/views.py +++ b/scoring2022/views.py @@ -90,9 +90,9 @@ def get_missing_councils(self, council_ids, authority_type): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context[ - "all_councils" - ] = Council.objects.all() # for location search autocomplete + context["all_councils"] = ( + Council.objects.all() + ) # for location search autocomplete authority_type = self.get_authority_type() @@ -139,9 +139,11 @@ def get_context_data(self, **kwargs): sorted_by = sort councils = sorted( councils, - key=lambda council: 0 - if council["score"] == 0 or council["score"] is None - else council["all_scores"][sort]["score"], + key=lambda council: ( + 0 + if council["score"] == 0 or council["score"] is None + else council["all_scores"][sort]["score"] + ), reverse=True, ) councils = sorted(councils, key=itemgetter("code")) @@ -304,18 +306,18 @@ def get_context_data(self, **kwargs): ) context["comparisons"] = comparisons - context[ - "page_description" - ] = "Want to know how effective {name}’s climate plans are? Check out {name}’s Council Climate Scorecard to understand how their climate plans compare to local authorities across the UK.".format( - name=council.name + context["page_description"] = ( + "Want to know how effective {name}’s climate plans are? Check out {name}’s Council Climate Scorecard to understand how their climate plans compare to local authorities across the UK.".format( + name=council.name + ) ) - context[ - "twitter_tweet_text" - ] = "Up to 30% of the UK’s transition to zero carbon is within the influence of local councils - that’s why I’m checking {name}’s Climate Action Plan on 📋 #CouncilClimateScorecards".format( - name=( - "@{}".format(council.twitter_name) - if council.twitter_name - else council.name + context["twitter_tweet_text"] = ( + "Up to 30% of the UK’s transition to zero carbon is within the influence of local councils - that’s why I’m checking {name}’s Climate Action Plan on 📋 #CouncilClimateScorecards".format( + name=( + "@{}".format(council.twitter_name) + if council.twitter_name + else council.name + ) ) ) return context @@ -339,9 +341,9 @@ def get_authority_type(self): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context[ - "all_councils" - ] = Council.objects.all() # for location search autocomplete + context["all_councils"] = ( + Council.objects.all() + ) # for location search autocomplete filter_args = { "data": self.request.GET or None, @@ -496,9 +498,9 @@ class LocationResultsView(PrivateScorecardsAccessMixin, BaseLocationResultsView) def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context[ - "all_councils" - ] = Council.objects.all() # for location search autocomplete + context["all_councils"] = ( + Council.objects.all() + ) # for location search autocomplete context["page_title"] = "Choose a council" return context @@ -509,9 +511,9 @@ class MethodologyView(PrivateScorecardsAccessMixin, TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context[ - "all_councils" - ] = Council.objects.all() # for location search autocomplete + context["all_councils"] = ( + Council.objects.all() + ) # for location search autocomplete # questions = PlanQuestion.objects.all() # sections = PlanSection.objects.all() @@ -562,9 +564,9 @@ class AboutView(PrivateScorecardsAccessMixin, TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context[ - "all_councils" - ] = Council.objects.all() # for location search autocomplete + context["all_councils"] = ( + Council.objects.all() + ) # for location search autocomplete context["page_title"] = "About" context["current_page"] = "about-page" return context @@ -576,9 +578,9 @@ class ContactView(PrivateScorecardsAccessMixin, TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context[ - "all_councils" - ] = Council.objects.all() # for location search autocomplete + context["all_councils"] = ( + Council.objects.all() + ) # for location search autocomplete context["page_title"] = "Contact" context["current_page"] = "contact-page" return context @@ -590,9 +592,9 @@ class HowToUseView(TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context[ - "all_councils" - ] = Council.objects.all() # for location search autocomplete + context["all_councils"] = ( + Council.objects.all() + ) # for location search autocomplete context["page_title"] = "How to use the Scorecards" context["current_page"] = "how-to-page" return context