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

Add last_activity info to serializer

parent 38acf3c2
...@@ -347,6 +347,12 @@ class UserStatsViewSet(viewsets.ReadOnlyModelViewSet): ...@@ -347,6 +347,12 @@ class UserStatsViewSet(viewsets.ReadOnlyModelViewSet):
class UserAccessView(views.APIView): class UserAccessView(views.APIView):
permission_classes = [permissions.IsAuthenticated] 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
def get(self, request, format=None): def get(self, request, format=None):
user_id = request.GET['user'] user_id = request.GET['user']
user = User.objects.get(id=user_id) user = User.objects.get(id=user_id)
...@@ -359,13 +365,9 @@ class UserAccessView(views.APIView): ...@@ -359,13 +365,9 @@ class UserAccessView(views.APIView):
accesses_30_days = 0 accesses_30_days = 0
if actions: if actions:
last_access_str = actions.filter(verb='access').last().timestamp.strftime('%d-%m-%Y %H:%M:%S') last_access = self.format_date(actions.filter(verb='access').last().timestamp)
date, hour = last_access_str.split() last_completed_activity = self.format_date(actions.filter(verb='answered').order_by('timestamp').last().timestamp)
last_access = date + ' às ' + hour last_login = self.format_date(user.last_login)
last_login_str = user.last_login.strftime('%d-%m-%Y %H:%M:%S')
date, hour = last_login_str.split()
last_login = date + ' às ' + hour
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()
...@@ -375,6 +377,7 @@ class UserAccessView(views.APIView): ...@@ -375,6 +377,7 @@ class UserAccessView(views.APIView):
access_data = { access_data = {
'last_login': last_login, 'last_login': last_login,
'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,
'accesses_30_days': accesses_30_days 'accesses_30_days': accesses_30_days
......
...@@ -88,8 +88,6 @@ class ActionSerializer(serializers.ModelSerializer): ...@@ -88,8 +88,6 @@ class ActionSerializer(serializers.ModelSerializer):
return ' no fórum ' + obj.title return ' no fórum ' + obj.title
if isinstance(obj, AccessibleArea): if isinstance(obj, AccessibleArea):
return ' na área ' + self.get_accesible_area_name(obj.name) return ' na área ' + self.get_accesible_area_name(obj.name)
if isinstance(obj, Answer):
return ' respondeu'
if isinstance(obj, LearningObject): if isinstance(obj, LearningObject):
unit = obj.unit.title unit = obj.unit.title
step = obj.unit.lesson.name step = obj.unit.lesson.name
......
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