Skip to content

Commit

Permalink
remove some unused views
Browse files Browse the repository at this point in the history
these were added as part of the initial prototype and never used to
removing
  • Loading branch information
struan committed Apr 30, 2024
1 parent 12f53e7 commit 4a370d8
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 247 deletions.
30 changes: 0 additions & 30 deletions ceuk-marking/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,46 +61,16 @@
name="authority_assignments",
),
# marking screens
path(
"section/<section_title>/questions/",
marking.SectionQuestionList.as_view(),
name="section_questions",
),
path(
"section/<section_title>/authorities/",
marking.SectionAuthorityList.as_view(),
name="section_authorities",
),
path(
"section/<section_title>/question/<slug:number>/",
marking.SectionQuestionAuthorityList.as_view(),
name="section_question_authorities",
),
path(
"authorities/<name>/section/<section_title>/question/<number>/",
marking.AuthorityQuestion.as_view(),
name="authority_question",
),
path(
"authorities/<name>/section/<section_title>/questions/",
marking.AuthoritySectionQuestions.as_view(),
name="authority_question_edit",
),
path(
"authorities/<name>/section/<section_title>/question/<number>/answer/",
marking.AuthorityQuestionAnswer.as_view(),
name="authority_question_answer",
),
path(
"authorities/<name>/section/<section_title>/question/<number>/edit/",
marking.AuthorityQuestionEdit.as_view(),
name="authority_question_edit",
),
path(
"authorities/<name>/section/<section_title>/question/<number>/view/",
marking.AuthorityQuestionView.as_view(),
name="authority_question_view",
),
# right of reply screens
path(
"authorities/<name>/ror/sections/",
Expand Down
20 changes: 0 additions & 20 deletions crowdsourcer/templates/crowdsourcer/authority_question.html

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

173 changes: 1 addition & 172 deletions crowdsourcer/views/marking.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@
from django.core.exceptions import PermissionDenied
from django.shortcuts import redirect
from django.urls import reverse
from django.views.generic import DetailView, ListView, TemplateView
from django.views.generic.base import RedirectView
from django.views.generic.edit import CreateView, UpdateView
from django.views.generic import ListView, TemplateView

from crowdsourcer.forms import ResponseForm
from crowdsourcer.mixins import CurrentStateMixin
from crowdsourcer.models import (
Assigned,
MarkingSession,
Option,
PublicAuthority,
Question,
Response,
ResponseType,
Section,
)
from crowdsourcer.views.base import BaseQuestionView, BaseSectionAuthorityList

Expand Down Expand Up @@ -207,48 +201,6 @@ class SectionAuthorityList(BaseSectionAuthorityList):
pass


class SectionQuestionList(CurrentStateMixin, ListView):
template_name = "crowdsourcer/section_question_list.html"
model = Section
context_object_name = "questions"

def get_queryset(self):
if self.request.user.is_anonymous:
return None

section = Section.objects.get(
title=self.kwargs["section_title"], marking_session=self.current_session
)
return Question.objects.filter(section=section).order_by("number")


class SectionQuestionAuthorityList(CurrentStateMixin, ListView):
template_name = "crowdsourcer/section_question_authority_list.html"
model = Question
context_object_name = "authorities"

def get_queryset(self):
if self.request.user.is_anonymous:
return None

question = Question.objects.get(
number=self.kwargs["number"],
section__title=self.kwargs["section_title"],
section__marking_session=self.current_session,
)
return PublicAuthority.objects.filter(
questiongroup__question=question
).order_by("name")

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
question = Question.objects.get(
number=self.kwargs["number"], section__title=self.kwargs["section_title"]
)
context["question"] = question
return context


class AuthoritySectionQuestions(BaseQuestionView):
template_name = "crowdsourcer/authority_questions.html"

Expand Down Expand Up @@ -290,126 +242,3 @@ def process_form(self, form):
logger.debug(
f"option is {cleaned_data.get('option', None)}, multi is {cleaned_data.get('multi_option', None)}"
)


class AuthorityQuestion(RedirectView):
def get_redirect_url(self, *args, **kwargs):
kwargs = {
"name": self.kwargs["name"],
"section_title": self.kwargs["section_title"],
"number": self.kwargs["number"],
}
if not Assigned.is_user_assigned(
self.request.user,
authority=self.kwargs["name"],
section=self.kwargs["section_title"],
):
return reverse("authority_question_view", kwargs=kwargs)

try:
Response.objects.get(
authority__name=self.kwargs["name"],
question__number=self.kwargs["number"],
question__section__title=self.kwargs["section_title"],
question__section__marking_session=self.current_session,
)
except Response.DoesNotExist:
return reverse("authority_question_answer", kwargs=kwargs)

return reverse("authority_question_edit", kwargs=kwargs)


class AuthorityQuestionAnswer(CreateView):
template_name = "crowdsourcer/authority_question.html"
model = Response
form_class = ResponseForm

def get_initial(self):
if not Assigned.is_user_assigned(
self.request.user,
authority=self.kwargs["name"],
section=self.kwargs["section_title"],
):
raise PermissionDenied

authority = PublicAuthority.objects.get(name=self.kwargs["name"])
question = Question.objects.get(
number=self.kwargs["number"], section__title=self.kwargs["section_title"]
)

return {
"question": question,
"authority": authority,
}

def form_valid(self, form):
form.instance.user = self.request.user
return super().form_valid(form)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
form = context["form"]
question = form.initial["question"]
context["options"] = Option.objects.filter(question=question)
form.fields["option"].choices = [
(c.id, c.description) for c in Option.objects.filter(question=question)
]
context["form"] = form

context["authority"] = form.initial["authority"]

return context


class AuthorityQuestionView(DetailView):
template_name = "crowdsourcer/authority_question_view.html"
model = Response
context_object_name = "response"

def get_object(self):
response = Response.objects.get(
authority__name=self.kwargs["name"],
question__number=self.kwargs["number"],
question__section__title=self.kwargs["section_title"],
)

return response


class AuthorityQuestionEdit(UpdateView):
template_name = "crowdsourcer/authority_question.html"
model = Response
form_class = ResponseForm

def get_object(self):
if not Assigned.is_user_assigned(
self.request.user,
authority=self.kwargs["name"],
section=self.kwargs["section_title"],
):
raise PermissionDenied
response = Response.objects.get(
authority__name=self.kwargs["name"],
question__number=self.kwargs["number"],
question__section__title=self.kwargs["section_title"],
)

return response

def form_valid(self, form):
form.instance.user = self.request.user
return super().form_valid(form)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
form = context["form"]
question = form.initial["question"]
context["options"] = Option.objects.filter(question=question)
form.fields["option"].choices = [
(c.id, c.description) for c in Option.objects.filter(question=question)
]
context["form"] = form

context["authority"] = form.initial["authority"]

return context

0 comments on commit 4a370d8

Please sign in to comment.