Add question review list view and template with filtering options
This commit is contained in:
@@ -3139,6 +3139,65 @@ class GenericViewBase:
|
||||
return render(request, f"{self.app_name}/question_review_complete.html", {"app_name": self.app_name})
|
||||
|
||||
|
||||
def question_review_list(self, request):
|
||||
"""Return a page listing questions that match the supplied filters.
|
||||
|
||||
Accepts query parameters similar to question_review_next: category, status.
|
||||
"""
|
||||
|
||||
# Read filters
|
||||
category = request.GET.get("category") or request.POST.get("category")
|
||||
status = request.GET.get("status") or request.POST.get("status") or "ANY"
|
||||
|
||||
# Build base queryset of questions for this app
|
||||
qs = self.question_object.objects.all().order_by("pk")
|
||||
|
||||
# Restrict by category if provided
|
||||
if category:
|
||||
try:
|
||||
qs = qs.filter(category__id=int(category))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Apply permission filter similar to question_review_next
|
||||
if not request.user.groups.filter(name=self.checker_group).exists():
|
||||
try:
|
||||
qs = qs.filter(open_access=True) | qs.filter(author__id=request.user.id)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Optionally filter by review status
|
||||
results = []
|
||||
for question in qs:
|
||||
try:
|
||||
if question.authors_only and not (
|
||||
request.user.is_superuser or request.user in question.author.all()
|
||||
):
|
||||
continue
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
ct = ContentType.objects.get_for_model(question)
|
||||
latest = (
|
||||
QuestionReview.objects.filter(content_type=ct, object_id=question.pk)
|
||||
.order_by("-created_on").first()
|
||||
)
|
||||
|
||||
match = False
|
||||
if status == "ANY":
|
||||
match = True
|
||||
elif status == "UNREVIEWED":
|
||||
match = latest is None
|
||||
else:
|
||||
if latest is not None and latest.status == status:
|
||||
match = True
|
||||
|
||||
if match:
|
||||
results.append(question)
|
||||
|
||||
return render(request, f"{self.app_name}/question_review_list.html", {"questions": results, "app_name": self.app_name, "filters": {"category": category, "status": status}})
|
||||
|
||||
|
||||
@method_decorator(user_passes_test(lambda u: u.is_superuser))
|
||||
def user_answer_delete_multiple(self, request):
|
||||
print(request.POST["answer_ids"])
|
||||
|
||||
Reference in New Issue
Block a user