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
1e1d94a1
Commit
1e1d94a1
authored
Oct 28, 2020
by
Matheus Miranda
Browse files
Fix timezone for actions timestamps
parent
9efc4500
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
12 deletions
+15
-12
courses/reports/serializers.py
courses/reports/serializers.py
+4
-3
courses/reports/views.py
courses/reports/views.py
+7
-6
courses/stats/serializers.py
courses/stats/serializers.py
+4
-3
No files found.
courses/reports/serializers.py
View file @
1e1d94a1
...
...
@@ -146,9 +146,10 @@ class UserStatsSerializer(serializers.ModelSerializer):
def
get_last_access
(
self
,
obj
):
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
from
django.utils
import
timezone
tz_str
=
timezone
.
localtime
(
last_access_obj
.
timestamp
)
date
,
hour
=
tz_str
.
strftime
(
'%d-%m-%Y %H:%M:%S'
).
split
()
return
'{} às {}'
.
format
(
date
,
hour
)
return
''
def
get_accesses_count
(
self
,
obj
):
...
...
courses/reports/views.py
View file @
1e1d94a1
...
...
@@ -348,10 +348,10 @@ class UserAccessView(views.APIView):
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
from
django.utils
import
timezone
tz_str
=
timezone
.
localtime
(
timestamp
)
date
,
hour
=
tz_str
.
strftime
(
'%d-%m-%Y %H:%M:%S'
).
split
()
return
'{} às {}'
.
format
(
date
,
hour
)
def
get
(
self
,
request
,
format
=
None
):
user_id
=
request
.
GET
[
'user'
]
...
...
@@ -371,8 +371,6 @@ class UserAccessView(views.APIView):
if
last_access_obj
:
last_access
=
self
.
format_date
(
last_access_obj
.
timestamp
)
if
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
)
...
...
@@ -382,6 +380,9 @@ class UserAccessView(views.APIView):
time_delta
=
timezone
.
now
()
-
timedelta
(
days
=
30
)
accesses_30_days
=
actions
.
filter
(
verb
=
'access'
,
timestamp__gte
=
time_delta
).
count
()
if
user
.
last_login
:
last_login
=
self
.
format_date
(
user
.
last_login
)
access_data
=
{
'last_login'
:
last_login
,
'last_completed_activity'
:
last_completed_activity
,
...
...
courses/stats/serializers.py
View file @
1e1d94a1
...
...
@@ -60,9 +60,10 @@ class ActionSerializer(serializers.ModelSerializer):
return
obj
.
target
def
get_timestamp
(
self
,
obj
):
timestamp_str
=
obj
.
timestamp
.
strftime
(
'%d-%m-%Y %H:%M:%S'
)
date
,
hour
=
timestamp_str
.
split
()
return
date
+
' às '
+
hour
from
django.utils
import
timezone
tz_str
=
timezone
.
localtime
(
obj
.
timestamp
)
date
,
hour
=
tz_str
.
strftime
(
'%d-%m-%Y %H:%M:%S'
).
split
()
return
'{} às {}'
.
format
(
date
,
hour
)
def
get_accesible_area_name
(
self
,
name
):
accesible_areas
=
{
...
...
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