Django 2.0
[wolnelektury.git] / src / picture / api / views.py
1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 import json
6 from django.http import Http404
7 from rest_framework.permissions import DjangoModelPermissions
8 from rest_framework.response import Response
9 from rest_framework import status
10 from rest_framework.views import APIView
11 from picture.forms import PictureImportForm
12 from picture.models import Picture
13
14
15 class PicturesView(APIView):
16     permission_classes = [DjangoModelPermissions]
17     queryset = Picture.objects.none()  # Required for DjangoModelPermissions
18
19     def post(self, request):
20         data = json.loads(request.POST.get('data'))
21         form = PictureImportForm(data)
22         if form.is_valid():
23             form.save()
24             return Response({}, status=status.HTTP_201_CREATED)
25         else:
26             raise Http404