From 1536bcd6468e07c521721256c4460e46a165288a Mon Sep 17 00:00:00 2001 From: Bahruddin El Hayat Date: Mon, 19 Aug 2019 14:31:11 +0700 Subject: [PATCH 1/3] add param to paginate --- orator/query/builder.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/orator/query/builder.py b/orator/query/builder.py index 6e8aaa6c..f54b9343 100644 --- a/orator/query/builder.py +++ b/orator/query/builder.py @@ -1064,7 +1064,7 @@ def _run_select(self): self.to_sql(), self.get_bindings(), not self._use_write_connection ) - def paginate(self, per_page=15, current_page=None, columns=None): + def paginate(self, per_page=15, current_page=None, column_count=None, columns=None): """ Paginate the given query. @@ -1077,15 +1077,20 @@ def paginate(self, per_page=15, current_page=None, columns=None): :param columns: The columns to return :type columns: list + :param column_count: The columns that used to get count + :type column_count: list + :return: The paginator :rtype: LengthAwarePaginator """ if columns is None: columns = ["*"] + if column_count is None: + column_count = ["*"] page = current_page or Paginator.resolve_current_page() - total = self.get_count_for_pagination() + total = self.get_count_for_pagination(column_count) results = self.for_page(page, per_page).get(columns) @@ -1116,10 +1121,10 @@ def simple_paginate(self, per_page=15, current_page=None, columns=None): return Paginator(self.get(columns), per_page, page) - def get_count_for_pagination(self): + def get_count_for_pagination(self, column_count): self._backup_fields_for_count() - total = self.count() + total = self.count(column_count) self._restore_fields_for_count() From a39c8f0c4ab60eac75a3ecfa4e6d29eb1e5144cf Mon Sep 17 00:00:00 2001 From: Bahruddin El Hayat Date: Tue, 20 Aug 2019 10:39:25 +0700 Subject: [PATCH 2/3] add new param --- orator/orm/builder.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/orator/orm/builder.py b/orator/orm/builder.py index 72a7441e..449a5894 100644 --- a/orator/orm/builder.py +++ b/orator/orm/builder.py @@ -286,7 +286,7 @@ def lists(self, column, key=None): results[i] = self._model.new_from_builder(fill).column - def paginate(self, per_page=None, current_page=None, columns=None): + def paginate(self, per_page=None, current_page=None, column_count=None, columns=None): """ Paginate the given query. @@ -296,6 +296,9 @@ def paginate(self, per_page=None, current_page=None, columns=None): :param current_page: The current page of results :type current_page: int + :param column_count: The columns that used to get count + :type column_count: list + :param columns: The columns to return :type columns: list @@ -303,8 +306,10 @@ def paginate(self, per_page=None, current_page=None, columns=None): """ if columns is None: columns = ["*"] + if column_count is None: + column_count = ["*"] - total = self.to_base().get_count_for_pagination() + total = self.to_base().get_count_for_pagination(column_count) page = current_page or Paginator.resolve_current_page() per_page = per_page or self._model.get_per_page() From 1e929d9e7a358d36dab19a33105debe3e23ed4e1 Mon Sep 17 00:00:00 2001 From: codingin Date: Mon, 25 Nov 2019 13:14:47 +0700 Subject: [PATCH 3/3] move column_count param to last param --- orator/orm/builder.py | 2 +- orator/query/builder.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/orator/orm/builder.py b/orator/orm/builder.py index 449a5894..ca3f5bcd 100644 --- a/orator/orm/builder.py +++ b/orator/orm/builder.py @@ -286,7 +286,7 @@ def lists(self, column, key=None): results[i] = self._model.new_from_builder(fill).column - def paginate(self, per_page=None, current_page=None, column_count=None, columns=None): + def paginate(self, per_page=None, current_page=None, columns=None, column_count=None): """ Paginate the given query. diff --git a/orator/query/builder.py b/orator/query/builder.py index f54b9343..80f094a6 100644 --- a/orator/query/builder.py +++ b/orator/query/builder.py @@ -1064,7 +1064,7 @@ def _run_select(self): self.to_sql(), self.get_bindings(), not self._use_write_connection ) - def paginate(self, per_page=15, current_page=None, column_count=None, columns=None): + def paginate(self, per_page=15, current_page=None, columns=None, column_count=None): """ Paginate the given query.