add context to cloning forms
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
{% extends "anatomy/exams.html" %}
|
||||
|
||||
{% block js %}
|
||||
{{ form.media }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Add Exam</h2>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
{% endblock %}
|
||||
+1
-1
@@ -805,7 +805,7 @@ class ExamCreate(ExamCreateBase):
|
||||
form_class = ExamForm
|
||||
|
||||
|
||||
class ExamUpdate(CheckCanEditMixin, ExamUpdateBase, AuthorOrCheckerRequiredMixin):
|
||||
class ExamUpdate(ExamUpdateBase, AuthorOrCheckerRequiredMixin):
|
||||
model = Exam
|
||||
form_class = ExamForm
|
||||
|
||||
|
||||
@@ -783,6 +783,9 @@ class CaseCollection(ExamOrCollectionGenericBase):
|
||||
def get_app_name(self):
|
||||
return "atlas"
|
||||
|
||||
def get_base_template(self):
|
||||
return "atlas/base.html"
|
||||
|
||||
def get_link_headers(self):
|
||||
return f"{self.get_app_name()}/collection_headers.html"
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
{% extends 'atlas/exams.html' %}
|
||||
|
||||
{% block content %}
|
||||
<h2>{{collection.name}}</h2>
|
||||
|
||||
{% include 'exam_notes.html' %}
|
||||
<div>
|
||||
Exam mode: {{collection.exam_mode}}<br />
|
||||
Publish results: {{collection.publish_results}}<br />
|
||||
|
||||
@@ -16,7 +16,3 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<h2>{{collection.name}}</h2>
|
||||
|
||||
{% include 'exam_notes.html' %}
|
||||
|
||||
+20
-5
@@ -49,7 +49,7 @@ from generic.decorators import user_is_cid_user_manager
|
||||
from generic.filters import CidUserFilter, ExaminationFilter
|
||||
|
||||
from generic.tables import CidUserExamTable, CidUserTable, ExaminationTable
|
||||
from generic.mixins import SuperuserRequiredMixin
|
||||
from generic.mixins import CheckCanEditMixin, SuperuserRequiredMixin
|
||||
|
||||
import zipfile
|
||||
from django.core.files.base import ContentFile
|
||||
@@ -2433,11 +2433,16 @@ class GenericViewBase:
|
||||
)
|
||||
|
||||
|
||||
class ExamCloneMixin:
|
||||
class ExamCloneMixin():
|
||||
def get_template_names(self) -> list[str]:
|
||||
return "exam_clone_form.html"
|
||||
#return super().get_template_names()
|
||||
|
||||
|
||||
def get_initial(self):
|
||||
old_object = get_object_or_404(self.model, pk=self.kwargs["exam_id"])
|
||||
|
||||
if self.request.user not in old_object.get_author_objects() and not self.request.user.is_superuser:
|
||||
if not old_object.check_user_can_edit(self.request.user):
|
||||
raise PermissionDenied() # or Http404
|
||||
|
||||
initial_data = model_to_dict(old_object, exclude=["id"])
|
||||
@@ -2458,8 +2463,18 @@ class ExamCloneMixin:
|
||||
self.exam_questions = list(questions)
|
||||
self.author = list(authors)
|
||||
|
||||
self.old_object = old_object
|
||||
|
||||
return initial_data
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context["can_edit"] = self.old_object.check_user_can_edit(self.request.user)
|
||||
context["exam"] = self.old_object
|
||||
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
object = form.save()
|
||||
# Reapply these otherwise they get lost?
|
||||
@@ -3158,7 +3173,7 @@ class ExamCreateBase(RevisionMixin, LoginRequiredMixin, CreateView):
|
||||
return kwargs
|
||||
|
||||
|
||||
class ExamUpdateBase(RevisionMixin, LoginRequiredMixin, UpdateView):
|
||||
class ExamUpdateBase(RevisionMixin, CheckCanEditMixin, LoginRequiredMixin, UpdateView):
|
||||
template_name = "exam_update_form.html"
|
||||
|
||||
def form_valid(self, form):
|
||||
@@ -3175,7 +3190,7 @@ class ExamUpdateBase(RevisionMixin, LoginRequiredMixin, UpdateView):
|
||||
return kwargs
|
||||
|
||||
|
||||
class ExamDeleteBase(RevisionMixin, DeleteView):
|
||||
class ExamDeleteBase(RevisionMixin, CheckCanEditMixin, DeleteView):
|
||||
template_name = "exam_confirm_delete.html"
|
||||
|
||||
def get_success_url(self) -> str:
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
{% extends "longs/exams.html" %}
|
||||
|
||||
{% block js %}
|
||||
{{ form.media }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Add Exam</h2>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
{% endblock %}
|
||||
+1
-1
@@ -1130,7 +1130,7 @@ class ExamCreate(ExamCreateBase):
|
||||
form_class = ExamForm
|
||||
|
||||
|
||||
class ExamUpdate(CheckCanEditMixin, ExamUpdateBase, AuthorOrCheckerRequiredMixin):
|
||||
class ExamUpdate(ExamUpdateBase, AuthorOrCheckerRequiredMixin):
|
||||
model = Exam
|
||||
form_class = ExamForm
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
{% extends "physics/exams.html" %}
|
||||
|
||||
{% block js %}
|
||||
{{ form.media }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Add Exam</h2>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
{% endblock %}
|
||||
+1
-1
@@ -339,7 +339,7 @@ class ExamCreate(ExamCreateBase):
|
||||
form_class = ExamForm
|
||||
|
||||
|
||||
class ExamUpdate(CheckCanEditMixin, ExamUpdateBase, AuthorOrCheckerRequiredMixin):
|
||||
class ExamUpdate(ExamUpdateBase, AuthorOrCheckerRequiredMixin):
|
||||
model = Exam
|
||||
form_class = ExamForm
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
{% extends "rapids/base.html" %}
|
||||
|
||||
{% block js %}
|
||||
{{ form.media }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h2>Add Exam</h2>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
{% endblock %}
|
||||
+1
-1
@@ -745,7 +745,7 @@ class ExamCreate(ExamCreateBase):
|
||||
form_class = ExamForm
|
||||
|
||||
|
||||
class ExamUpdate(CheckCanEditMixin, ExamUpdateBase, AuthorOrCheckerRequiredMixin):
|
||||
class ExamUpdate(ExamUpdateBase, AuthorOrCheckerRequiredMixin):
|
||||
model = Exam
|
||||
form_class = ExamForm
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
{% extends "sbas/exams.html" %}
|
||||
|
||||
{% block js %}
|
||||
{{ form.media }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Add Exam</h2>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
{% endblock %}
|
||||
+1
-1
@@ -55,7 +55,7 @@ urlpatterns = [
|
||||
path("exam/<int:exam_id>/clone", views.ExamClone.as_view(), name="exam_clone"),
|
||||
path("exam/<int:exam_id>/clone2", views.exam_clone2, name="exam_clone2"),
|
||||
path("exam/available", views.active_exams, name="active_exams"),
|
||||
path("exam/create", views.ExamUpdate.as_view(), name="exam_create"),
|
||||
path("exam/create", views.ExamCreate.as_view(), name="exam_create"),
|
||||
path("exam/<int:pk>/update", views.ExamUpdate.as_view(), name="exam_update"),
|
||||
path("exam/<int:pk>/delete", views.ExamDelete.as_view(), name="exam_delete"),
|
||||
# path("exam/json/<int:pk>", views.exam_json, name="exam_json"),
|
||||
|
||||
+1
-1
@@ -402,7 +402,7 @@ class ExamCreate(ExamCreateBase):
|
||||
form_class = ExamForm
|
||||
|
||||
|
||||
class ExamUpdate(CheckCanEditMixin, ExamUpdateBase, AuthorOrCheckerRequiredMixin):
|
||||
class ExamUpdate(ExamUpdateBase, AuthorOrCheckerRequiredMixin):
|
||||
model = Exam
|
||||
form_class = ExamForm
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
{% extends view.model.app_name|add:"/exams.html" %}
|
||||
|
||||
{% block js %}
|
||||
{{ form.media }}
|
||||
{% endblock %}
|
||||
|
||||
{% block navigation %}
|
||||
{{ block.super }}
|
||||
{% include exam.get_link_headers %}
|
||||
{% endblock navigation %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h2>Cloning Exam: {{exam}}</h2>
|
||||
<p>
|
||||
This will create a new exam with the same settings, questions and answers as the original exam. <br/>
|
||||
Candidate groups and candidates will not be cloned.
|
||||
</p>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
{% extends 'base.html' %}
|
||||
{% extends object.get_base_template %}
|
||||
|
||||
{% block navigation %}
|
||||
{{ block.super }}
|
||||
{% include object.get_link_headers %}
|
||||
{% endblock navigation %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Delete Exam: {{ object }}</h2>
|
||||
<form method="post">{% csrf_token %}
|
||||
<p>Are you sure you want to delete the exam "{{ object }}"?</p>
|
||||
<input type="submit" value="Confirm">
|
||||
|
||||
Reference in New Issue
Block a user