start taking more advantage of class based views

This commit is contained in:
Ross
2024-03-11 11:08:35 +00:00
parent 78e4ed871e
commit 0cb38f5c31
27 changed files with 244 additions and 104 deletions
+6
View File
@@ -108,6 +108,9 @@ class Question(QuestionBase):
if self.e_answer:
self.e_answer = self.e_answer.strip()
def get_app_name(self):
return "sbas"
def get_absolute_url(self):
return reverse("sbas:question_detail", kwargs={"pk": self.pk})
@@ -210,6 +213,9 @@ class Exam(ExamBase):
def get_take_url(self):
return reverse("sbas:exam_start", kwargs={"pk": self.pk})
def get_app_name(self):
return "sbas"
@reversion.register
class UserAnswer(UserAnswerBase):
+19 -15
View File
@@ -1,10 +1,14 @@
{% extends 'sbas/exams.html' %}
{% block navigation %}
{{ block.super }}
{% include 'generic/exam_overview_headers.html' %}
{% endblock navigation %}
{% block content %}
{% load thumbnail %}
<div class="sbas">
{% include 'generic/exam_overview_headers.html' %}
This exam will be available to take <a href="{% url 'sbas:exam_start' pk=exam.pk %}">here</a> (when active).
@@ -47,17 +51,17 @@
})
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
.done(function (data) {
console.log(data);
console.log(data);
if (data.status == "success") {
toastr.info('Exam state changed.')
}
if (data.status == "success") {
toastr.info('Exam state changed.')
}
// show some message according to the response.
// For eg. A message box showing that the status has been changed
})
})
.always(function () {
console.log('[Done]');
})
console.log('[Done]');
})
})
$("#exam-publish-results-switch").on("change", function () {
$.ajax({
@@ -71,17 +75,17 @@
})
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
.done(function (data) {
console.log(data);
console.log(data);
if (data.status == "success") {
toastr.info('Publish results state changed.')
}
if (data.status == "success") {
toastr.info('Publish results state changed.')
}
// show some message according to the response.
// For eg. A message box showing that the status has been changed
})
})
.always(function () {
console.log('[Done]');
})
console.log('[Done]');
})
})
});
</script>
+4 -3
View File
@@ -1,5 +1,5 @@
from reversion.views import RevisionMixin
from generic.mixins import SuperuserRequiredMixin
from generic.mixins import CheckCanEditMixin, SuperuserRequiredMixin
from django.views.generic.detail import DetailView
from generic.models import CidUser
from sbas.forms import UserAnswerForm, ExamAuthorForm, ExamForm
@@ -402,7 +402,7 @@ class ExamCreate(ExamCreateBase):
form_class = ExamForm
class ExamUpdate(ExamUpdateBase, AuthorOrCheckerRequiredMixin):
class ExamUpdate(CheckCanEditMixin, ExamUpdateBase, AuthorOrCheckerRequiredMixin):
model = Exam
form_class = ExamForm
@@ -428,11 +428,12 @@ class ExamDelete(AuthorOrCheckerRequiredMixin, ExamDeleteBase):
class ExamAuthorUpdate(
RevisionMixin, LoginRequiredMixin, AuthorRequiredMixin, UpdateView
RevisionMixin, CheckCanEditMixin, LoginRequiredMixin, AuthorRequiredMixin, UpdateView
):
model = Exam
form_class = ExamAuthorForm
template_name = "author_form.html"
class ExamClone(ExamCloneMixin, ExamCreate):
"""Clone exam view"""