-
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.
basic form for bulk editing option scores
Add a view to allow all the scores for questions in a section to be edited in one go. Fixes #106
- Loading branch information
Showing
6 changed files
with
163 additions
and
1 deletion.
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
55 changes: 55 additions & 0 deletions
55
crowdsourcer/templates/crowdsourcer/questions/options.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,55 @@ | ||
{% extends 'crowdsourcer/base.html' %} | ||
|
||
{% load crowdsourcer_tags django_bootstrap5 static %} | ||
|
||
{% block content %} | ||
{% if show_login %} | ||
<h1 class="mb-4">Sign in</h1> | ||
<a href="{% url 'login' %}">Sign in</a> | ||
{% else %} | ||
<h3 class="mb-4">Scores for {{ section.title }} answers</h3> | ||
|
||
|
||
<form action="" method="post"> | ||
{% csrf_token %} | ||
{{ form.management_form }} | ||
<div class="container"> | ||
<div class="row border-bottom"> | ||
<div class="col-sm"> | ||
Description | ||
</div> | ||
|
||
<div class="col-sm"> | ||
Score | ||
</div> | ||
</div> | ||
{% for option_form in form %} | ||
{% ifchanged option_form.instance.question.number_and_part %} | ||
<fieldset class="pt-1"> | ||
<h5> | ||
{{ option_form.instance.question.number_and_part }} | ||
{{ option_form.instance.question.description }} | ||
</h5> | ||
{% endifchanged %} | ||
<div class="row py-0"> | ||
<div class="col-sm"> | ||
<div class="mb-dd-4"> | ||
{{ option_form.instance.description }} | ||
</div> | ||
</div> | ||
|
||
<div class="col-sm"> | ||
{{ option_form.score }} | ||
</div> | ||
</div> | ||
{{ option_form.id }} | ||
{% ifchanged option_form.instance.question.number_and_part %} | ||
</fieldset> | ||
{% endifchanged %} | ||
{% endfor %} | ||
</div> | ||
<input type="submit" class="btn btn-primary" value="Update"> | ||
</form> | ||
|
||
{% endif %} | ||
{% endblock %} |
20 changes: 20 additions & 0 deletions
20
crowdsourcer/templates/crowdsourcer/questions/sections.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,20 @@ | ||
{% 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 %} | ||
<div class="d-md-flex align-items-center mb-4"> | ||
<h1 class="mb-md-0 me-md-auto">Sections</h1> | ||
</div> | ||
|
||
<ul> | ||
{% for section in sections %} | ||
<li><a href="{% session_url 'edit_options' section.title %}">{{ section.title }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% 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,59 @@ | ||
from django.contrib.auth.mixins import UserPassesTestMixin | ||
from django.shortcuts import get_object_or_404 | ||
from django.urls import reverse | ||
from django.views.generic import FormView, ListView | ||
|
||
from crowdsourcer.forms import OptionFormset | ||
from crowdsourcer.models import Option, Section | ||
|
||
|
||
class SectionList(ListView): | ||
template_name = "crowdsourcer/questions/sections.html" | ||
context_object_name = "sections" | ||
|
||
def get_queryset(self): | ||
return Section.objects.filter(marking_session=self.request.current_session) | ||
|
||
|
||
class OptionsView(UserPassesTestMixin, FormView): | ||
template_name = "crowdsourcer/questions/options.html" | ||
form_class = OptionFormset | ||
|
||
def test_func(self): | ||
return self.request.user.has_perm("crowdsourcer.can_manage_users") | ||
|
||
def get_success_url(self): | ||
return reverse( | ||
"session_urls:edit_options", | ||
kwargs={ | ||
"marking_session": self.request.current_session.label, | ||
"section_name": "Buildings & Heating", | ||
}, | ||
) | ||
|
||
def get_form(self): | ||
self.section = get_object_or_404( | ||
Section, | ||
title=self.kwargs["section_name"], | ||
marking_session=self.request.current_session, | ||
) | ||
|
||
options = ( | ||
Option.objects.filter( | ||
question__section=self.section, | ||
) | ||
.order_by("question__number", "question__number_part", "ordering") | ||
.select_related("question") | ||
) | ||
return self.form_class(queryset=options, **self.get_form_kwargs()) | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
|
||
context["section"] = self.section | ||
|
||
return context | ||
|
||
def form_valid(self, form): | ||
form.save() | ||
return super().form_valid(form) |