Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
MOOC packages by hacklab
django-courses
Commits
120f1d56
Commit
120f1d56
authored
Sep 25, 2020
by
Matheus Miranda
Browse files
Add interaction info to UserStatsSerializer
parent
e69dc69a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
1 deletion
+16
-1
courses/reports/serializers.py
courses/reports/serializers.py
+16
-1
No files found.
courses/reports/serializers.py
View file @
120f1d56
...
...
@@ -6,6 +6,7 @@ from django.utils import timezone
from
datetime
import
timedelta
from
courses.models
import
CourseStudent
from
discussion.models
import
Comment
,
Topic
,
TopicLike
,
CommentLike
User
=
get_user_model
()
...
...
@@ -133,11 +134,15 @@ class UsersByClassSerializer(serializers.Serializer):
class
UserStatsSerializer
(
serializers
.
ModelSerializer
):
last_access
=
serializers
.
SerializerMethodField
()
accesses_count
=
serializers
.
SerializerMethodField
()
created_topics
=
serializers
.
SerializerMethodField
()
reactions
=
serializers
.
SerializerMethodField
()
comments
=
serializers
.
SerializerMethodField
()
class
Meta
:
model
=
User
fields
=
(
'name'
,
'username'
,
'email'
,
'id'
,
'image'
,
'groups'
,
'last_access'
,
'accesses_count'
)
'last_access'
,
'accesses_count'
,
'created_topics'
,
'reactions'
,
'comments'
)
def
get_last_access
(
self
,
obj
):
count
=
obj
.
actor_actions
.
count
()
...
...
@@ -146,3 +151,13 @@ class UserStatsSerializer(serializers.ModelSerializer):
def
get_accesses_count
(
self
,
obj
):
time_delta
=
timezone
.
now
()
-
timedelta
(
days
=
7
)
return
obj
.
actor_actions
.
filter
(
timestamp__gte
=
time_delta
).
count
()
def
get_created_topics
(
self
,
obj
):
return
Topic
.
objects
.
filter
(
author
=
obj
).
count
()
def
get_reactions
(
self
,
obj
):
return
TopicLike
.
objects
.
filter
(
user
=
obj
).
count
()
+
CommentLike
.
objects
.
filter
(
user
=
obj
).
count
()
def
get_comments
(
self
,
obj
):
return
Comment
.
objects
.
filter
(
author
=
obj
).
count
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment