Refactor frontend views
All checks were successful
Build and push image / build-containers (push) Successful in 10m14s
All checks were successful
Build and push image / build-containers (push) Successful in 10m14s
This commit is contained in:
@ -0,0 +1,41 @@
|
||||
"""Common utilities."""
|
||||
|
||||
import math
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class PagingInfo(BaseModel):
|
||||
page: int
|
||||
limit: int
|
||||
total: int
|
||||
offset: int = 0
|
||||
|
||||
@property
|
||||
def first(self) -> int:
|
||||
"""The first result number."""
|
||||
return self.offset + 1
|
||||
|
||||
@property
|
||||
def last(self) -> int:
|
||||
"""Return the last result number."""
|
||||
return self.offset + self.limit
|
||||
|
||||
@property
|
||||
def total_pages(self) -> int:
|
||||
"""Return total pages."""
|
||||
return math.ceil(self.total / self.limit)
|
||||
|
||||
@property
|
||||
def pages(self) -> list[int]:
|
||||
"""Return all page numbers."""
|
||||
return [page for page in range(1, self.total_pages + 1)]
|
||||
|
||||
@property
|
||||
def is_last(self) -> bool:
|
||||
"""Is this the last page?"""
|
||||
return self.page == self.total_pages
|
||||
|
||||
@property
|
||||
def is_first(self) -> bool:
|
||||
"""Is this the first page?"""
|
||||
return self.page == 1
|
||||
Reference in New Issue
Block a user