This commit is contained in:
Ross
2021-02-17 21:49:25 +00:00
parent d521cee235
commit 326c155c24
17 changed files with 68 additions and 4 deletions
+3
View File
@@ -52,6 +52,9 @@ class AnatomyQuestionTable(tables.Table):
# text='Clone',
# args=[A('pk')],
# orderable=False)
delete = tables.LinkColumn(
"anatomy:question_delete", text="Delete", args=[A("pk")], orderable=False
)
exams = tables.ManyToManyColumn(verbose_name="Exams")
class Meta:
@@ -0,0 +1 @@
{% include 'confirm_delete.html' %}
@@ -23,6 +23,7 @@
<div class="question">
<a href="{% url 'anatomy:anatomy_question_update' question.id %}" title="Edit the Question">Edit</a>
<a href="{% url 'anatomy:question_clone' question.id %}" title="Clone the Question">Clone</a>
<a href="{% url 'anatomy:question_delete' pk=question.pk %}" title="Delete the Question">Delete</a>
<a href="{% url 'admin:anatomy_anatomyquestion_change' question.id %}"
title="Edit the Question using the admin interface">Admin Edit</a>
<div class="date">
+1
View File
@@ -15,6 +15,7 @@ urlpatterns = [
views.answer_question,
name="answer_question"),
path("question/<int:pk>/clone", views.QuestionClone.as_view(), name="question_clone"),
path("question/<int:pk>/delete", views.QuestionDelete.as_view(), name="question_delete"),
path("exam/<int:pk>/<int:sk>/mark", views.mark, name="mark"),
path("exam/<int:pk>/mark", views.AnatomyExamViews.mark_overview, name="mark_overview"),
path("exam/<int:pk>/<int:sk>/", views.exam_take, name="exam_take"),
+13 -1
View File
@@ -6,6 +6,7 @@ from django import forms
# from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
from django.contrib.auth.mixins import LoginRequiredMixin
@@ -64,6 +65,14 @@ from django.template.defaulttags import register
from generic.mixins import SuperuserRequiredMixin
class AuthorOrCheckerRequiredMixin(object):
def get_object(self, *args, **kwargs):
obj = super().get_object(*args, **kwargs)
if self.request.user.groups.filter(name="anatomy_checker").exists():
return obj
if self.request.user not in obj.author.all():
raise PermissionDenied() # or Http404
return obj
@register.filter
def get_item(dictionary, key):
@@ -948,4 +957,7 @@ AnatomyExamViews = ExamViews(Exam, "anatomy", "anatomy", loadJsonAnswer)
class UserAnswerDelete(SuperuserRequiredMixin, DeleteView):
model = CidUserAnswer
success_url = reverse_lazy("anatomy:anatomy_user_answer_view")
success_url = reverse_lazy("anatomy:anatomy_user_answer_view")
class QuestionDelete(AuthorOrCheckerRequiredMixin, DeleteView):
model = AnatomyQuestion
success_url = reverse_lazy("anatomy:anatomy_question_view")