Skip to content

Commit

Permalink
response history pages
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Aug 8, 2024
1 parent 510a8f1 commit 5cdd68f
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ceuk-marking/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@
stats.DuplicateResponsesView.as_view(),
name="duplicate_responses",
),
path(
"stats/response_history/",
stats.CouncilHistoryListView.as_view(),
name="select_council_for_history",
),
path(
"stats/response_history/<authority>/",
stats.CouncilQuestionHistoryListView.as_view(),
name="question_history_list",
),
path(
"stats/response_history/<authority>/<stage>/<question>/",
stats.ResponseHistoryView.as_view(),
name="question_history",
),
# audit screens
path(
"section/audit/<section_title>/authorities/",
Expand Down
68 changes: 68 additions & 0 deletions crowdsourcer/templates/crowdsourcer/response_history.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{% extends 'crowdsourcer/base.html' %}

{% load crowdsourcer_tags %}

{% block content %}
{% if show_login %}
<h1 class="mb-4">Sign in</h1>
<a href="{% url 'login' %}">Sign in</a>
{% else %}
<h1 class="mb-4">Reponse History</h1>

{% if missing_question %}
<p>
Could not find that question
</p>
{% else %}
<h3 class="mb-3">{{ question.section.title }}: {{ question }}</h3>
{% if responses is None %}
<p>
No responses to that question so far.
</p>
{% else %}
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>User</th>
<th>Response</th>
<th>Notes</th>
<th>Links</th>
<th>Private notes</th>
</tr>
</thead>
<tbody>
{% for response in responses %}
<tr>
<td>
{{ response.history_date }}
</td>
<td>
{{ response.user }}
</td>
<td>
{% if response.multi_option %}
{% for r in response.multi_option %}
{{ r }},
{% endfor %}
{% else %}
{{ response.option }}
{% endif %}
</td>
<td>
{{ response.evidence }}
</td>
<td>
{{ response.public_notes }}
</td>
<td>
{{ response.private_notes }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% endif %}
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends 'crowdsourcer/base.html' %}

{% load crowdsourcer_tags %}

{% block content %}
{% if show_login %}
<h1 class="mb-4">Sign in</h1>
<a href="{% url 'login' %}">Sign in</a>
{% else %}
<h1 class="mb-4">{{ session.entity_name }} History</h1>
<p>
Click on an authority to see the list of questions for that authority.
</p>

<table class="table sticky-head-table">
<tbody>
{% for authority in authorities %}
<tr>
<td class="align-middle">
<a href="{% session_url 'question_history_list' authority.name %}" class="d-flex align-items-center">
{{ authority.name }}
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% extends 'crowdsourcer/base.html' %}

{% load crowdsourcer_tags %}

{% block content %}
{% if show_login %}
<h1 class="mb-4">Sign in</h1>
<a href="{% url 'login' %}">Sign in</a>
{% else %}
<h1 class="mb-4">Question Data</h1>
<table class="table sticky-head-table">
<thead>
<tr>
<th>Question</th>
<th>First Mark</th>
<th>Right of Reply</th>
<th>Audit</th>
</tr>
</thead>
{% for section, data in sections.items %}
<tbody>
<tr class="sticky-subhead">
<td class="align-middle h5 lh-1" colspan="4">{{ section }}</td>
</tr>
{% for q in data %}
<tr>
<td class="align-middle">
{{ q.number_and_part }} - {{ q.description }}
</td>
<td class="align-middle">
<a href="{% session_url 'question_history' authority.name 'First Mark' q.id %}" class="d-flex align-items-center">
View
</a>
</td>
<td class="align-middle">
<a href="{% session_url 'question_history' authority.name 'Right of Reply' q.id %}" class="d-flex align-items-center">
View
</a>
</td>
<td class="align-middle">
<a href="{% session_url 'question_history' authority.name 'Audit' q.id %}" class="d-flex align-items-center">
View
</a>
</td>
</tr>
{% endfor %}
</tbody>
{% endfor %}
</table>
{% endif %}
{% endblock %}
3 changes: 3 additions & 0 deletions crowdsourcer/templates/crowdsourcer/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ <h1 class="mb-4">{{ page_title }}</h1>
<span class="me-3">All answer data</span>
{% include 'crowdsourcer/includes/csv-badge.html' %}
</a>
<a class="list-group-item list-group-item-action d-flex align-items-center justify-content-between" href="{% session_url 'select_council_for_history' %}">
Question response history
</a>
</div>
{% endif %}
{% endblock %}
74 changes: 74 additions & 0 deletions crowdsourcer/views/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,3 +677,77 @@ def get_context_data(self, **kwargs):
context["dupes"] = dupes

return context


class CouncilHistoryListView(StatsUserTestMixin, ListView):
context_object_name = "authorities"
template_name = "crowdsourcer/response_history_authorities.html"

def get_queryset(self):
return PublicAuthority.objects.filter(
marking_session=self.request.current_session
).order_by("name")


class CouncilQuestionHistoryListView(SelectQuestionView):
template_name = "crowdsourcer/response_history_questions.html"

def get_queryset(self):
try:
authority = PublicAuthority.objects.get(name=self.kwargs["authority"])
except PublicAuthority.DoesNotExist:
return None

return (
Question.objects.filter(
questiongroup=authority.questiongroup,
section__marking_session=self.request.current_session,
)
.select_related("section")
.order_by("section__title", "number", "number_part")
)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

try:
authority = PublicAuthority.objects.get(name=self.kwargs["authority"])
context["authority"] = authority
except PublicAuthority.DoesNotExist:
context["no_authority"] = True

return context


class ResponseHistoryView(StatsUserTestMixin, ListView):
context_object_name = "responses"
template_name = "crowdsourcer/response_history.html"

def get_queryset(self):
stage = self.kwargs["stage"]
authority = self.kwargs["authority"]
question = self.kwargs["question"]

try:
response = Response.objects.get(
question__section__marking_session=self.request.current_session,
question_id=question,
authority__name=authority,
response_type__type=stage,
)
except Response.DoesNotExist:
return None
return response.history.all()

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

try:
context["question"] = Question.objects.get(
section__marking_session=self.request.current_session,
id=self.kwargs["question"],
)
except Question.DoesNotExist:
context["missing_question"] = True

return context

0 comments on commit 5cdd68f

Please sign in to comment.