Mercurial > kallithea
changeset 7975:3936f5cc4c58
page: replace RepoPage with Page given the reverse collection
That seems to be all RepoPage did ...
We must still take care to make sure the collection works correctly, even when
filtered so indices might be higher than repo length. vcs module takes care of
that by internally creating a list of hashes (which it can reverse), while the
Changeset instances are only created on demand. We can save some resources by
not retrieving the whole list of Changesets just to reverse it so we can use a
few entries.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Sat, 16 Nov 2019 22:49:59 +0100 |
parents | ae98ec548fd4 |
children | 2a6b6baf1448 |
files | kallithea/controllers/changelog.py kallithea/controllers/summary.py kallithea/lib/page.py |
diffstat | 3 files changed, 7 insertions(+), 94 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/changelog.py Sun Nov 24 02:22:27 2019 +0100 +++ b/kallithea/controllers/changelog.py Sat Nov 16 22:49:59 2019 +0100 @@ -38,7 +38,7 @@ from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired from kallithea.lib.base import BaseRepoController, render from kallithea.lib.graphmod import graph_data -from kallithea.lib.page import RepoPage +from kallithea.lib.page import Page from kallithea.lib.utils2 import safe_int, safe_str from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, ChangesetError, EmptyRepositoryError, NodeDoesNotExistError, RepositoryError @@ -113,14 +113,13 @@ except RepositoryError as e: h.flash(safe_str(e), category='warning') raise HTTPFound(location=h.url('changelog_home', repo_name=repo_name)) - collection = list(reversed(collection)) else: collection = c.db_repo_scm_instance.get_changesets(start=0, end=revision, - branch_name=branch_name) + branch_name=branch_name, reverse=True) c.total_cs = len(collection) - c.cs_pagination = RepoPage(collection, page=p, item_count=c.total_cs, - items_per_page=c.size, branch=branch_name,) + c.cs_pagination = Page(collection, page=p, item_count=c.total_cs, items_per_page=c.size, + branch=branch_name) page_revisions = [x.raw_id for x in c.cs_pagination] c.cs_comments = c.db_repo.get_comments(page_revisions)
--- a/kallithea/controllers/summary.py Sun Nov 24 02:22:27 2019 +0100 +++ b/kallithea/controllers/summary.py Sat Nov 16 22:49:59 2019 +0100 @@ -45,7 +45,7 @@ from kallithea.lib.celerylib.tasks import get_commits_stats from kallithea.lib.compat import json from kallithea.lib.markup_renderer import MarkupRenderer -from kallithea.lib.page import RepoPage +from kallithea.lib.page import Page from kallithea.lib.utils2 import safe_int, safe_str from kallithea.lib.vcs.backends.base import EmptyChangeset from kallithea.lib.vcs.exceptions import ChangesetError, EmptyRepositoryError, NodeDoesNotExistError @@ -106,11 +106,11 @@ p = safe_int(request.GET.get('page'), 1) size = safe_int(request.GET.get('size'), 10) try: - collection = c.db_repo_scm_instance.get_changesets() + collection = c.db_repo_scm_instance.get_changesets(reverse=True) except EmptyRepositoryError as e: h.flash(safe_str(e), category='warning') collection = [] - c.cs_pagination = RepoPage(collection, page=p, items_per_page=size) + c.cs_pagination = Page(collection, page=p, items_per_page=size) page_revisions = [x.raw_id for x in list(c.cs_pagination)] c.cs_comments = c.db_repo.get_comments(page_revisions) c.cs_statuses = c.db_repo.statuses(page_revisions)
--- a/kallithea/lib/page.py Sun Nov 24 02:22:27 2019 +0100 +++ b/kallithea/lib/page.py Sat Nov 16 22:49:59 2019 +0100 @@ -15,7 +15,6 @@ Custom paging classes """ import logging -import math import re from webhelpers2.html import HTML, literal @@ -168,88 +167,3 @@ }) return literal(result) - - -class RepoPage(Page): - - def __init__(self, collection, page=1, items_per_page=20, - item_count=None, **kwargs): - - """Create a "RepoPage" instance. special pager for paging - repository - """ - # TODO: call baseclass __init__ - self._url_generator = kwargs.pop('url', url.current) - - # Safe the kwargs class-wide so they can be used in the pager() method - self.kwargs = kwargs - - # Save a reference to the collection - self.original_collection = collection - - self.collection = collection - - # The self.page is the number of the current page. - # The first page has the number 1! - try: - self.page = int(page) # make it int() if we get it as a string - except (ValueError, TypeError): - log.error("Invalid page value: %r", page) - self.page = 1 - - self.items_per_page = items_per_page - - # Unless the user tells us how many items the collections has - # we calculate that ourselves. - if item_count is not None: - self.item_count = item_count - else: - self.item_count = len(self.collection) - - # Compute the number of the first and last available page - if self.item_count > 0: - self.first_page = 1 - self.page_count = int(math.ceil(float(self.item_count) / - self.items_per_page)) - self.last_page = self.first_page + self.page_count - 1 - - # Make sure that the requested page number is the range of - # valid pages - if self.page > self.last_page: - self.page = self.last_page - elif self.page < self.first_page: - self.page = self.first_page - - # Note: the number of items on this page can be less than - # items_per_page if the last page is not full - self.first_item = max(0, (self.item_count) - (self.page * - items_per_page)) - self.last_item = ((self.item_count - 1) - items_per_page * - (self.page - 1)) - - self.items = list(self.collection[self.first_item:self.last_item + 1]) - - # Links to previous and next page - if self.page > self.first_page: - self.previous_page = self.page - 1 - else: - self.previous_page = None - - if self.page < self.last_page: - self.next_page = self.page + 1 - else: - self.next_page = None - - # No items available - else: - self.first_page = None - self.page_count = 0 - self.last_page = None - self.first_item = None - self.last_item = None - self.previous_page = None - self.next_page = None - self.items = [] - - # This is a subclass of the 'list' type. Initialise the list now. - list.__init__(self, reversed(self.items))