You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.3 KiB
42 lines
1.3 KiB
from django.shortcuts import render, get_object_or_404
|
|
from django.http import HttpResponse
|
|
from django.template import loader
|
|
from django.contrib.auth.models import User
|
|
from .models import Match
|
|
from .serializers import UserSerializer, MatchSerializer
|
|
from rest_framework import viewsets
|
|
from rest_framework import permissions
|
|
|
|
def index(request):
|
|
matches = Match.objects.order_by('court')
|
|
template = loader.get_template('scores/index.html')
|
|
context = {
|
|
'matches': matches,
|
|
}
|
|
return HttpResponse(template.render(context, request))
|
|
|
|
def match(request, match_id):
|
|
|
|
match = get_object_or_404(Match, pk=match_id)
|
|
template = loader.get_template('scores/match.html')
|
|
context = {
|
|
'match': match,
|
|
}
|
|
return HttpResponse(template.render(context, request))
|
|
|
|
|
|
class UserViewSet(viewsets.ModelViewSet):
|
|
"""
|
|
API endpoint that allows users to be viewed or edited.
|
|
"""
|
|
queryset = User.objects.all().order_by('-date_joined')
|
|
serializer_class = UserSerializer
|
|
permission_classes = [permissions.IsAuthenticated]
|
|
|
|
class MatchViewSet(viewsets.ModelViewSet):
|
|
"""
|
|
API endpoint that allows matches to be viewed or edited.
|
|
"""
|
|
queryset = Match.objects.all().order_by('court')
|
|
serializer_class = MatchSerializer
|
|
permission_classes = [permissions.IsAuthenticated]
|
|
|