Compare commits
No commits in common. "94d2f5a8d87e89aa1c7152fa7652855c26ccd620" and "c43c5c1e10d0413753abd13f80f6f55337133d5a" have entirely different histories.
94d2f5a8d8
...
c43c5c1e10
29
api/views.py
29
api/views.py
|
@ -1,9 +1,11 @@
|
||||||
|
from django_filters.rest_framework import DjangoFilterBackend
|
||||||
|
from rest_framework import viewsets, generics, filters
|
||||||
from rest_framework.permissions import IsAuthenticated, IsAdminUser
|
from rest_framework.permissions import IsAuthenticated, IsAdminUser
|
||||||
from rest_framework import viewsets
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from .serializers import ContestSerializer, BandSerializer, FrequencySerializer, EntryCategorySerializer, \
|
from .serializers import ContestSerializer, BandSerializer, FrequencySerializer, EntryCategorySerializer, \
|
||||||
ReferenceSerializer, QSOSerializer, ShadowCallSerializer, UserSerializer
|
ReferenceSerializer, QSOSerializer, ShadowCallSerializer, UserSerializer
|
||||||
from contest.models import Contest, Band, Frequency, EntryCategory, Reference, QSO, ShadowCall, User
|
from contest.models import Contest, Band, Frequency, EntryCategory, Reference, QSO, ShadowCall
|
||||||
|
|
||||||
|
|
||||||
class ContestViewSet(viewsets.ReadOnlyModelViewSet):
|
class ContestViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
@ -62,26 +64,17 @@ class QSOViewSet(viewsets.ModelViewSet):
|
||||||
return serializer.save(owner=self.request.user)
|
return serializer.save(owner=self.request.user)
|
||||||
|
|
||||||
|
|
||||||
class UserProfileViewSet(viewsets.ModelViewSet):
|
class UserProfileViewSet(generics.UpdateAPIView, viewsets.GenericViewSet):
|
||||||
"""
|
|
||||||
Resource to view user-profiles, currently restricted to the current user's profile.
|
|
||||||
Use `me/` to get the profile of the currently logged in user.
|
|
||||||
"""
|
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
|
|
||||||
|
def list(self, request, format=None):
|
||||||
|
user = request.user
|
||||||
|
serializer = UserSerializer(user)
|
||||||
|
return Response(serializer.data)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return User.objects.filter(id=self.request.user.id)
|
return self.request.user
|
||||||
|
|
||||||
def get_object(self):
|
|
||||||
lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
|
|
||||||
if self.kwargs.get(lookup_url_kwarg) == "me":
|
|
||||||
obj = self.request.user
|
|
||||||
self.check_object_permissions(self.request, obj)
|
|
||||||
else:
|
|
||||||
obj = super(ContestViewSet, self).get_object()
|
|
||||||
|
|
||||||
return obj
|
|
||||||
|
|
||||||
|
|
||||||
class ShadowCallViewSet(viewsets.ReadOnlyModelViewSet):
|
class ShadowCallViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
|
Loading…
Reference in New Issue