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
12117799
Commit
12117799
authored
Oct 09, 2020
by
Matheus Miranda
Browse files
Add last_login field
parent
561ef390
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
3 deletions
+9
-3
courses/reports/serializers.py
courses/reports/serializers.py
+3
-2
courses/reports/views.py
courses/reports/views.py
+6
-1
No files found.
courses/reports/serializers.py
View file @
12117799
...
...
@@ -144,8 +144,9 @@ class UserStatsSerializer(serializers.ModelSerializer):
'accesses_count'
,
'topics'
,
'reactions'
,
'comments'
)
def
get_last_access
(
self
,
obj
):
if
obj
.
last_login
:
timestamp_str
=
obj
.
last_login
.
strftime
(
'%d-%m-%Y %H:%M:%S'
)
last_access_obj
=
obj
.
actor_actions
.
order_by
(
'timestamp'
).
filter
(
verb
=
'access'
).
last
()
if
last_access_obj
:
timestamp_str
=
last_access_obj
.
timestamp
.
strftime
(
'%d-%m-%Y %H:%M:%S'
)
date
,
hour
=
timestamp_str
.
split
()
return
date
+
' às '
+
hour
return
''
...
...
courses/reports/views.py
View file @
12117799
...
...
@@ -360,15 +360,19 @@ class UserAccessView(views.APIView):
actions
=
user
.
actor_actions
.
all
().
order_by
(
'timestamp'
)
last_access
=
''
last_login
=
''
last_completed_activity
=
''
accesses_7_days
=
0
accesses_30_days
=
0
if
actions
:
last_access_obj
=
actions
.
filter
(
verb
=
'access'
).
last
()
last_activity_obj
=
actions
.
filter
(
verb
=
'answered'
).
last
()
if
last_access_obj
:
last_access
=
self
.
format_date
(
last_access_obj
.
timestamp
)
if
user
.
last_login
:
last_
access
=
self
.
format_date
(
user
.
last_login
)
last_
login
=
self
.
format_date
(
user
.
last_login
)
if
last_activity_obj
:
last_completed_activity
=
self
.
format_date
(
last_activity_obj
.
timestamp
)
...
...
@@ -379,6 +383,7 @@ class UserAccessView(views.APIView):
accesses_30_days
=
actions
.
filter
(
verb
=
'access'
,
timestamp__gte
=
time_delta
).
count
()
access_data
=
{
'last_login'
:
last_login
,
'last_completed_activity'
:
last_completed_activity
,
'last_access'
:
last_access
,
'accesses_7_days'
:
accesses_7_days
,
...
...
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