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

Add last_login field

parent 561ef390
......@@ -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 ''
......
......@@ -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,
......
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