Skip to content
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

display council minutes on council pages #167

Merged
merged 3 commits into from
Jun 19, 2024
Merged
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
36 changes: 36 additions & 0 deletions crowdsourcer/management/commands/import_council_minutes_links.py
Original file line number Diff line number Diff line change
@@ -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)
45 changes: 45 additions & 0 deletions crowdsourcer/migrations/0051_authoritydata.py
Original file line number Diff line number Diff line change
@@ -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",
)
],
},
),
]
18 changes: 18 additions & 0 deletions crowdsourcer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -198,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"

Expand Down
6 changes: 6 additions & 0 deletions crowdsourcer/templates/crowdsourcer/authority_questions.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ <h1 class="mb-3 mb-md-4">
</h1>

<div class="sticky-top py-3 bg-white border-bottom" style="margin-bottom: -1px;">
{% if council_minutes %}
<div class="float-end" style="position: relative; z-index: 10;">
<a href="{{ council_minutes }}">Minutes</a>
</div>
{% endif %}

<div class="dropdown">
<button class="btn btn-outline-secondary dropdown-toggle" id="navbarDropdown" data-bs-toggle="dropdown" aria-expanded="false">
Skip to question
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ <h1 class="mb-3 mb-md-4">
</h1>

<div class="sticky-top py-3 bg-white border-bottom" style="margin-bottom: -1px;">
{% if council_minutes %}
<div class="float-end" style="position: relative; z-index: 10;">
<a href="{{ council_minutes }}">Minutes</a>
</div>
{% endif %}

<div class="dropdown">
<button class="btn btn-outline-secondary dropdown-toggle" id="navbarDropdown" data-bs-toggle="dropdown" aria-expanded="false">
Skip to question
Expand Down
1 change: 1 addition & 0 deletions crowdsourcer/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def get_context_data(self, **kwargs):
] = f"{self.title_start}{context['authority_name']}: {context['section_title']}"
context["has_previous_questions"] = self.has_previous_questions

context["council_minutes"] = self.authority.get_data("council_minutes")
return context


Expand Down
Loading