X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/c3e563338050cf161ed6568d01c8a5f010257c2f..ff382f6c37063c0c4c5d21c2834a8759e25c5d02:/src/api/views.py diff --git a/src/api/views.py b/src/api/views.py index 812be832c..377beb681 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -1,8 +1,13 @@ +# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# from django.http import Http404 from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from rest_framework.generics import RetrieveAPIView, get_object_or_404 +from rest_framework.generics import ListAPIView, RetrieveAPIView, get_object_or_404 +from migdal.models import Entry from catalogue.models import Book from .models import BookUserData from . import serializers @@ -39,3 +44,17 @@ class BookUserDataView(RetrieveAPIView): instance = BookUserData.update(book, request.user, state) serializer = self.get_serializer(instance) return Response(serializer.data) + + +class BlogView(ListAPIView): + serializer_class = serializers.BlogSerializer + + def get_queryset(self): + after = self.request.query_params.get('after') + count = int(self.request.query_params.get('count', 20)) + entries = Entry.published_objects.filter(in_stream=True).order_by('-first_published_at') + if after: + entries = entries.filter(first_published_at__lt=after) + if count: + entries = entries[:count] + return entries