Skip to content

Commit

Permalink
[scorecards] correctly check for existence of keys in filter mixin
Browse files Browse the repository at this point in the history
Not all pages have all keys so we need to do the .get() thing on all
filter params to avoid 500 errors
  • Loading branch information
struan committed Jan 10, 2024
1 parent 74603ad commit aa38217
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions scoring/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,29 @@ def setup_filter_context(self, context, filter, authority_type):
if getattr(filter.form, "cleaned_data", None) is not None:
params = filter.form.cleaned_data
descs = []
if params["population"] and params["population"] != "":
descs.append(params["population"])
if params["control"] and params["control"] != "":
descs.append(params["control"])
if params["ruc_cluster"] and params["ruc_cluster"] != "":
descs.append(PlanScore.ruc_cluster_description(params["ruc_cluster"]))
if params["imdq"] and params["imdq"] != "":
descs.append("deprivation quintile {}".format(params["imdq"]))
if params["country"] and params["country"] != "":
if (
params.get("population", None) is not None
and params["population"] != ""
):
descs.append(params.get("population", None) is not None)
if params.get("control", None) is not None and params["control"] != "":
descs.append(params.get("control", None) is not None)
if (
params.get("ruc_cluster", None) is not None
and params["ruc_cluster"] != ""
):
descs.append(
PlanScore.ruc_cluster_description(
params.get("ruc_cluster", None) is not None
)
)
if params.get("imdq", None) is not None and params["imdq"] != "":
descs.append(
"deprivation quintile {}".format(
params.get("imdq", None) is not None
)
)
if params.get("country", None) is not None and params["country"] != "":
descs.append(Council.country_description(params["country"]))
if params.get("region", None) is not None and params["region"] != "":
descs.append(params["region"])
Expand Down

0 comments on commit aa38217

Please sign in to comment.