Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add serializer and API view for shitbox submissions #412

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions chemie/shitbox/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework import serializers
from .models import Submission


class SubmissionSerializer(serializers.ModelSerializer):
class Meta:
model = Submission
fields = ("id", "content", "image", "author")
3 changes: 3 additions & 0 deletions chemie/shitbox/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from django.urls import path
from .views import *
from .views import SubmissionListView, SubmissionDetailView

app_name = "shitbox"

urlpatterns = [
path("api/", SubmissionListView.as_view()),
path("api/<int:pk>/", SubmissionDetailView.as_view()),
path("liste/", submissions_overview, name="list"),
path("", post_votes, name="index"),
path("toggle-used", toggle_used, name="toggle-used"),
Expand Down
16 changes: 16 additions & 0 deletions chemie/shitbox/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
from django.http import JsonResponse
from django.contrib.auth.decorators import permission_required
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger

from rest_framework import generics
from rest_framework.parsers import MultiPartParser, FormParser

from .forms import PostForm
from .models import Submission
from .serializers import SubmissionSerializer


@login_required
Expand Down Expand Up @@ -85,3 +90,14 @@ def toggle_used(request):
return JsonResponse({"used": submission.used})
else:
return redirect("shitbox:list")


class SubmissionListView(generics.ListCreateAPIView):
parser_class = [MultiPartParser, FormParser]
queryset = Submission.objects.all()
serializer_class = SubmissionSerializer


class SubmissionDetailView(generics.RetrieveUpdateDestroyAPIView):
queryset = Submission.objects.all()
serializer_class = SubmissionSerializer