Skip to content
Snippets Groups Projects
Commit 78a9eaf0 authored by Sigurd's avatar Sigurd
Browse files

comments/views.py - Grouped imports, removed commented code, var names

Pylint and sonarlint
parent 5ec5c0ce
No related branches found
No related tags found
No related merge requests found
Pipeline #170727 passed with stage
in 24 seconds
from django.shortcuts import render
from rest_framework import generics, mixins
from django.db.models import Q
from rest_framework import generics, mixins, permissions
from rest_framework.filters import OrderingFilter
from comments.models import Comment, Like
from rest_framework import permissions
from comments.permissions import IsCommentVisibleToUser
from workouts.permissions import IsOwner, IsReadOnly
from comments.serializers import CommentSerializer, LikeSerializer
from django.db.models import Q
from rest_framework.filters import OrderingFilter
from workouts.permissions import IsOwner, IsReadOnly
# Create your views here.
class CommentList(
mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView
):
# queryset = Comment.objects.all()
serializer_class = CommentSerializer
permission_classes = [permissions.IsAuthenticated]
filter_backends = [OrderingFilter]
......@@ -29,12 +26,13 @@ class CommentList(
def get_queryset(self):
workout_pk = self.kwargs.get("pk")
qs = Comment.objects.none()
query_set = Comment.objects.none()
if workout_pk:
qs = Comment.objects.filter(workout=workout_pk)
query_set = 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 was written by the user
- The comment is on a coach visibility workout and the user is the workout owner's coach
......@@ -43,8 +41,7 @@ class CommentList(
# 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(
query_set = Comment.objects.filter(
Q(workout__visibility="PU")
| Q(owner=self.request.user)
| (
......@@ -54,7 +51,7 @@ class CommentList(
| Q(workout__owner=self.request.user)
).distinct()
return qs
return query_set
# Details of comment
class CommentDetail(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment