Commit 7dc3fdd3 authored by Julien Palard's avatar Julien Palard
Browse files

We can now unpublish an exercise.

parent 7a19ada1
......@@ -15,6 +15,7 @@ class AdminExerciseForm(forms.ModelForm):
fields = (
"title",
"slug",
"is_published",
"position",
"wording",
"initial_solution",
......@@ -39,7 +40,7 @@ class AdminExerciseForm(forms.ModelForm):
class ExerciseAdmin(admin.ModelAdmin):
readonly_fields = ("id",)
list_display = ("title", "slug", "position")
list_display = ("title", "slug", "is_published", "position")
form = AdminExerciseForm
......
......@@ -156,6 +156,12 @@ class ExerciseViewSet(viewsets.ModelViewSet):
permission_classes = [AdminOrReadOnly]
queryset = Exercise.objects.all()
def get_queryset(self):
queryset = super().get_queryset()
if self.request.user.is_staff:
return queryset
return queryset.filter(is_published=True)
def get_serializer_class(self):
if self.request.user.is_staff:
return StaffExerciseSerializer
......
......@@ -52,7 +52,7 @@ class ExerciseListView(LoginRequiredMixin, ListView):
template_name = "hkis/exercises.html"
def get_queryset(self):
self.queryset = Exercise.objects.annotate(
self.queryset = Exercise.objects.filter(is_published=True).annotate(
tried=Count("answers", filter=Q(answers__user_id=self.request.user.id)),
succeeded=Count(
"answers",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment