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

Support for WhoFundsThem #147

Closed
wants to merge 7 commits into from
Closed
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 ceuk-marking/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
ALLOWED_HOSTS=(list, []),
HIDE_DEBUG_TOOLBAR=(bool, False),
LOG_LEVEL=(str, "WARNING"),
BRAND=(str, "default"),
)
environ.Env.read_env(BASE_DIR / ".env")

Expand All @@ -41,6 +42,7 @@
MAPIT_URL = env("MAPIT_URL")
MAPIT_API_KEY = env("MAPIT_API_KEY")
LOG_LEVEL = env("LOG_LEVEL")
BRAND = env("BRAND")

# make sure CSRF checking still works behind load balancers
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
Expand Down
15 changes: 10 additions & 5 deletions crowdsourcer/fixtures/basics.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,35 +93,40 @@
"model": "crowdsourcer.questiongroup",
"pk": 1,
"fields": {
"description": "Single Tier"
"description": "Single Tier",
"marking_session": [1,2]
}
},
{
"model": "crowdsourcer.questiongroup",
"pk": 2,
"fields": {
"description": "District"
"description": "District",
"marking_session": [1,2]
}
},
{
"model": "crowdsourcer.questiongroup",
"pk": 3,
"fields": {
"description": "County"
"description": "County",
"marking_session": [1,2]
}
},
{
"model": "crowdsourcer.questiongroup",
"pk": 4,
"fields": {
"description": "Northern Ireland"
"description": "Northern Ireland",
"marking_session": [1,2]
}
},
{
"model": "crowdsourcer.questiongroup",
"pk": 5,
"fields": {
"description": "Combined Authority"
"description": "Combined Authority",
"marking_session": [1,2]
}
},
{
Expand Down
79 changes: 79 additions & 0 deletions crowdsourcer/management/commands/set_up_mp_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from django.core.management.base import BaseCommand

import pandas as pd

from crowdsourcer.models import (
MarkingSession,
PublicAuthority,
QuestionGroup,
ResponseType,
Section,
)


class Command(BaseCommand):
help = "set up authorities and question groups"

groups = ["MP"]

sections = [
"Who Funds Them",
]

session = "WhoFundsThem 2024"

response_types = ["First Mark", "Right of Reply", "Audit"]

def add_arguments(self, parser):
parser.add_argument(
"-q", "--quiet", action="store_true", help="Silence progress bars."
)

def get_group(self, mp):
return QuestionGroup.objects.get(description="MP")

def get_do_not_mark_list(self):
df = pd.read_csv(self.do_not_mark_file)
return list(df["gss-code"])

def get_twfy_df(self):
df = pd.read_csv("https://www.theyworkforyou.com/mps/?f=csv").rename(
columns={"Person ID": "twfyid"}
)

return df

def handle(self, quiet: bool = False, *args, **options):
session, _ = MarkingSession.objects.get_or_create(
label=self.session, defaults={"start_date": "2024-06-01"}
)

for section in self.sections:
c, c = Section.objects.get_or_create(title=section, marking_session=session)

for group in self.groups:
g, c = QuestionGroup.objects.get_or_create(description=group)
g.marking_session.set([session])

for r_type in self.response_types:
r, c = ResponseType.objects.get_or_create(type=r_type, priority=1)

mps = self.get_twfy_df()

if not quiet:
print("Importing MPs")
for _, mp in mps.iterrows():
do_not_mark = False

name = f"{mp['First name']} {mp['Last name']}"
defaults = {
"name": name,
"questiongroup": self.get_group(mp),
"do_not_mark": do_not_mark,
"type": "MP",
}

a, created = PublicAuthority.objects.update_or_create(
unique_id=mp["twfyid"],
defaults=defaults,
)
6 changes: 6 additions & 0 deletions crowdsourcer/middleware.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.conf import settings

from crowdsourcer.models import MarkingSession, ResponseType


Expand Down Expand Up @@ -30,6 +32,10 @@ def process_template_response(self, request, response):

context["marking_session"] = request.current_session
context["sessions"] = MarkingSession.objects.filter(active=True)
context["brand"] = settings.BRAND
context[
"brand_include"
] = f"crowdsourcer/cobrand/navbar_{context['brand']}.html"

response.context_data = context

Expand Down
18 changes: 18 additions & 0 deletions crowdsourcer/migrations/0046_questiongroup_marking_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-05-08 12:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("crowdsourcer", "0045_markingsession_stage"),
]

operations = [
migrations.AddField(
model_name="questiongroup",
name="marking_session",
field=models.ManyToManyField(to="crowdsourcer.markingsession"),
),
]
18 changes: 18 additions & 0 deletions crowdsourcer/migrations/0047_markingsession_entity_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-05-08 16:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("crowdsourcer", "0046_questiongroup_marking_session"),
]

operations = [
migrations.AddField(
model_name="markingsession",
name="entity_name",
field=models.TextField(blank=True, max_length=200, null=True),
),
]
2 changes: 2 additions & 0 deletions crowdsourcer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class MarkingSession(models.Model):
start_date = models.DateField()
active = models.BooleanField(default=False)
stage = models.ForeignKey("ResponseType", null=True, on_delete=models.SET_NULL)
entity_name = models.TextField(max_length=200, null=True, blank=True)

def __str__(self):
return self.label
Expand All @@ -42,6 +43,7 @@ class QuestionGroup(models.Model):
"""

description = models.TextField(max_length=200)
marking_session = models.ManyToManyField(MarkingSession)

def __str__(self):
return self.description
Expand Down
8 changes: 6 additions & 2 deletions crowdsourcer/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ def get_blank_section_scores(session):
).values_list("title", flat=True)
}

for council in PublicAuthority.objects.filter(do_not_mark=False).all():
for council in PublicAuthority.objects.filter(
questiongroup__marking_session=session, do_not_mark=False
).all():
if council.type == "COMB":
weighted[council.name] = ca_sections.copy()
raw_scores[council.name] = ca_sections.copy()
Expand Down Expand Up @@ -561,7 +563,9 @@ def get_scoring_object(session):
scoring["council_type"] = types
scoring["council_control"] = control
scoring["councils"] = {}
for council in PublicAuthority.objects.all():
for council in PublicAuthority.objects.filter(
questiongroup__marking_session=session
):
scoring["councils"][council.name] = council

get_section_maxes(scoring, session)
Expand Down
Binary file added crowdsourcer/static/img/mysoc_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h1 class="mb-4">Section Right of Reply Progress and Challenges</h1>
{% widthratio counts.complete counts.total 100 as width %}
<div class="progress-bar bg-success" role="progressbar" aria-labelled-by="label-{{ forloop.counter }}" aria-valuenow="{{ width|default:"0" }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ width|default:"0" }}%"></div>
</div>
<span id="label-{{ forloop.counter }}">{{ counts.complete }} of {{ counts.total }} councils completed. ({{ counts.started }} started, {{ counts.challenges }} challenges)</span>
<span id="label-{{ forloop.counter }}">{{ counts.complete }} of {{ counts.total }} {{ marking_session.entity_name|default:"council" }}{{ counts.total|pluralize }} completed. ({{ counts.started }} started, {{ counts.challenges }} challenges)</span>
</td>
</tr>
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1 class="mb-4">Section Progress</h1>
{% widthratio counts.complete counts.total 100 as width %}
<div class="progress-bar bg-success" role="progressbar" aria-labelled-by="label-{{ forloop.counter }}" aria-valuenow="{{ width|default:"0" }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ width|default:"0" }}%"></div>
</div>
<span id="label-{{ forloop.counter }}">{{ counts.complete }} of {{ counts.total }} councils completed. ({{ counts.started }} started, {{ counts.assigned }} assigned)</span>
<span id="label-{{ forloop.counter }}">{{ counts.complete }} of {{ counts.total }} {{ marking_session.entity_name|default:"council" }}{{ counts.total|pluralize }} completed. ({{ counts.started }} started, {{ counts.assigned }} assigned)</span>
</td>
</tr>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion crowdsourcer/templates/crowdsourcer/assignments.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h1 class="mb-4">{% if show_users %}All{% else %}Your{% endif %} assignments</h1
{% widthratio assignment.complete assignment.total 100 as width %}
<div class="progress-bar bg-success" role="progressbar" aria-labelled-by="label-{{ forloop.counter }}" aria-valuenow="{{ width|default:"0" }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ width|default:"0" }}%"></div>
</div>
<span id="label-{{ forloop.counter }}">{{ assignment.complete }} of {{ assignment.total }} authorities completed</span>
<span id="label-{{ forloop.counter }}">{{ assignment.complete }} of {{ assignment.total }} {{ marking_session.entity_name|default:"council" }}{{ assignment.total|pluralize }} completed</span>
</td>
</tr>
{% empty %}
Expand Down
6 changes: 3 additions & 3 deletions crowdsourcer/templates/crowdsourcer/authorities_assigned.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<h1 class="mb-4">Sign in</h1>
<a href="{% url 'login' %}">Sign in</a>
{% else %}
<h1 class="mb-4">Authority Assigned</h1>
<h1 class="mb-4">{{ marking_session.entity_name }} Assigned</h1>
<table class="table">
<thead>
<tr>
<th>Authority {% if do_not_mark_only %}<a href="./">ALL</a>{% else %}<a href="?do_not_mark_only=1">DNM</a>{% endif %}</th>
<th>{{ marking_session.entity_name }} {% if do_not_mark_only %}<a href="./">ALL</a>{% else %}<a href="?do_not_mark_only=1">DNM</a>{% endif %}</th>
<th>Sections Assigned <a href="?sort=asc">&#9650;</a>/<a href="?sort=desc">&#9660;</a></th>
</tr>
</thead>
Expand All @@ -31,7 +31,7 @@ <h1 class="mb-4">Authority Assigned</h1>
{% widthratio authority.num_sections 7 100 as width %}
<div class="progress-bar bg-success" role="progressbar" aria-labelled-by="label-{{ forloop.counter }}" aria-valuenow="{{ width|default:"0" }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ width|default:"0" }}%"></div>
</div>
<span id="label-{{ forloop.counter }}">{% if authority.num_sections %}{{ authority.num_sections }}{% else %}0{% endif %} of 7 sections assigned</span>
<span id="label-{{ forloop.counter }}">{% if authority.num_sections %}{{ authority.num_sections }}{% else %}0{% endif %} of {{ total_sections }} section{{ total_sections|pluralize }} assigned</span>
{% endif %}
</td>
</tr>
Expand Down
21 changes: 9 additions & 12 deletions crowdsourcer/templates/crowdsourcer/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
<body>
<nav class="navbar navbar-expand-sm bg-light border-bottom site-header">
<div class="container">
<a class="navbar-brand d-flex align-items-center" href="{% url 'home' %}">
<img src="{% static 'img/ceuk-logo.png' %}" alt="Climate Emergency UK" width="290" height="100" class="me-3">
GRACE
</a>
{% include brand_include|default:"crowdsourcer/cobrand/navbar_default.html" %}
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
Expand Down Expand Up @@ -44,10 +41,10 @@
</button>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li>
<a class="dropdown-item d-flex" href="{% session_url 'authority_assignments' %}">Authorities assigned</a>
<a class="dropdown-item d-flex" href="{% session_url 'authority_assignments' %}">{{ marking_session.entity_name|default:"Council" }}s assigned</a>
</li>
<li>
<a class="dropdown-item d-flex" href="{% session_url 'all_authority_progress' %}">Authority Progress</a>
<a class="dropdown-item d-flex" href="{% session_url 'all_authority_progress' %}">{{ marking_session.entity_name|default:"Council" }} Progress</a>
</li>
<li>
<a class="dropdown-item d-flex" href="{% session_url 'all_section_progress' %}">Section Progress</a>
Expand All @@ -65,16 +62,16 @@
</button>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li>
<a class="dropdown-item d-flex" href="{% session_url 'all_authority_ror_progress' %}">Authority Progress</a>
<a class="dropdown-item d-flex" href="{% session_url 'all_authority_ror_progress' %}">{{ marking_session.entity_name|default:"Council" }} Progress</a>
</li>
<li>
<a class="dropdown-item d-flex" href="{% session_url 'authority_login_report' %}">Authority Login Report</a>
<a class="dropdown-item d-flex" href="{% session_url 'authority_login_report' %}">{{ marking_session.entity_name|default:"Council" }} Login Report</a>
</li>
<li>
<a class="dropdown-item d-flex" href="{% session_url 'section_ror_progress' %}">Section Progress</a>
</li>
<li>
<a class="dropdown-item d-flex" href="{% session_url 'authority_contacts_report' %}">Authority Contacts</a>
<a class="dropdown-item d-flex" href="{% session_url 'authority_contacts_report' %}">{{ marking_session.entity_name|default:"Council" }} Contacts</a>
</li>
</ul>
</div>
Expand All @@ -95,7 +92,7 @@
<a class="dropdown-item d-flex" href="{% session_url 'all_audit_marks_csv' %}">Audit Mark Scores</a>
</li>
<li>
<a class="dropdown-item d-flex" href="{% session_url 'council_disagree_mark_csv' %}">Council disagree with positive mark</a>
<a class="dropdown-item d-flex" href="{% session_url 'council_disagree_mark_csv' %}">{{ marking_session.entity_name|default:"Council" }} disagree with positive mark</a>
</li>
<li>
<a class="dropdown-item d-flex" href="{% session_url 'stats_select_question' %}">Per question data</a>
Expand Down Expand Up @@ -127,10 +124,10 @@
</button>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li>
<a class="dropdown-item d-flex" href="{% session_url 'audit_authority_assignments' %}">Authorities assigned</a>
<a class="dropdown-item d-flex" href="{% session_url 'audit_authority_assignments' %}">{{ marking_session.entity_name|default:"Council" }}s assigned</a>
</li>
<li>
<a class="dropdown-item d-flex" href="{% session_url 'audit_all_authority_progress' %}">Authority Progress</a>
<a class="dropdown-item d-flex" href="{% session_url 'audit_all_authority_progress' %}">{{ marking_session.entity_name|default:"Council" }} Progress</a>
</li>
<li>
<a class="dropdown-item d-flex" href="{% session_url 'audit_all_section_progress' %}">Section Progress</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h1 class="mb-4">{{ page_title }}</h1>
<table class="table">
<thead>
<tr>
<th>Authority</th>
<th>{{ marking_session.entity_name|default:"Council" }}</th>
<th>Progress <a href="?sort=asc">&#9650;</a>/<a href="?sort=desc">&#9660;</a></th>
</tr>
</thead>
Expand All @@ -25,7 +25,7 @@ <h1 class="mb-4">{{ page_title }}</h1>
{% widthratio councils.complete councils.total 100 as width %}
<div class="progress-bar bg-success" role="progressbar" aria-labelled-by="label-{{ forloop.counter }}" aria-valuenow="{{ width|default:"0" }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ width|default:"0" }}%"></div>
</div>
<span id="label-{{ forloop.counter }}">{{ councils.complete }} of {{ councils.total }} councils completed</span>
<span id="label-{{ forloop.counter }}">{{ councils.complete }} of {{ councils.total }} {{ marking_session.entity_name|default:"council" }}{{ councils.total|pluralize }} completed</span>
</td>
</tr>
{% for authority in authorities %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load static %}
<a class="navbar-brand d-flex align-items-center" href="{% url 'home' %}">
<img src="{% static 'img/ceuk-logo.png' %}" alt="Climate Emergency UK" width="290" height="100" class="me-3">
GRACE
</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load static %}
<a class="navbar-brand d-flex align-items-center" href="{% url 'home' %}">
<img src="{% static 'img/mysoc_logo.png' %}" class="me-3">
mySociety
</a>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load crowdsourcer_tags %}

{% block content %}
<h1 class="mb-4">{{ section_title }} authorities</h1>
<h1 class="mb-4">{{ section_title }} {{ marking_session.entity_name|default:"Council" }}s</h1>
<table class="table">
<thead>
<tr>
Expand Down
Loading
Loading