Commit 1e1d94a1 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Fix timezone for actions timestamps

parent 9efc4500
......@@ -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):
......
......@@ -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,
......
......@@ -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 = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment