Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
hackinscience
hkis-website
Commits
7dc3fdd3
Commit
7dc3fdd3
authored
Jan 18, 2019
by
Julien Palard
Browse files
We can now unpublish an exercise.
parent
7a19ada1
Changes
3
Hide whitespace changes
Inline
Side-by-side
website/admin.py
View file @
7dc3fdd3
...
...
@@ -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
...
...
website/api.py
View file @
7dc3fdd3
...
...
@@ -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
...
...
website/views.py
View file @
7dc3fdd3
...
...
@@ -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"
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment