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

View File

@ -1,9 +1,10 @@
from rest_framework import viewsets from rest_framework import viewsets
from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated, IsAdminUser from rest_framework.permissions import IsAuthenticated, IsAdminUser
from rest_framework.response import Response
from .serializers import ContestSerializer, BandSerializer, FrequencySerializer, EntryCategorySerializer, \ 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 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) return QSO.objects.filter(owner=self.request.user)
class UserProfile(viewsets.ReadOnlyModelViewSet): class UserProfileView(APIView):
"""Return the currently authenticated user as a single item""" permission_classes = [IsAuthenticated]
pass
def get(self, request, format=None):
user = request.user
serializer = UserSerializer(user)
return Response(serializer.data)
class ShadowCallViewSet(viewsets.ReadOnlyModelViewSet): class ShadowCallViewSet(viewsets.ReadOnlyModelViewSet):