WIP user profile api

This commit is contained in:
Sebastian Lohff 2020-02-02 02:10:33 +01:00
parent 4361c4f44a
commit 7158cef122
2 changed files with 12 additions and 6 deletions

View File

@ -2,7 +2,7 @@ from django.conf.urls import include, url
from rest_framework import routers
from .views import ContestViewSet, BandViewSet, FrequencyViewSet, EntryCategoryViewSet, ReferenceViewSet, QSOViewSet, \
ShadowCallViewSet
ShadowCallViewSet, UserProfileView
router = routers.DefaultRouter()
router.register('contests', ContestViewSet)
@ -12,6 +12,7 @@ router.register('entrycategories', EntryCategoryViewSet)
router.register('references', ReferenceViewSet)
router.register('qsos', QSOViewSet, basename='qso')
router.register('shadowcalls', ShadowCallViewSet)
router.register('profile', UserProfileView, basename='profile')
urlpatterns = [
url(r'^', include(router.urls)),

View File

@ -1,9 +1,10 @@
from rest_framework import viewsets
from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated, IsAdminUser
from rest_framework.response import Response
from .serializers import ContestSerializer, BandSerializer, FrequencySerializer, EntryCategorySerializer, \
ReferenceSerializer, QSOSerializer, ShadowCallSerializer
ReferenceSerializer, QSOSerializer, ShadowCallSerializer, UserSerializer
from contest.models import Contest, Band, Frequency, EntryCategory, Reference, QSO, ShadowCall
@ -41,9 +42,13 @@ class QSOViewSet(viewsets.ReadOnlyModelViewSet):
return QSO.objects.filter(owner=self.request.user)
class UserProfile(viewsets.ReadOnlyModelViewSet):
"""Return the currently authenticated user as a single item"""
pass
class UserProfileView(APIView):
permission_classes = [IsAuthenticated]
def get(self, request, format=None):
user = request.user
serializer = UserSerializer(user)
return Response(serializer.data)
class ShadowCallViewSet(viewsets.ReadOnlyModelViewSet):