allow adding markers and authors to exams in collections
This commit is contained in:
@@ -77,6 +77,7 @@ from .forms import (
|
||||
CidGroupExamForm,
|
||||
UserUserForm,
|
||||
UserUserGroupForm,
|
||||
UsersAutocompleteForm, # Added import
|
||||
)
|
||||
|
||||
from .models import (
|
||||
@@ -769,6 +770,7 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
|
||||
return self.exam_list(request, all=True, collection=collection)
|
||||
|
||||
|
||||
@method_decorator(login_required)
|
||||
def exam_list(self, request, all=False, collection=None):
|
||||
if collection is None:
|
||||
@@ -4032,3 +4034,53 @@ def toggle_share_with_supervisor(request, pk):
|
||||
)
|
||||
else:
|
||||
raise PermissionDenied()
|
||||
|
||||
|
||||
def exam_collection_add_author(request, collection_id):
|
||||
if request.method != "POST":
|
||||
form = UsersAutocompleteForm()
|
||||
|
||||
return render(
|
||||
request,
|
||||
"generic/user_form.html",
|
||||
{"form": form, "collection_id": collection_id},
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
collection = get_object_or_404(ExamCollection, pk=collection_id)
|
||||
|
||||
if not request.user in collection.author.all():
|
||||
raise PermissionDenied
|
||||
|
||||
#user = get_object_or_404(User, pk=request.POST.get("user"))
|
||||
users = User.objects.filter(pk__in=request.POST.getlist("users"))
|
||||
|
||||
collection.add_author_to_exams(users)
|
||||
|
||||
return HttpResponse("Author added to all exams")
|
||||
|
||||
|
||||
def exam_collection_add_marker(request, collection_id, exam_type):
|
||||
if request.method != "POST":
|
||||
form = UsersAutocompleteForm()
|
||||
|
||||
return render(
|
||||
request,
|
||||
"generic/marker_form.html",
|
||||
{"form": form, "collection_id": collection_id, "exam_type": exam_type},
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
collection = get_object_or_404(ExamCollection, pk=collection_id)
|
||||
|
||||
if not request.user in collection.author.all():
|
||||
raise PermissionDenied
|
||||
|
||||
#user = get_object_or_404(User, pk=request.POST.get("user"))
|
||||
users = User.objects.filter(pk__in=request.POST.getlist("users"))
|
||||
|
||||
collection.add_marker_to_exams(users, exam_types=(exam_type,))
|
||||
|
||||
return HttpResponse("Marker added to exams")
|
||||
Reference in New Issue
Block a user