Add identifying string to Signups and list them on Forms
This commit is contained in:
+13
-3
@@ -10,9 +10,9 @@ from django.shortcuts import render
|
||||
from django.views.decorators.http import require_http_methods
|
||||
from django_filters import rest_framework as filters
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from rest_framework import permissions, routers, viewsets
|
||||
from rest_framework import routers, viewsets
|
||||
from rest_framework.filters import OrderingFilter, SearchFilter
|
||||
from rest_framework.permissions import IsAuthenticatedOrReadOnly
|
||||
from rest_framework.permissions import IsAuthenticatedOrReadOnly, BasePermission
|
||||
from jsonschema import validate
|
||||
from jsonschema.exceptions import ValidationError
|
||||
|
||||
@@ -22,7 +22,7 @@ from webapp.serializers import (EventSerializer, SignupFormSerializer, SignupSer
|
||||
OccupationSerializer, TagSerializer)
|
||||
|
||||
|
||||
class IsPostOrIsAuthenticated(permissions.BasePermission):
|
||||
class IsPostOrIsAuthenticated(BasePermission):
|
||||
|
||||
def has_permission(self, request, view):
|
||||
if request.method == 'POST':
|
||||
@@ -63,6 +63,16 @@ class SignupFormViewSet(viewsets.ModelViewSet):
|
||||
# filter_fields = '__all__'
|
||||
# search_fields = '__all__'
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
try:
|
||||
schema = {
|
||||
"type": "array",
|
||||
}
|
||||
validate(instance=request.data["questions"], schema=schema)
|
||||
return super().create(request, *args, **kwargs)
|
||||
except ValidationError as err:
|
||||
return JsonResponse(status=400, data={"error": err.message})
|
||||
|
||||
def get_queryset(self):
|
||||
if self.request.user.is_authenticated:
|
||||
return SignupForm.objects.all().order_by('start_time')
|
||||
|
||||
Reference in New Issue
Block a user