Skip to content

Commit c55af09

Browse files
committed
WIP
1 parent 6af8b00 commit c55af09

22 files changed

+186
-31
lines changed

ceuk-marking/settings.py

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
ALLOWED_HOSTS=(list, []),
3131
HIDE_DEBUG_TOOLBAR=(bool, False),
3232
LOG_LEVEL=(str, "WARNING"),
33+
BRAND=(str, "default"),
3334
)
3435
environ.Env.read_env(BASE_DIR / ".env")
3536

@@ -41,6 +42,7 @@
4142
MAPIT_URL = env("MAPIT_URL")
4243
MAPIT_API_KEY = env("MAPIT_API_KEY")
4344
LOG_LEVEL = env("LOG_LEVEL")
45+
BRAND = env("BRAND")
4446

4547
# make sure CSRF checking still works behind load balancers
4648
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from django.conf import settings
2+
from django.core.management.base import BaseCommand
3+
4+
import pandas as pd
5+
6+
from crowdsourcer.models import (
7+
MarkingSession,
8+
PublicAuthority,
9+
QuestionGroup,
10+
ResponseType,
11+
Section,
12+
)
13+
from utils import mapit
14+
15+
16+
class Command(BaseCommand):
17+
help = "set up authorities and question groups"
18+
19+
groups = ["MP"]
20+
21+
sections = [
22+
"Who Funds Them",
23+
]
24+
25+
session = "WhoFundsThem 2024"
26+
27+
response_types = ["First Mark", "Right of Reply", "Audit"]
28+
29+
def add_arguments(self, parser):
30+
parser.add_argument(
31+
"-q", "--quiet", action="store_true", help="Silence progress bars."
32+
)
33+
34+
def get_group(self, mp):
35+
return QuestionGroup.objects.get(description="MP")
36+
37+
def get_do_not_mark_list(self):
38+
df = pd.read_csv(self.do_not_mark_file)
39+
return list(df["gss-code"])
40+
41+
def get_twfy_df(self):
42+
df = pd.read_csv("https://www.theyworkforyou.com/mps/?f=csv").rename(
43+
columns={"Person ID": "twfyid"}
44+
)
45+
46+
return df
47+
48+
def handle(self, quiet: bool = False, *args, **options):
49+
session, _ = MarkingSession.objects.get_or_create(
50+
label=self.session, defaults={"start_date": "2024-06-01"}
51+
)
52+
53+
for section in self.sections:
54+
c, c = Section.objects.get_or_create(title=section, marking_session=session)
55+
56+
for group in self.groups:
57+
g, c = QuestionGroup.objects.get_or_create(description=group)
58+
g.marking_session.set([session])
59+
60+
for r_type in self.response_types:
61+
r, c = ResponseType.objects.get_or_create(type=r_type, priority=1)
62+
63+
mps = self.get_twfy_df()
64+
65+
if not quiet:
66+
print("Importing MPs")
67+
for _, mp in mps.iterrows():
68+
do_not_mark = False
69+
70+
name = f"{mp['First name']} {mp['Last name']}"
71+
defaults = {
72+
"name": name,
73+
"questiongroup": self.get_group(mp),
74+
"do_not_mark": do_not_mark,
75+
"type": "MP",
76+
}
77+
78+
a, created = PublicAuthority.objects.update_or_create(
79+
unique_id=mp["twfyid"],
80+
defaults=defaults,
81+
)

crowdsourcer/middleware.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from django.conf import settings
2+
13
from crowdsourcer.models import MarkingSession, ResponseType
24

35

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

3133
context["marking_session"] = request.current_session
3234
context["sessions"] = MarkingSession.objects.filter(active=True)
35+
context["brand"] = settings.BRAND
36+
context[
37+
"brand_include"
38+
] = f"crowdsourcer/cobrand/navbar_{context['brand']}.html"
3339

3440
response.context_data = context
3541

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.11 on 2024-05-08 12:52
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("crowdsourcer", "0045_markingsession_stage"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="questiongroup",
15+
name="marking_session",
16+
field=models.ManyToManyField(to="crowdsourcer.markingsession"),
17+
),
18+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.11 on 2024-05-08 16:06
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("crowdsourcer", "0046_questiongroup_marking_session"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="markingsession",
15+
name="entity_name",
16+
field=models.TextField(blank=True, max_length=200, null=True),
17+
),
18+
]

crowdsourcer/models.py

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class MarkingSession(models.Model):
1919
start_date = models.DateField()
2020
active = models.BooleanField(default=False)
2121
stage = models.ForeignKey("ResponseType", null=True, on_delete=models.SET_NULL)
22+
entity_name = models.TextField(max_length=200, null=True, blank=True)
2223

2324
def __str__(self):
2425
return self.label
@@ -42,6 +43,7 @@ class QuestionGroup(models.Model):
4243
"""
4344

4445
description = models.TextField(max_length=200)
46+
marking_session = models.ManyToManyField(MarkingSession)
4547

4648
def __str__(self):
4749
return self.description

crowdsourcer/scoring.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,9 @@ def get_blank_section_scores(session):
337337
).values_list("title", flat=True)
338338
}
339339

340-
for council in PublicAuthority.objects.filter(do_not_mark=False).all():
340+
for council in PublicAuthority.objects.filter(
341+
questiongroup__marking_session=session, do_not_mark=False
342+
).all():
341343
if council.type == "COMB":
342344
weighted[council.name] = ca_sections.copy()
343345
raw_scores[council.name] = ca_sections.copy()
@@ -561,7 +563,9 @@ def get_scoring_object(session):
561563
scoring["council_type"] = types
562564
scoring["council_control"] = control
563565
scoring["councils"] = {}
564-
for council in PublicAuthority.objects.all():
566+
for council in PublicAuthority.objects.filter(
567+
questiongroup__marking_session=session
568+
):
565569
scoring["councils"][council.name] = council
566570

567571
get_section_maxes(scoring, session)
4.2 KB
Loading
Loading

crowdsourcer/templates/crowdsourcer/all_section_challenge.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ <h1 class="mb-4">Section Right of Reply Progress and Challenges</h1>
2424
{% widthratio counts.complete counts.total 100 as width %}
2525
<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>
2626
</div>
27-
<span id="label-{{ forloop.counter }}">{{ counts.complete }} of {{ counts.total }} councils completed. ({{ counts.started }} started, {{ counts.challenges }} challenges)</span>
27+
<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>
2828
</td>
2929
</tr>
3030
{% endfor %}

crowdsourcer/templates/crowdsourcer/all_section_progress.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h1 class="mb-4">Section Progress</h1>
2626
{% widthratio counts.complete counts.total 100 as width %}
2727
<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>
2828
</div>
29-
<span id="label-{{ forloop.counter }}">{{ counts.complete }} of {{ counts.total }} councils completed. ({{ counts.started }} started, {{ counts.assigned }} assigned)</span>
29+
<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>
3030
</td>
3131
</tr>
3232
{% endfor %}

crowdsourcer/templates/crowdsourcer/assignments.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h1 class="mb-4">{% if show_users %}All{% else %}Your{% endif %} assignments</h1
3434
{% widthratio assignment.complete assignment.total 100 as width %}
3535
<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>
3636
</div>
37-
<span id="label-{{ forloop.counter }}">{{ assignment.complete }} of {{ assignment.total }} authorities completed</span>
37+
<span id="label-{{ forloop.counter }}">{{ assignment.complete }} of {{ assignment.total }} {{ marking_session.entity_name|default:"council" }}{{ assignment.total|pluralize }} completed</span>
3838
</td>
3939
</tr>
4040
{% empty %}

crowdsourcer/templates/crowdsourcer/authorities_assigned.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<h1 class="mb-4">Sign in</h1>
66
<a href="{% url 'login' %}">Sign in</a>
77
{% else %}
8-
<h1 class="mb-4">Authority Assigned</h1>
8+
<h1 class="mb-4">{{ marking_session.entity_name }} Assigned</h1>
99
<table class="table">
1010
<thead>
1111
<tr>
12-
<th>Authority {% if do_not_mark_only %}<a href="./">ALL</a>{% else %}<a href="?do_not_mark_only=1">DNM</a>{% endif %}</th>
12+
<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>
1313
<th>Sections Assigned <a href="?sort=asc">&#9650;</a>/<a href="?sort=desc">&#9660;</a></th>
1414
</tr>
1515
</thead>

crowdsourcer/templates/crowdsourcer/base.html

+9-12
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
<body>
1414
<nav class="navbar navbar-expand-sm bg-light border-bottom site-header">
1515
<div class="container">
16-
<a class="navbar-brand d-flex align-items-center" href="{% url 'home' %}">
17-
<img src="{% static 'img/ceuk-logo.png' %}" alt="Climate Emergency UK" width="290" height="100" class="me-3">
18-
GRACE
19-
</a>
16+
{% include brand_include %}
2017
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
2118
<span class="navbar-toggler-icon"></span>
2219
</button>
@@ -44,10 +41,10 @@
4441
</button>
4542
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
4643
<li>
47-
<a class="dropdown-item d-flex" href="{% session_url 'authority_assignments' %}">Authorities assigned</a>
44+
<a class="dropdown-item d-flex" href="{% session_url 'authority_assignments' %}">{{ marking_session.entity_name|default:"Council" }}s assigned</a>
4845
</li>
4946
<li>
50-
<a class="dropdown-item d-flex" href="{% session_url 'all_authority_progress' %}">Authority Progress</a>
47+
<a class="dropdown-item d-flex" href="{% session_url 'all_authority_progress' %}">{{ marking_session.entity_name|default:"Council" }} Progress</a>
5148
</li>
5249
<li>
5350
<a class="dropdown-item d-flex" href="{% session_url 'all_section_progress' %}">Section Progress</a>
@@ -65,16 +62,16 @@
6562
</button>
6663
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
6764
<li>
68-
<a class="dropdown-item d-flex" href="{% session_url 'all_authority_ror_progress' %}">Authority Progress</a>
65+
<a class="dropdown-item d-flex" href="{% session_url 'all_authority_ror_progress' %}">{{ marking_session.entity_name|default:"Council" }} Progress</a>
6966
</li>
7067
<li>
71-
<a class="dropdown-item d-flex" href="{% session_url 'authority_login_report' %}">Authority Login Report</a>
68+
<a class="dropdown-item d-flex" href="{% session_url 'authority_login_report' %}">{{ marking_session.entity_name|default:"Council" }} Login Report</a>
7269
</li>
7370
<li>
7471
<a class="dropdown-item d-flex" href="{% session_url 'section_ror_progress' %}">Section Progress</a>
7572
</li>
7673
<li>
77-
<a class="dropdown-item d-flex" href="{% session_url 'authority_contacts_report' %}">Authority Contacts</a>
74+
<a class="dropdown-item d-flex" href="{% session_url 'authority_contacts_report' %}">{{ marking_session.entity_name|default:"Council" }} Contacts</a>
7875
</li>
7976
</ul>
8077
</div>
@@ -95,7 +92,7 @@
9592
<a class="dropdown-item d-flex" href="{% session_url 'all_audit_marks_csv' %}">Audit Mark Scores</a>
9693
</li>
9794
<li>
98-
<a class="dropdown-item d-flex" href="{% session_url 'council_disagree_mark_csv' %}">Council disagree with positive mark</a>
95+
<a class="dropdown-item d-flex" href="{% session_url 'council_disagree_mark_csv' %}">{{ marking_session.entity_name|default:"Council" }} disagree with positive mark</a>
9996
</li>
10097
<li>
10198
<a class="dropdown-item d-flex" href="{% session_url 'stats_select_question' %}">Per question data</a>
@@ -127,10 +124,10 @@
127124
</button>
128125
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
129126
<li>
130-
<a class="dropdown-item d-flex" href="{% session_url 'audit_authority_assignments' %}">Authorities assigned</a>
127+
<a class="dropdown-item d-flex" href="{% session_url 'audit_authority_assignments' %}">{{ marking_session.entity_name|default:"Council" }}s assigned</a>
131128
</li>
132129
<li>
133-
<a class="dropdown-item d-flex" href="{% session_url 'audit_all_authority_progress' %}">Authority Progress</a>
130+
<a class="dropdown-item d-flex" href="{% session_url 'audit_all_authority_progress' %}">{{ marking_session.entity_name|default:"Council" }} Progress</a>
134131
</li>
135132
<li>
136133
<a class="dropdown-item d-flex" href="{% session_url 'audit_all_section_progress' %}">Section Progress</a>

crowdsourcer/templates/crowdsourcer/base_all_authority_progress.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h1 class="mb-4">{{ page_title }}</h1>
1111
<table class="table">
1212
<thead>
1313
<tr>
14-
<th>Authority</th>
14+
<th>{{ marking_session.entity_name|default:"Council" }}</th>
1515
<th>Progress <a href="?sort=asc">&#9650;</a>/<a href="?sort=desc">&#9660;</a></th>
1616
</tr>
1717
</thead>
@@ -25,7 +25,7 @@ <h1 class="mb-4">{{ page_title }}</h1>
2525
{% widthratio councils.complete councils.total 100 as width %}
2626
<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>
2727
</div>
28-
<span id="label-{{ forloop.counter }}">{{ councils.complete }} of {{ councils.total }} councils completed</span>
28+
<span id="label-{{ forloop.counter }}">{{ councils.complete }} of {{ councils.total }} {{ marking_session.entity_name|default:"council" }}{{ councils.total|pluralize }} completed</span>
2929
</td>
3030
</tr>
3131
{% for authority in authorities %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% load static %}
2+
<a class="navbar-brand d-flex align-items-center" href="{% url 'home' %}">
3+
<img src="{% static 'img/ceuk-logo.png' %}" alt="Climate Emergency UK" width="290" height="100" class="me-3">
4+
GRACE
5+
</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% load static %}
2+
<a class="navbar-brand d-flex align-items-center" href="{% url 'home' %}">
3+
<img src="{% static 'img/mysoc_logo.png' %}" class="me-3">
4+
mySociety
5+
</a>

crowdsourcer/templates/crowdsourcer/section_progress.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h1 class="mb-4">{{ section.title }} Section Progress</h1>
1111
<table class="table">
1212
<thead>
1313
<tr>
14-
<th>Authority</th>
14+
<th>{{ marking_session.entity_name|default:"Council" }}</th>
1515
<th>Progress <a href="?sort=asc">&#9650;</a>/<a href="?sort=desc">&#9660;</a></th>
1616
</tr>
1717
</thead>
@@ -25,7 +25,7 @@ <h1 class="mb-4">{{ section.title }} Section Progress</h1>
2525
{% widthratio totals.complete totals.total 100 as width %}
2626
<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>
2727
</div>
28-
<span id="label-{{ forloop.counter }}">{{ totals.complete }} of {{ totals.total }} councils completed</span>
28+
<span id="label-{{ forloop.counter }}">{{ totals.complete }} of {{ totals.total }} {{ marking_session.entity_name|default:"council" }}{{ totals.total|pluralize }} completed</span>
2929
</td>
3030
</tr>
3131
{% for authority in authorities %}

crowdsourcer/templates/crowdsourcer/volunteer_progress.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ <h1 class="mb-4">Volunteer Progress: {{ user.first_name }} {{ user.last_name }}<
2929
{% widthratio section.totals.complete section.totals.total 100 as width %}
3030
<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>
3131
</div>
32-
<span id="label-{{ forloop.counter }}">{{ section.totals.complete }} of {{ section.totals.total }} councils completed</span>
32+
<span id="label-{{ forloop.counter }}">{{ section.totals.complete }} of {{ section.totals.total }} {{ marking_session.entity_name|default:"council" }}{{ section.totals.total|pluralize }} completed</span>
3333
</td>
3434
</tr>
3535
{% for authority in section.authorities %}

crowdsourcer/views/base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ def test_func(self):
343343

344344
def get_queryset(self):
345345
rt = ResponseType.objects.get(type=self.stage)
346-
qs = PublicAuthority.objects.all().annotate(
346+
qs = PublicAuthority.objects.filter(
347+
questiongroup__marking_session=self.request.current_session
348+
).annotate(
347349
num_sections=Subquery(
348350
Assigned.objects.filter(authority=OuterRef("pk"), response_type=rt)
349351
.values("authority")

0 commit comments

Comments
 (0)