Skip to content

Commit d1c0279

Browse files
authored
Merge pull request #149 from PROCOLLAB-github/feature/projects-news
Pagination for projects news
2 parents cd0b5d7 + 761e8b0 commit d1c0279

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

projects/pagination.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from rest_framework import pagination
2+
3+
4+
class ProjectNewsPagination(pagination.LimitOffsetPagination):
5+
"""
6+
Pagination for project news
7+
8+
For example:
9+
/projects/1/news/?limit=10&offset=10
10+
gets the next 10 news after the first 10 news.
11+
"""
12+
13+
default_limit = 5
14+
limit_query_param = "limit"
15+
offset_query_param = "offset"

projects/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from projects.constants import VERBOSE_STEPS
1414
from projects.helpers import get_recommended_users, check_related_fields_update
1515
from projects.models import Project, Achievement, ProjectNews
16+
from projects.pagination import ProjectNewsPagination
1617
from projects.permissions import (
1718
IsProjectLeaderOrReadOnlyForNonDrafts,
1819
HasInvolvementInProjectOrReadOnly,
@@ -233,6 +234,7 @@ def get(self, request, pk):
233234
class ProjectNewsList(generics.ListCreateAPIView):
234235
serializer_class = ProjectNewsListSerializer
235236
permission_classes = [IsNewsAuthorIsProjectLeaderOrReadOnly]
237+
pagination_class = ProjectNewsPagination
236238

237239
def perform_create(self, serializer):
238240
project = Project.objects.get(pk=self.kwargs.get("project_pk"))

0 commit comments

Comments
 (0)