2020-02-02 01:48:10 +01:00
|
|
|
from rest_framework import viewsets
|
2020-02-02 02:10:33 +01:00
|
|
|
from rest_framework.views import APIView
|
2020-02-02 01:48:10 +01:00
|
|
|
from rest_framework.permissions import IsAuthenticated, IsAdminUser
|
2020-02-02 02:10:33 +01:00
|
|
|
from rest_framework.response import Response
|
2020-02-02 01:48:10 +01:00
|
|
|
|
|
|
|
from .serializers import ContestSerializer, BandSerializer, FrequencySerializer, EntryCategorySerializer, \
|
2020-02-02 02:10:33 +01:00
|
|
|
ReferenceSerializer, QSOSerializer, ShadowCallSerializer, UserSerializer
|
2020-02-02 01:48:10 +01:00
|
|
|
from contest.models import Contest, Band, Frequency, EntryCategory, Reference, QSO, ShadowCall
|
|
|
|
|
|
|
|
|
|
|
|
class ContestViewSet(viewsets.ReadOnlyModelViewSet):
|
|
|
|
queryset = Contest.objects.all()
|
|
|
|
serializer_class = ContestSerializer
|
|
|
|
|
|
|
|
|
|
|
|
class BandViewSet(viewsets.ReadOnlyModelViewSet):
|
|
|
|
queryset = Band.objects.all()
|
|
|
|
serializer_class = BandSerializer
|
|
|
|
|
|
|
|
|
|
|
|
class FrequencyViewSet(viewsets.ReadOnlyModelViewSet):
|
|
|
|
queryset = Frequency.objects.all()
|
|
|
|
serializer_class = FrequencySerializer
|
|
|
|
|
|
|
|
|
|
|
|
class EntryCategoryViewSet(viewsets.ReadOnlyModelViewSet):
|
|
|
|
queryset = EntryCategory.objects.all()
|
|
|
|
serializer_class = EntryCategorySerializer
|
|
|
|
|
|
|
|
|
|
|
|
class ReferenceViewSet(viewsets.ReadOnlyModelViewSet):
|
|
|
|
permission_classes = [IsAdminUser]
|
|
|
|
queryset = Reference.objects.all()
|
|
|
|
serializer_class = ReferenceSerializer
|
|
|
|
|
|
|
|
|
|
|
|
class QSOViewSet(viewsets.ReadOnlyModelViewSet):
|
|
|
|
permission_classes = [IsAuthenticated]
|
|
|
|
serializer_class = QSOSerializer
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
return QSO.objects.filter(owner=self.request.user)
|
|
|
|
|
|
|
|
|
2020-02-02 02:10:33 +01:00
|
|
|
class UserProfileView(APIView):
|
|
|
|
permission_classes = [IsAuthenticated]
|
|
|
|
|
|
|
|
def get(self, request, format=None):
|
|
|
|
user = request.user
|
|
|
|
serializer = UserSerializer(user)
|
|
|
|
return Response(serializer.data)
|
2020-02-02 01:48:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ShadowCallViewSet(viewsets.ReadOnlyModelViewSet):
|
|
|
|
permission_classes = [IsAdminUser]
|
|
|
|
queryset = ShadowCall.objects.all()
|
|
|
|
serializer_class = ShadowCallSerializer
|