Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

add param to paginate #320

Open
wants to merge 3 commits into
base: 0.9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions orator/orm/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, columns=None, column_count=None):
"""
Paginate the given query.

Expand All @@ -296,15 +296,20 @@ 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

:return: The paginator
"""
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()
Expand Down
13 changes: 9 additions & 4 deletions orator/query/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, columns=None, column_count=None):
"""
Paginate the given query.

Expand All @@ -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)

Expand Down Expand Up @@ -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()

Expand Down