diff options
author | maxbr <maxbr@mi.fu-berlin.de> | 2016-10-05 14:24:11 +0200 |
---|---|---|
committer | Jose Lausuch <jose.lausuch@ericsson.com> | 2016-10-12 13:29:04 +0000 |
commit | 7022542bc70c448f71fa56c06d90595e276d7dcc (patch) | |
tree | 44b37f2772860eb211ccede03fa0c0dfbce5accd /tools/pharos-dashboard/src/api | |
parent | 0655a3226b31ac0486e053a6161f99f08223ba59 (diff) |
Sync dashboard user data with jira
JIRA: PHAROS-264
Change-Id: Ic4533af04946ee0493c762ca79aaf46ee0f80e00
Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'tools/pharos-dashboard/src/api')
-rw-r--r-- | tools/pharos-dashboard/src/api/urls.py | 1 | ||||
-rw-r--r-- | tools/pharos-dashboard/src/api/views.py | 18 |
2 files changed, 18 insertions, 1 deletions
diff --git a/tools/pharos-dashboard/src/api/urls.py b/tools/pharos-dashboard/src/api/urls.py index 5206ac7f..dfbe1ac9 100644 --- a/tools/pharos-dashboard/src/api/urls.py +++ b/tools/pharos-dashboard/src/api/urls.py @@ -35,4 +35,5 @@ router.register(r'bookings', BookingViewSet) urlpatterns = [ url(r'^', include(router.urls)), + url(r'^token$', GenerateTokenView.as_view(), name='generate_token'), ]
\ No newline at end of file diff --git a/tools/pharos-dashboard/src/api/views.py b/tools/pharos-dashboard/src/api/views.py index 761ce6e7..55de5c6a 100644 --- a/tools/pharos-dashboard/src/api/views.py +++ b/tools/pharos-dashboard/src/api/views.py @@ -10,9 +10,14 @@ from rest_framework import viewsets +from django.contrib.auth.decorators import login_required +from django.utils.decorators import method_decorator from api.serializers import ResourceSerializer, ServerSerializer, BookingSerializer from booking.models import Booking from dashboard.models import Resource, Server +from django.views import View +from rest_framework.authtoken.models import Token +from django.shortcuts import redirect class BookingViewSet(viewsets.ModelViewSet): @@ -30,4 +35,15 @@ class ServerViewSet(viewsets.ModelViewSet): class ResourceViewSet(viewsets.ModelViewSet): queryset = Resource.objects.all() serializer_class = ResourceSerializer - filter_fields = ('name',)
\ No newline at end of file + filter_fields = ('name',) + + +@method_decorator(login_required, name='dispatch') +class GenerateTokenView(View): + def get(self, request, *args, **kwargs): + user = self.request.user + token, created = Token.objects.get_or_create(user=user) + if not created: + token.delete() + Token.objects.create(user=user) + return redirect('account:settings') |