Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
The Social Network
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
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
Marc Feger
The Social Network
Commits
416caa89
Commit
416caa89
authored
3 years ago
by
Andreas Burbach
Browse files
Options
Downloads
Patches
Plain Diff
pagination for statement feed
parent
bd0b1846
No related branches found
No related tags found
1 merge request
!3
Feeding chicken with chicken
Pipeline
#75914
passed
3 years ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
social_network/the_social_network/urls/contentUrls.py
+1
-0
1 addition, 0 deletions
social_network/the_social_network/urls/contentUrls.py
social_network/the_social_network/views/contentViews.py
+42
-4
42 additions, 4 deletions
social_network/the_social_network/views/contentViews.py
with
43 additions
and
4 deletions
social_network/the_social_network/urls/contentUrls.py
+
1
−
0
View file @
416caa89
...
@@ -6,5 +6,6 @@ urlpatterns = [
...
@@ -6,5 +6,6 @@ urlpatterns = [
path
(
'
statements/get/<int:id>/
'
,
ShowStatement
.
as_view
(),
name
=
"
show_statement
"
),
path
(
'
statements/get/<int:id>/
'
,
ShowStatement
.
as_view
(),
name
=
"
show_statement
"
),
path
(
'
statements/with/hashtag/
'
,
ShowStatementsWithHashtag
.
as_view
(),
name
=
"
show_statement_with_hashtag
"
),
path
(
'
statements/with/hashtag/
'
,
ShowStatementsWithHashtag
.
as_view
(),
name
=
"
show_statement_with_hashtag
"
),
path
(
'
statements/feed/
'
,
ShowStatementFeed
.
as_view
(),
name
=
"
show_statement_feed
"
),
path
(
'
statements/feed/
'
,
ShowStatementFeed
.
as_view
(),
name
=
"
show_statement_feed
"
),
path
(
'
statements/feed/pagination
'
,
ShowStatementFeedPagination
.
as_view
(),
name
=
"
show_statement_feed_pagination
"
),
path
(
'
trending/hashtag/
'
,
ShowTrendingHashtag
.
as_view
(),
name
=
"
show_trending_hashtags
"
),
path
(
'
trending/hashtag/
'
,
ShowTrendingHashtag
.
as_view
(),
name
=
"
show_trending_hashtags
"
),
]
]
\ No newline at end of file
This diff is collapsed.
Click to expand it.
social_network/the_social_network/views/contentViews.py
+
42
−
4
View file @
416caa89
...
@@ -82,7 +82,6 @@ class ShowStatementFeed(APIView):
...
@@ -82,7 +82,6 @@ class ShowStatementFeed(APIView):
def
get
(
request
:
Request
):
def
get
(
request
:
Request
):
"""
"""
This is for getting the feed.
This is for getting the feed.
Todo: Add pagination for infinite scrolling.
:param request: The request containing the token to identify the calling user.
:param request: The request containing the token to identify the calling user.
:return: Feed for the calling user based on the actions of those the calling account follows.
:return: Feed for the calling user based on the actions of those the calling account follows.
"""
"""
...
@@ -93,6 +92,47 @@ class ShowStatementFeed(APIView):
...
@@ -93,6 +92,47 @@ class ShowStatementFeed(APIView):
return
Response
(
status
=
status
.
HTTP_200_OK
,
data
=
serializer
.
data
)
return
Response
(
status
=
status
.
HTTP_200_OK
,
data
=
serializer
.
data
)
class
ShowStatementFeedPagination
(
APIView
):
"""
This view is for querying the feed for an calling account.
The feed is generated by the accounts the calling account is following.
To get the feed the calling account must be authenticated.
"""
authentication_classes
=
[
TokenAuthentication
]
permission_classes
=
(
IsAuthenticated
,)
@staticmethod
def
get
(
request
:
Request
):
"""
This is for getting the feed with pagination.
Todo: Add pagination for infinite scrolling.
:param request: The request containing the token to identify the calling user. The page number. The size number.
:return: Feed for the calling user based on the actions of those the calling account follows.
"""
page
:
int
=
int
(
request
.
query_params
.
get
(
'
page
'
,
None
))
size
:
int
=
int
(
request
.
query_params
.
get
(
'
size
'
,
None
))
if
not
page
or
not
size
or
page
<=
0
or
size
<=
0
:
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
account
:
Account
=
Account
.
objects
.
get
(
user
=
request
.
user
)
following
:
List
[
Account
]
=
account
.
get_related_to
()
+
[
account
]
feed
:
QuerySet
[
Statement
]
=
Statement
.
objects
.
filter
(
author__in
=
following
)
first
=
(
page
-
1
)
*
size
last
=
first
+
size
total
:
int
=
feed
.
count
()
if
first
>=
total
:
feed
=
[]
else
:
if
last
>=
total
:
last
=
None
feed
=
feed
[
first
:
last
]
serializer
:
StatementSerializer
=
StatementSerializer
(
instance
=
feed
,
many
=
True
)
return
Response
(
status
=
status
.
HTTP_200_OK
,
data
=
{
"
data
"
:
serializer
.
data
,
"
total
"
:
total
})
class
ShowTrendingHashtag
(
APIView
):
class
ShowTrendingHashtag
(
APIView
):
"""
"""
This view is for getting the five most trending hashtags.
This view is for getting the five most trending hashtags.
...
@@ -114,9 +154,7 @@ class ShowTrendingHashtag(APIView):
...
@@ -114,9 +154,7 @@ class ShowTrendingHashtag(APIView):
:return: 200 OK with empty or not empty data section. The data section is empty if there are not hashtags.
:return: 200 OK with empty or not empty data section. The data section is empty if there are not hashtags.
"""
"""
hashtags
:
QuerySet
[
Dict
]
=
HashtagTagging
.
objects
.
values
(
'
hashtag
'
)
hashtags
:
QuerySet
[
Dict
]
=
HashtagTagging
.
objects
.
values
(
'
hashtag
'
)
hashtags_counted
:
QuerySet
[
Dict
]
=
hashtags
.
annotate
(
hashtags_counted
:
QuerySet
[
Dict
]
=
hashtags
.
annotate
(
the_count
=
Count
(
'
hashtag
'
)).
order_by
(
"
-the_count
"
)
the_count
=
Count
(
'
hashtag
'
)
).
order_by
(
"
-the_count
"
)
counted
:
Dict
=
{
item
[
"
hashtag
"
]:
item
[
"
the_count
"
]
for
item
in
hashtags_counted
}
counted
:
Dict
=
{
item
[
"
hashtag
"
]:
item
[
"
the_count
"
]
for
item
in
hashtags_counted
}
hashtags
:
QuerySet
[
Hashtag
]
=
Hashtag
.
objects
.
filter
(
id__in
=
counted
.
keys
())
hashtags
:
QuerySet
[
Hashtag
]
=
Hashtag
.
objects
.
filter
(
id__in
=
counted
.
keys
())
if
not
hashtags_counted
:
if
not
hashtags_counted
:
...
...
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