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
bd17f5f0
Commit
bd17f5f0
authored
Oct 02, 2020
by
Matheus Miranda
Browse files
Add last_activity info to serializer
parent
38acf3c2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
9 deletions
+10
-9
courses/reports/views.py
courses/reports/views.py
+10
-7
courses/stats/serializers.py
courses/stats/serializers.py
+0
-2
No files found.
courses/reports/views.py
View file @
bd17f5f0
...
@@ -347,6 +347,12 @@ class UserStatsViewSet(viewsets.ReadOnlyModelViewSet):
...
@@ -347,6 +347,12 @@ class UserStatsViewSet(viewsets.ReadOnlyModelViewSet):
class
UserAccessView
(
views
.
APIView
):
class
UserAccessView
(
views
.
APIView
):
permission_classes
=
[
permissions
.
IsAuthenticated
]
permission_classes
=
[
permissions
.
IsAuthenticated
]
def
format_date
(
self
,
timestamp
):
timestamp_str
=
timestamp
.
strftime
(
'%d-%m-%Y %H:%M:%S'
)
date
,
hour
=
timestamp_str
.
split
()
formatted_timestamp
=
date
+
' às '
+
hour
return
formatted_timestamp
def
get
(
self
,
request
,
format
=
None
):
def
get
(
self
,
request
,
format
=
None
):
user_id
=
request
.
GET
[
'user'
]
user_id
=
request
.
GET
[
'user'
]
user
=
User
.
objects
.
get
(
id
=
user_id
)
user
=
User
.
objects
.
get
(
id
=
user_id
)
...
@@ -359,13 +365,9 @@ class UserAccessView(views.APIView):
...
@@ -359,13 +365,9 @@ class UserAccessView(views.APIView):
accesses_30_days
=
0
accesses_30_days
=
0
if
actions
:
if
actions
:
last_access_str
=
actions
.
filter
(
verb
=
'access'
).
last
().
timestamp
.
strftime
(
'%d-%m-%Y %H:%M:%S'
)
last_access
=
self
.
format_date
(
actions
.
filter
(
verb
=
'access'
).
last
().
timestamp
)
date
,
hour
=
last_access_str
.
split
()
last_completed_activity
=
self
.
format_date
(
actions
.
filter
(
verb
=
'answered'
).
order_by
(
'timestamp'
).
last
().
timestamp
)
last_access
=
date
+
' às '
+
hour
last_login
=
self
.
format_date
(
user
.
last_login
)
last_login_str
=
user
.
last_login
.
strftime
(
'%d-%m-%Y %H:%M:%S'
)
date
,
hour
=
last_login_str
.
split
()
last_login
=
date
+
' às '
+
hour
time_delta
=
timezone
.
now
()
-
timedelta
(
days
=
7
)
time_delta
=
timezone
.
now
()
-
timedelta
(
days
=
7
)
accesses_7_days
=
actions
.
filter
(
verb
=
'access'
,
timestamp__gte
=
time_delta
).
count
()
accesses_7_days
=
actions
.
filter
(
verb
=
'access'
,
timestamp__gte
=
time_delta
).
count
()
...
@@ -375,6 +377,7 @@ class UserAccessView(views.APIView):
...
@@ -375,6 +377,7 @@ class UserAccessView(views.APIView):
access_data
=
{
access_data
=
{
'last_login'
:
last_login
,
'last_login'
:
last_login
,
'last_completed_activity'
:
last_completed_activity
,
'last_access'
:
last_access
,
'last_access'
:
last_access
,
'accesses_7_days'
:
accesses_7_days
,
'accesses_7_days'
:
accesses_7_days
,
'accesses_30_days'
:
accesses_30_days
'accesses_30_days'
:
accesses_30_days
...
...
courses/stats/serializers.py
View file @
bd17f5f0
...
@@ -88,8 +88,6 @@ class ActionSerializer(serializers.ModelSerializer):
...
@@ -88,8 +88,6 @@ class ActionSerializer(serializers.ModelSerializer):
return
' no fórum '
+
obj
.
title
return
' no fórum '
+
obj
.
title
if
isinstance
(
obj
,
AccessibleArea
):
if
isinstance
(
obj
,
AccessibleArea
):
return
' na área '
+
self
.
get_accesible_area_name
(
obj
.
name
)
return
' na área '
+
self
.
get_accesible_area_name
(
obj
.
name
)
if
isinstance
(
obj
,
Answer
):
return
' respondeu'
if
isinstance
(
obj
,
LearningObject
):
if
isinstance
(
obj
,
LearningObject
):
unit
=
obj
.
unit
.
title
unit
=
obj
.
unit
.
title
step
=
obj
.
unit
.
lesson
.
name
step
=
obj
.
unit
.
lesson
.
name
...
...
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