From b23167673633a0efb605bce2dbef02d98d779089 Mon Sep 17 00:00:00 2001 From: Kseninia Mikhaylova Date: Fri, 19 Jul 2024 10:39:13 +0300 Subject: [PATCH] add pagination --- back/api/settings.py | 4 ++-- back/tgbot/pagination.py | 10 ++++++++++ back/tgbot/tgbot.py | 6 ++++++ back/tgbot/views.py | 2 +- front/pages/table/index.vue | 14 +++++++++++--- front/types/index.d.ts | 1 + 6 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 back/tgbot/pagination.py diff --git a/back/api/settings.py b/back/api/settings.py index 6c77a83..a4883fd 100644 --- a/back/api/settings.py +++ b/back/api/settings.py @@ -95,8 +95,8 @@ WSGI_APPLICATION = "api.wsgi.application" # Rest Framework REST_FRAMEWORK = { - "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination", - "PAGE_SIZE": 10, + "DEFAULT_PAGINATION_CLASS": "tgbot.pagination.CustomPagination", + "PAGE_SIZE": 5, } diff --git a/back/tgbot/pagination.py b/back/tgbot/pagination.py new file mode 100644 index 0000000..1e1aecb --- /dev/null +++ b/back/tgbot/pagination.py @@ -0,0 +1,10 @@ +from rest_framework import pagination +from rest_framework.response import Response + +class CustomPagination(pagination.PageNumberPagination): + def get_paginated_response(self, data): + return Response({ + 'count': self.page.paginator.count, + 'per_page': self.page.paginator.per_page, + 'results': data + }) diff --git a/back/tgbot/tgbot.py b/back/tgbot/tgbot.py index 8a688d5..57dbfc2 100644 --- a/back/tgbot/tgbot.py +++ b/back/tgbot/tgbot.py @@ -127,6 +127,12 @@ class TgBot: "У вас нет доступных для редактирования инвентаризаций" ) + async def format_text(self, user, inv=None, tmc=None): + text = ( + f"Специалист {user.full_name}, ID {user.id}\n" + f"Введите название объекта" + ), + async def get_inv(self, update: Update, context: CallbackContext): query = update.callback_query await update.effective_message.edit_reply_markup(InlineKeyboardMarkup([])) diff --git a/back/tgbot/views.py b/back/tgbot/views.py index c1560a9..b120822 100644 --- a/back/tgbot/views.py +++ b/back/tgbot/views.py @@ -19,7 +19,7 @@ logger = logging.getLogger("root") class TgItemViewSet(viewsets.ModelViewSet): - queryset = TgItem.objects.all() + queryset = TgItem.objects.all().order_by('-updated_at') serializer_class = TgItemSerializer http_method_names = ["post", "get"] diff --git a/front/pages/table/index.vue b/front/pages/table/index.vue index 8827df0..5ec5f31 100644 --- a/front/pages/table/index.vue +++ b/front/pages/table/index.vue @@ -1,9 +1,16 @@