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): ...@@ -15,6 +15,7 @@ class AdminExerciseForm(forms.ModelForm):
fields = ( fields = (
"title", "title",
"slug", "slug",
"is_published",
"position", "position",
"wording", "wording",
"initial_solution", "initial_solution",
...@@ -39,7 +40,7 @@ class AdminExerciseForm(forms.ModelForm): ...@@ -39,7 +40,7 @@ class AdminExerciseForm(forms.ModelForm):
class ExerciseAdmin(admin.ModelAdmin): class ExerciseAdmin(admin.ModelAdmin):
readonly_fields = ("id",) readonly_fields = ("id",)
list_display = ("title", "slug", "position") list_display = ("title", "slug", "is_published", "position")
form = AdminExerciseForm form = AdminExerciseForm
......
...@@ -156,6 +156,12 @@ class ExerciseViewSet(viewsets.ModelViewSet): ...@@ -156,6 +156,12 @@ class ExerciseViewSet(viewsets.ModelViewSet):
permission_classes = [AdminOrReadOnly] permission_classes = [AdminOrReadOnly]
queryset = Exercise.objects.all() 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): def get_serializer_class(self):
if self.request.user.is_staff: if self.request.user.is_staff:
return StaffExerciseSerializer return StaffExerciseSerializer
......
...@@ -52,7 +52,7 @@ class ExerciseListView(LoginRequiredMixin, ListView): ...@@ -52,7 +52,7 @@ class ExerciseListView(LoginRequiredMixin, ListView):
template_name = "hkis/exercises.html" template_name = "hkis/exercises.html"
def get_queryset(self): 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)), tried=Count("answers", filter=Q(answers__user_id=self.request.user.id)),
succeeded=Count( succeeded=Count(
"answers", "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