From 85379eb128fb98dfce34df98268f8a0d1f6cc0aa Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 25 Sep 2021 21:16:53 +0100 Subject: [PATCH] . --- .../anatomy/ciduseranswer_detail.html | 10 +++++++++ anatomy/views.py | 5 +++++ generic/views.py | 22 ++++++++++++++++++- rapids/templates/rapids/category_detail.html | 6 ++--- rapids/views.py | 17 -------------- 5 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 anatomy/templates/anatomy/ciduseranswer_detail.html diff --git a/anatomy/templates/anatomy/ciduseranswer_detail.html b/anatomy/templates/anatomy/ciduseranswer_detail.html new file mode 100644 index 00000000..d35f4d35 --- /dev/null +++ b/anatomy/templates/anatomy/ciduseranswer_detail.html @@ -0,0 +1,10 @@ + +{% extends 'anatomy/base.html' %} + +{% block content %} +CID: {{ciduseranswer.cid}}
+{{ciduseranswer.title}}
+{{ciduseranswer.question}}
+Answer(s): {{ciduseranswer.answers}}
+Delete answer +{% endblock content %} \ No newline at end of file diff --git a/anatomy/views.py b/anatomy/views.py index 239cc1a0..8f01b366 100644 --- a/anatomy/views.py +++ b/anatomy/views.py @@ -9,6 +9,7 @@ from django.contrib.auth.models import User from django.core.exceptions import PermissionDenied from django.contrib.auth.mixins import LoginRequiredMixin +from django.views.generic.detail import DetailView from django.views.generic.edit import CreateView, UpdateView, DeleteView from django.views.generic import ListView @@ -973,6 +974,10 @@ def question_save_annotation(request, pk): AnatomyExamViews = ExamViews(Exam, AnatomyQuestion, "anatomy", "anatomy", loadJsonAnswer) +class UserAnswerView(LoginRequiredMixin, DetailView): + model = CidUserAnswer + + class UserAnswerDelete(SuperuserRequiredMixin, DeleteView): model = CidUserAnswer success_url = reverse_lazy("anatomy:anatomy_user_answer_view") diff --git a/generic/views.py b/generic/views.py index 39bbbefb..76b5ca4a 100644 --- a/generic/views.py +++ b/generic/views.py @@ -1,3 +1,4 @@ +from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.forms.models import model_to_dict from django.shortcuts import render, get_object_or_404, redirect @@ -738,4 +739,23 @@ class GenericViewBase: request, f"{self.app_name}/question_user_answers.html", {"question": question, "answers": answers}, - ) \ No newline at end of file + ) + + @method_decorator(login_required) + def author_detail(self, request, pk): + # logging.debug(Author.objects.all()) + # author = get_object_or_404(Author, pk=pk) + author = User.objects.get(pk=pk) + + questions = self.question_object.objects.filter(author=pk) + + return render( + request, f"{self.app_name}/category_detail.html", {"category": author, "questions": questions} + ) + + + @method_decorator(login_required) + def author_list(self, request): + authors = User.objects.all() + + return render(request, f"{self.app_name}/author_list.html", {"authors": authors}) \ No newline at end of file diff --git a/rapids/templates/rapids/category_detail.html b/rapids/templates/rapids/category_detail.html index 8205f85a..9ecb93fb 100755 --- a/rapids/templates/rapids/category_detail.html +++ b/rapids/templates/rapids/category_detail.html @@ -3,9 +3,9 @@ {% block content %} {{category}}: diff --git a/rapids/views.py b/rapids/views.py index 4bc5efd3..e8f48ac4 100755 --- a/rapids/views.py +++ b/rapids/views.py @@ -156,23 +156,6 @@ def rapid_split(request, pk): return render(request, "rapids/question_detail.html", {"question": rapid}) -@login_required -def author_detail(request, pk): - # logging.debug(Author.objects.all()) - # author = get_object_or_404(Author, pk=pk) - author = User.objects.get(pk=pk) - - rapids = Rapid.objects.filter(author=pk) - - return render( - request, "rapids/category_detail.html", {"category": author, "rapids": rapids} - ) - - -def author_list(request): - authors = User.objects.all() - - return render(request, "rapids/author_list.html", {"authors": authors}) class RapidCreationDefaultView(LoginRequiredMixin, UpdateView):