Commit 215b302c authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Merge branch 'develop' into 'master'

Add actions user viewset

See merge request !62
parents ed1da45f eacd0c2c
......@@ -6,6 +6,10 @@ from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from rest_framework.pagination import PageNumberPagination
from rest_pandas import PandasViewSet
from rest_pandas.renderers import PandasCSVRenderer, PandasJSONRenderer, PandasExcelRenderer
import pandas as pd
from discussion.models import Forum, Topic
from .serializers import UserActionsSerializer, UserAccessSerializer, ActionSerializer
from .models import AccessibleArea
......@@ -15,7 +19,6 @@ from ..classroom.models import Classroom
from cards.models import Card
from courses.models import Unit
from courses_learning_objects.models import LearningObject
from django.contrib.auth.models import User
......@@ -107,3 +110,48 @@ class UserActivitiesViewSet(viewsets.ReadOnlyModelViewSet):
queryset = actor_stream(user)
return queryset
class UserActionsViewSet(PandasViewSet):
permission_classes = [IsAuthenticated]
renderer_classes = [
PandasCSVRenderer,
PandasJSONRenderer,
PandasExcelRenderer,
]
def get_queryset(self):
user_id = self.request.GET.get('user')
user = User.objects.get(id=user_id)
queryset = actor_stream(user)
return queryset
def list(self, request, format=None):
queryset = self.get_queryset()
serializer = ActionSerializer(queryset, many=True)
return self.update_pandas_headers(Response(self.transform_data(serializer.data)))
def transform_data(self, data):
response = []
for user in data:
compls = []
phrase = user['action_phrase'].split()
if user['complements']:
for v, k in user['complements'].items():
compls += [k]
else:
compls += [' '.join(phrase[2:]) , " ", " "]
response.append({'Usuário': phrase[0], 'Ação': phrase[1], 'Espaço 1': compls[0], 'Espaço 2': compls[1], 'Espaço 3': compls[2], 'Data/Hora': user['timestamp']})
return pd.DataFrame.from_dict(response)
def get_pandas_filename(self, request, format):
user_id = self.request.GET.get('user')
user = User.objects.get(id=user_id)
return 'Percursos do usuario - ' + user.name
......@@ -36,7 +36,8 @@ from courses.classroom.views import (
)
from courses.stats.views import (
UserActionsView,
UserActivitiesViewSet
UserActivitiesViewSet,
UserActionsViewSet
)
......@@ -80,6 +81,7 @@ router.register(r'event', EventViewSet, base_name='event')
# Stats
router.register(r'user-activities', UserActivitiesViewSet, base_name='user-activities')
router.register(r'actions-user', UserActionsViewSet, base_name='actions-user')
app_name = 'courses'
urlpatterns = [
......
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