-
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.
Allows uploading a CSV with updated responses to a question for bulk editing
- Loading branch information
Showing
9 changed files
with
383 additions
and
5 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
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
21 changes: 21 additions & 0 deletions
21
crowdsourcer/templates/crowdsourcer/questions/question_bulk_upload.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,21 @@ | ||
{% extends 'crowdsourcer/base.html' %} | ||
|
||
{% load crowdsourcer_tags django_bootstrap5 %} | ||
|
||
{% block content %} | ||
{% if show_login %} | ||
<h1 class="mb-4">Sign in</h1> | ||
<a href="{% url 'login' %}">Sign in</a> | ||
{% else %} | ||
<h1 class="mb-4">Update Responses for {{ section.title }} {{ question.number_and_part }}</h1> | ||
<h4 class="mb-4">{{ question.description }}</h4> | ||
|
||
|
||
<form enctype="multipart/form-data" action="" method="post"> | ||
{% csrf_token %} | ||
{% bootstrap_form form %} | ||
<input type="submit" value="Update"> | ||
</form> | ||
|
||
{% endif %} | ||
{% endblock %} |
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,4 @@ | ||
authority,answer,score,public_notes,page_number,evidence,private_notes | ||
Aberdeen City Council,Yes,1,uploaded public notes,99,uploaded evidence,uploaded private notes | ||
Aberdeenshire Council,No,0,,,, | ||
Adur District Council,-,-,-,-,-,- |
4 changes: 4 additions & 0 deletions
4
crowdsourcer/tests/data/test_question_upload_one_unchanged.csv
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,4 @@ | ||
authority,answer,score,public_notes,page_number,evidence,private_notes | ||
Aberdeen City Council,Yes,1,uploaded public notes,99,uploaded evidence,uploaded private notes | ||
Aberdeenshire Council,Yes,0,public notrs,0,,private notes | ||
Adur District Council,-,-,-,-,-,- |
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,125 @@ | ||
import pathlib | ||
|
||
from django.contrib.auth.models import Permission, User | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
from crowdsourcer.models import Question, Response | ||
|
||
|
||
class BaseTestCase(TestCase): | ||
fixtures = [ | ||
"authorities.json", | ||
"basics.json", | ||
"users.json", | ||
"questions.json", | ||
"options.json", | ||
"assignments.json", | ||
"responses.json", | ||
] | ||
|
||
def setUp(self): | ||
p = Permission.objects.get(codename="can_manage_users") | ||
u = User.objects.get(username="volunteer_admin") | ||
u.user_permissions.add(p) | ||
|
||
self.client.force_login(u) | ||
self.user = u | ||
|
||
|
||
class TestBulkUpload(BaseTestCase): | ||
def test_one_update_one_new(self): | ||
url = reverse("question_bulk_update", args=("Transport", "1")) | ||
response = self.client.get(url) | ||
|
||
q = Question.objects.get( | ||
section__title="Transport", | ||
section__marking_session__label="Default", | ||
number=1, | ||
) | ||
|
||
all_r = Response.objects.filter(question=q, response_type__type="First Mark") | ||
self.assertEqual(all_r.count(), 1) | ||
|
||
r = Response.objects.get(question=q, authority__name="Aberdeenshire Council") | ||
|
||
self.assertEqual(r.option.description, "Yes") | ||
self.assertEqual(r.page_number, "0") | ||
|
||
upload_file = ( | ||
pathlib.Path(__file__).parent.resolve() | ||
/ "data" | ||
/ "test_question_upload.csv" | ||
) | ||
|
||
with open(upload_file, "rb") as fp: | ||
response = self.client.post( | ||
url, | ||
data={ | ||
"question": 281, | ||
"updated_responses": fp, | ||
"stage": "First Mark", | ||
}, | ||
) | ||
|
||
self.assertRedirects(response, "/Default" + url) | ||
self.assertEqual(all_r.count(), 2) | ||
|
||
r = Response.objects.get(question=q, authority__name="Aberdeen City Council") | ||
|
||
self.assertEqual(r.option.description, "Yes") | ||
self.assertEqual(r.page_number, "99") | ||
|
||
r = Response.objects.get(question=q, authority__name="Aberdeenshire Council") | ||
|
||
self.assertEqual(r.option.description, "No") | ||
self.assertEqual(r.page_number, None) | ||
|
||
def test_one_new_one_unchanged(self): | ||
url = reverse("question_bulk_update", args=("Transport", "1")) | ||
response = self.client.get(url) | ||
|
||
q = Question.objects.get( | ||
section__title="Transport", | ||
section__marking_session__label="Default", | ||
number=1, | ||
) | ||
|
||
all_r = Response.objects.filter(question=q, response_type__type="First Mark") | ||
self.assertEqual(all_r.count(), 1) | ||
|
||
r = Response.objects.get(question=q, authority__name="Aberdeenshire Council") | ||
|
||
last_update = r.last_update | ||
self.assertEqual(r.option.description, "Yes") | ||
self.assertEqual(r.page_number, "0") | ||
|
||
upload_file = ( | ||
pathlib.Path(__file__).parent.resolve() | ||
/ "data" | ||
/ "test_question_upload_one_unchanged.csv" | ||
) | ||
|
||
with open(upload_file, "rb") as fp: | ||
response = self.client.post( | ||
url, | ||
data={ | ||
"question": 281, | ||
"updated_responses": fp, | ||
"stage": "First Mark", | ||
}, | ||
) | ||
|
||
self.assertRedirects(response, "/Default" + url) | ||
self.assertEqual(all_r.count(), 2) | ||
|
||
r = Response.objects.get(question=q, authority__name="Aberdeen City Council") | ||
|
||
self.assertEqual(r.option.description, "Yes") | ||
self.assertEqual(r.page_number, "99") | ||
|
||
r = Response.objects.get(question=q, authority__name="Aberdeenshire Council") | ||
|
||
self.assertEqual(r.option.description, "Yes") | ||
self.assertEqual(r.page_number, "0") | ||
self.assertEqual(last_update, r.last_update) |
Oops, something went wrong.