cqtu/api/views.py

53 lines
1.6 KiB
Python

from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticated, IsAdminUser
from .serializers import ContestSerializer, BandSerializer, FrequencySerializer, EntryCategorySerializer, \
ReferenceSerializer, QSOSerializer, ShadowCallSerializer
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)
class UserProfile(viewsets.ReadOnlyModelViewSet):
"""Return the currently authenticated user as a single item"""
pass
class ShadowCallViewSet(viewsets.ReadOnlyModelViewSet):
permission_classes = [IsAdminUser]
queryset = ShadowCall.objects.all()
serializer_class = ShadowCallSerializer