Skip to content
Snippets Groups Projects
Commit 0fc87444 authored by Elias Sagmo Larsen's avatar Elias Sagmo Larsen
Browse files

pylint/views_duplicated_code&naming_convention

parent c29db9c8
No related branches found
No related tags found
No related merge requests found
Pipeline #127140 passed
from django.contrib import admin from django.contrib import admin
from models import Comment from comments.models import Comment
# Register your models here. # Register your models here.
......
...@@ -30,32 +30,21 @@ class CommentList( ...@@ -30,32 +30,21 @@ class CommentList(
serializer.save(owner=self.request.user) serializer.save(owner=self.request.user)
def get_queryset(self): def get_queryset(self):
workout_pk = self.kwargs.get("pk")
qs = Comment.objects.none()
if workout_pk:
qs = 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: """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 is on a public visibility workout
- The comment was written by the user - 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 coach visibility workout and the user is the workout owner's coach
- The comment is on a workout owned by the user - The comment is on a workout owned by the user
""" """
# The code below is kind of duplicate of the one in ./permissions.py workout_pk = self.kwargs.get("pk")
# We should replace it with a better solution. queryset = Comment.objects.none()
# Or maybe not.
qs = Comment.objects.filter( if workout_pk:
Q(workout__visibility="PU") queryset = Comment.objects.filter(workout=workout_pk)
| Q(owner=self.request.user) elif self.request.user:
| ( queryset = Comment.objects.filter(IsCommentVisibleToUser.has_object_permission).distinct()
Q(workout__visibility="CO")
& Q(workout__owner__coach=self.request.user) return queryset
)
| Q(workout__owner=self.request.user)
).distinct()
return qs
# Details of comment # Details of comment
class CommentDetail( class CommentDetail(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment