-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
195 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
crowdsourcer/migrations/0046_questiongroup_marking_session.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
crowdsourcer/migrations/0047_markingsession_entity_name.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
crowdsourcer/templates/crowdsourcer/cobrand/navbar_default.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
5 changes: 5 additions & 0 deletions
5
crowdsourcer/templates/crowdsourcer/cobrand/navbar_mysociety.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.