Commit b6432b4c authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Fix last_login info

parent 6b9403a6
...@@ -144,9 +144,8 @@ class UserStatsSerializer(serializers.ModelSerializer): ...@@ -144,9 +144,8 @@ class UserStatsSerializer(serializers.ModelSerializer):
'accesses_count', 'topics', 'reactions', 'comments') 'accesses_count', 'topics', 'reactions', 'comments')
def get_last_access(self, obj): def get_last_access(self, obj):
last_access_obj = obj.actor_actions.order_by('timestamp').filter(verb='access').last() if obj.last_login:
if last_access_obj: timestamp_str = obj.last_login.strftime('%d-%m-%Y %H:%M:%S')
timestamp_str = last_access_obj.timestamp.strftime('%d-%m-%Y %H:%M:%S')
date, hour = timestamp_str.split() date, hour = timestamp_str.split()
return date + ' às ' + hour return date + ' às ' + hour
return '' return ''
......
...@@ -359,21 +359,18 @@ class UserAccessView(views.APIView): ...@@ -359,21 +359,18 @@ class UserAccessView(views.APIView):
actions = user.actor_actions.all().order_by('timestamp') actions = user.actor_actions.all().order_by('timestamp')
last_login = ''
last_access = '' last_access = ''
last_completed_activity = '' last_completed_activity = ''
accesses_7_days = 0 accesses_7_days = 0
accesses_30_days = 0 accesses_30_days = 0
if actions: if actions:
last_access_obj = actions.filter(verb='access').last()
last_activity_obj = actions.filter(verb='answered').last() last_activity_obj = actions.filter(verb='answered').last()
if last_access_obj: if user.last_login:
last_access = self.format_date(last_access_obj.timestamp) last_access = self.format_date(user.last_login)
if last_activity_obj: if last_activity_obj:
last_completed_activity = self.format_date(last_activity_obj.timestamp) last_completed_activity = self.format_date(last_activity_obj.timestamp)
last_login = self.format_date(user.last_login)
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()
...@@ -382,7 +379,6 @@ class UserAccessView(views.APIView): ...@@ -382,7 +379,6 @@ class UserAccessView(views.APIView):
accesses_30_days = actions.filter(verb='access', timestamp__gte=time_delta).count() accesses_30_days = actions.filter(verb='access', timestamp__gte=time_delta).count()
access_data = { access_data = {
'last_login': last_login,
'last_completed_activity': last_completed_activity, '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,
......
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