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
214e5427
Commit
214e5427
authored
Sep 18, 2020
by
Matheus Miranda
Browse files
[Classroom Status] Add access info to UserStats serialization
parent
5b39ac1d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
courses/reports/serializers.py
courses/reports/serializers.py
+15
-1
courses/reports/views.py
courses/reports/views.py
+1
-1
No files found.
courses/reports/serializers.py
View file @
214e5427
...
...
@@ -2,6 +2,8 @@ from django.contrib.auth import get_user_model
from
django.contrib.auth.models
import
User
from
rest_framework
import
serializers
from
django.utils
import
timezone
from
datetime
import
timedelta
from
courses.models
import
CourseStudent
...
...
@@ -129,6 +131,18 @@ class UsersByClassSerializer(serializers.Serializer):
class
UserStatsSerializer
(
serializers
.
ModelSerializer
):
last_access
=
serializers
.
SerializerMethodField
()
accesses_count
=
serializers
.
SerializerMethodField
()
class
Meta
:
model
=
User
fields
=
(
'name'
,
'username'
,
'email'
,
'id'
,
'image'
,
'groups'
)
fields
=
(
'name'
,
'username'
,
'email'
,
'id'
,
'image'
,
'groups'
,
'last_access'
,
'accesses_count'
)
def
get_last_access
(
self
,
obj
):
count
=
obj
.
actor_actions
.
count
()
return
obj
.
actor_actions
.
last
().
timestamp
if
count
else
None
def
get_accesses_count
(
self
,
obj
):
time_delta
=
timezone
.
now
()
-
timedelta
(
days
=
7
)
return
obj
.
actor_actions
.
filter
(
timestamp__gte
=
time_delta
).
count
()
courses/reports/views.py
View file @
214e5427
...
...
@@ -317,7 +317,7 @@ class UserStats(viewsets.ReadOnlyModelViewSet):
queryset
=
User
.
objects
.
all
().
order_by
(
'name'
)
serializer_class
=
UserStatsSerializer
filterset_fields
=
[
'groups'
]
#
permission_classes = [IsAuthenticated]
permission_classes
=
[
IsAuthenticated
]
pagination_class
=
ReportPagination
filter_backends
=
[
filters
.
SearchFilter
,
...
...
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