diff options
author | 2016-10-05 14:24:11 +0200 | |
---|---|---|
committer | 2016-10-12 13:29:04 +0000 | |
commit | adafb09cb1f221259970d16886ea0e03169899a5 (patch) | |
tree | d282c9c67723a4f5247909256396bbfd1d957335 /pharos-dashboard/src/api/views.py | |
parent | 46e1d9ab232df1c4deb672b72cd7b87081094955 (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 'pharos-dashboard/src/api/views.py')
-rw-r--r-- | pharos-dashboard/src/api/views.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/pharos-dashboard/src/api/views.py b/pharos-dashboard/src/api/views.py index 761ce6e..55de5c6 100644 --- a/pharos-dashboard/src/api/views.py +++ b/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') |