Skip to content

Commit

Permalink
apps/budgeting/proposal-list/pagination: using super Response and jus…
Browse files Browse the repository at this point in the history
…t add what is really needed
  • Loading branch information
Kha committed Nov 22, 2021
1 parent 8ec9277 commit 6139057
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
31 changes: 4 additions & 27 deletions meinberlin/apps/budgeting/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from rest_framework import mixins
from rest_framework import status
from rest_framework import viewsets
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response

from adhocracy4.api.mixins import ModuleMixin
from adhocracy4.api.permissions import ViewSetRulesPermission
Expand All @@ -16,32 +14,11 @@
class BudgetPagination(PageNumberPagination):
page_size = 15

def get_next_page(self):
if self.page.has_next():
return self.page.next_page_number()
else:
return None

def get_previous_page(self):
if self.page.has_previous():
return self.page.previous_page_number()
else:
return None

def get_paginated_response(self, data):
return Response({
'status': True,
'results': data,
'meta': {
'results_count': self.page.paginator.count,
'current_page': self.page.number,
'previous_page': self.get_previous_page(),
'next_page': self.get_next_page(),
'page_count': self.page.paginator.num_pages,
'page_size': self.page_size,
'is_paginated': self.page.paginator.num_pages > 1
}},
status=status.HTTP_200_OK)
response = super(BudgetPagination, self).get_paginated_response(data)
response.data['page_size'] = self.page_size
response.data['page_count'] = self.page.paginator.num_pages
return response


class ProposalViewSet(ModuleMixin,
Expand Down
8 changes: 7 additions & 1 deletion meinberlin/apps/budgeting/assets/BudgetingProposalList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ export const BudgetingProposalList = (props) => {
.then(resp => resp.json())
.then(json => {
setData(json.results)
setMeta(json.meta)
setMeta({
current_page: pageNumber,
page_count: json.page_count,
is_paginated: json.page_count > 1,
previous: json.previous,
next: json.next
})
})
.catch(error => console.log(error))
}
Expand Down

0 comments on commit 6139057

Please sign in to comment.