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
0982085f
Commit
0982085f
authored
Sep 25, 2020
by
Matheus Miranda
Browse files
Update serializer to get access actions
parent
9cf0ba63
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
5 deletions
+7
-5
courses/reports/serializers.py
courses/reports/serializers.py
+6
-4
courses/stats/serializers.py
courses/stats/serializers.py
+1
-1
No files found.
courses/reports/serializers.py
View file @
0982085f
...
...
@@ -5,7 +5,7 @@ from rest_framework import serializers
from
django.utils
import
timezone
from
datetime
import
timedelta
from
courses.models
import
CourseStudent
from
courses.models
import
CourseStudent
,
Classroom
from
discussion.models
import
Comment
,
Topic
,
TopicLike
,
CommentLike
User
=
get_user_model
()
...
...
@@ -144,12 +144,14 @@ class UserStatsSerializer(serializers.ModelSerializer):
'accesses_count'
,
'topics'
,
'reactions'
,
'comments'
)
def
get_last_access
(
self
,
obj
):
count
=
obj
.
actor_actions
.
count
()
return
obj
.
actor_actions
.
last
().
timestamp
if
count
else
None
#group_id = self.context['group']
#group = Classroom.objects.get(id=group_id)
last_access_obj
=
obj
.
actor_actions
.
filter
(
verb
=
'access'
).
last
()
return
last_access_obj
.
timestamp
if
last_access_obj
else
''
def
get_accesses_count
(
self
,
obj
):
time_delta
=
timezone
.
now
()
-
timedelta
(
days
=
7
)
return
obj
.
actor_actions
.
filter
(
timestamp__gte
=
time_delta
).
count
()
return
obj
.
actor_actions
.
filter
(
verb
=
'access'
,
timestamp__gte
=
time_delta
).
count
()
def
get_topics
(
self
,
obj
):
return
Topic
.
objects
.
filter
(
author
=
obj
).
count
()
...
...
courses/stats/serializers.py
View file @
0982085f
...
...
@@ -71,7 +71,7 @@ class ActionSerializer(serializers.ModelSerializer):
action_phrase
=
''
action_phrase
+=
obj
.
actor
.
name
action_phrase
+=
obj
.
actor
.
name
.
split
()[
0
]
action_phrase
+=
(
' '
+
verbs
.
get
(
obj
.
verb
))
if
obj
.
target
:
...
...
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