From bab65295e4f3a7f92a64279ddbecc4410cb023d3 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 17 Jun 2024 15:00:41 +0100 Subject: [PATCH 1/3] add AuthorityData table --- crowdsourcer/migrations/0051_authoritydata.py | 45 +++++++++++++++++++ crowdsourcer/models.py | 11 +++++ 2 files changed, 56 insertions(+) create mode 100644 crowdsourcer/migrations/0051_authoritydata.py diff --git a/crowdsourcer/migrations/0051_authoritydata.py b/crowdsourcer/migrations/0051_authoritydata.py new file mode 100644 index 00000000..5e5a1c6e --- /dev/null +++ b/crowdsourcer/migrations/0051_authoritydata.py @@ -0,0 +1,45 @@ +# Generated by Django 4.2.11 on 2024-06-17 14:00 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ("crowdsourcer", "0050_add_previous_q_link"), + ] + + operations = [ + migrations.CreateModel( + name="AuthorityData", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("data_name", models.CharField(max_length=200)), + ("data_value", models.TextField()), + ( + "authority", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="crowdsourcer.publicauthority", + ), + ), + ], + options={ + "indexes": [ + models.Index( + fields=["authority", "data_name"], + name="crowdsource_authori_49003f_idx", + ) + ], + }, + ), + ] diff --git a/crowdsourcer/models.py b/crowdsourcer/models.py index f23cf553..9ed027cd 100644 --- a/crowdsourcer/models.py +++ b/crowdsourcer/models.py @@ -104,6 +104,17 @@ def options(self): return Option.objects.filter(question=self).order_by("ordering", "score") +class AuthorityData(models.Model): + authority = models.ForeignKey("PublicAuthority", on_delete=models.CASCADE) + data_name = models.CharField(max_length=200) + data_value = models.TextField() + + class Meta: + indexes = [ + models.Index(fields=["authority", "data_name"]), + ] + + class PublicAuthority(models.Model): COUNTRIES = [ ("england", "England"), From 75e5aad68cc1a985ab494857c9b2c625b18d5d03 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 17 Jun 2024 16:40:39 +0100 Subject: [PATCH 2/3] management command to import council minutes links --- .../commands/import_council_minutes_links.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 crowdsourcer/management/commands/import_council_minutes_links.py diff --git a/crowdsourcer/management/commands/import_council_minutes_links.py b/crowdsourcer/management/commands/import_council_minutes_links.py new file mode 100644 index 00000000..f7bd5de1 --- /dev/null +++ b/crowdsourcer/management/commands/import_council_minutes_links.py @@ -0,0 +1,36 @@ +from django.conf import settings +from django.core.management.base import BaseCommand + +import pandas as pd + +from crowdsourcer.models import AuthorityData, PublicAuthority + + +class Command(BaseCommand): + help = "import council minutes links" + + data_file = settings.BASE_DIR / "data" / "council_minutes.csv" + + def handle(self, *args, **kwargs): + df = pd.read_csv(self.data_file) + df = df.dropna(subset=["campaigns_lab_url"]) + + for _, row in df.iterrows(): + gss = row["gss-code"] + if not pd.isna(gss): + try: + authority = PublicAuthority.objects.get(unique_id=gss) + except PublicAuthority.DoesNotExist: + self.stderr.write( + f"could not find authority with GSS code {gss} ({row['official-name']}" + ) + continue + + ad, _ = AuthorityData.objects.update_or_create( + authority=authority, + data_name="council_minutes", + defaults={ + "data_value": row["campaigns_lab_url"], + }, + ) + print(authority.name) From 1348ad9e978ca1bd1f1a90b50deb08fa8fc28e97 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 17 Jun 2024 16:41:13 +0100 Subject: [PATCH 3/3] display a list to council minutes, if exists, in question header Fixes #160 --- crowdsourcer/models.py | 7 +++++++ .../templates/crowdsourcer/authority_questions.html | 6 ++++++ .../crowdsourcer/authority_questions_with_previous.html | 6 ++++++ crowdsourcer/views/base.py | 1 + 4 files changed, 20 insertions(+) diff --git a/crowdsourcer/models.py b/crowdsourcer/models.py index 9ed027cd..1154e873 100644 --- a/crowdsourcer/models.py +++ b/crowdsourcer/models.py @@ -209,6 +209,13 @@ def response_counts( return authorities + def get_data(self, data_name): + try: + data = AuthorityData.objects.get(authority=self, data_name=data_name) + return data.data_value + except AuthorityData.DoesNotExist: + return None + class Meta: verbose_name_plural = "authorities" diff --git a/crowdsourcer/templates/crowdsourcer/authority_questions.html b/crowdsourcer/templates/crowdsourcer/authority_questions.html index b4cc23df..ddc50035 100644 --- a/crowdsourcer/templates/crowdsourcer/authority_questions.html +++ b/crowdsourcer/templates/crowdsourcer/authority_questions.html @@ -13,6 +13,12 @@

+ {% if council_minutes %} +
+ Minutes +
+ {% endif %} +