Commit 0fc87444 authored by Elias Sagmo Larsen's avatar Elias Sagmo Larsen
Browse files

pylint/views_duplicated_code&naming_convention

parent c29db9c8
Pipeline #127140 passed with stage
in 31 seconds
from django.contrib import admin
from models import Comment
from comments.models import Comment
# Register your models here.
......
......@@ -30,32 +30,21 @@ class CommentList(
serializer.save(owner=self.request.user)
def get_queryset(self):
"""A comment should be visible to the requesting user if any of the following hold:
- The comment is on a public visibility workout
- The comment was written by the user
- The comment is on a coach visibility workout and the user is the workout owner's coach
- The comment is on a workout owned by the user
"""
workout_pk = self.kwargs.get("pk")
qs = Comment.objects.none()
queryset = Comment.objects.none()
if workout_pk:
qs = Comment.objects.filter(workout=workout_pk)
queryset = Comment.objects.filter(workout=workout_pk)
elif self.request.user:
"""A comment should be visible to the requesting user if any of the following hold:
- The comment is on a public visibility workout
- The comment was written by the user
- The comment is on a coach visibility workout and the user is the workout owner's coach
- The comment is on a workout owned by the user
"""
# The code below is kind of duplicate of the one in ./permissions.py
# We should replace it with a better solution.
# Or maybe not.
qs = Comment.objects.filter(
Q(workout__visibility="PU")
| Q(owner=self.request.user)
| (
Q(workout__visibility="CO")
& Q(workout__owner__coach=self.request.user)
)
| Q(workout__owner=self.request.user)
).distinct()
return qs
queryset = Comment.objects.filter(IsCommentVisibleToUser.has_object_permission).distinct()
return queryset
# Details of comment
class CommentDetail(
......
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