Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tdt4242-ex2
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jørgen Hollum
tdt4242-ex2
Commits
78a9eaf0
Commit
78a9eaf0
authored
2 years ago
by
Sigurd
Browse files
Options
Downloads
Patches
Plain Diff
comments/views.py - Grouped imports, removed commented code, var names
Pylint and sonarlint
parent
5ec5c0ce
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#170727
passed with stage
in 24 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
backend/secfit/comments/views.py
+10
-13
10 additions, 13 deletions
backend/secfit/comments/views.py
with
10 additions
and
13 deletions
backend/secfit/comments/views.py
+
10
−
13
View file @
78a9eaf0
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
"
)
q
s
=
Comment
.
objects
.
none
()
q
uery_set
=
Comment
.
objects
.
none
()
if
workout_pk
:
q
s
=
Comment
.
objects
.
filter
(
workout
=
workout_pk
)
q
uery_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
q
s
return
q
uery_set
# Details of comment
class
CommentDetail
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment