Changeset - 2323e2bb2797
[Not reviewed]
default
0 4 0
Mads Kiilerich - 6 years ago 2019-11-08 00:23:10
mads@kiilerich.com
Grafted from: c97a16f46588
page: consistently invoke Page with kwargs instead of explicitly providing a custom url generator

Drop the option of providing an url maker as 'url', and thus also hardcode the
assumption that the page parameter is called page.
4 files changed with 11 insertions and 20 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/admin.py
Show inline comments
 
@@ -36,7 +36,6 @@ from whoosh import query
 
from whoosh.qparser.dateparse import DateParserPlugin
 
from whoosh.qparser.default import QueryParser
 

	
 
from kallithea.config.routing import url
 
from kallithea.lib.auth import HasPermissionAnyDecorator, LoginRequired
 
from kallithea.lib.base import BaseController, render
 
from kallithea.lib.indexers import JOURNAL_SCHEMA
 
@@ -139,10 +138,8 @@ class AdminController(BaseController):
 

	
 
        p = safe_int(request.GET.get('page'), 1)
 

	
 
        def url_generator(**kw):
 
            return url.current(filter=c.search_term, **kw)
 

	
 
        c.users_log = Page(users_log, page=p, items_per_page=10, url=url_generator)
 
        c.users_log = Page(users_log, page=p, items_per_page=10,
 
                           filter=c.search_term)
 

	
 
        if request.environ.get('HTTP_X_PARTIAL_XHR'):
 
            return render('admin/admin_log.html')
kallithea/controllers/journal.py
Show inline comments
 
@@ -39,7 +39,6 @@ from webhelpers.feedgenerator import Ato
 
from webob.exc import HTTPBadRequest
 

	
 
import kallithea.lib.helpers as h
 
from kallithea.config.routing import url
 
from kallithea.controllers.admin.admin import _journal_filter
 
from kallithea.lib.auth import LoginRequired
 
from kallithea.lib.base import BaseController, render
 
@@ -201,10 +200,8 @@ class JournalController(BaseController):
 

	
 
        journal = self._get_journal_data(c.following)
 

	
 
        def url_generator(**kw):
 
            return url.current(filter=c.search_term, **kw)
 

	
 
        c.journal_pager = Page(journal, page=p, items_per_page=20, url=url_generator)
 
        c.journal_pager = Page(journal, page=p, items_per_page=20,
 
                               filter=c.search_term)
 
        c.journal_day_aggregate = self._get_daily_aggregate(c.journal_pager)
 

	
 
        if request.environ.get('HTTP_X_PARTIAL_XHR'):
kallithea/controllers/search.py
Show inline comments
 
@@ -27,12 +27,10 @@ Original author and date, and relevant c
 

	
 
import logging
 
import traceback
 
import urllib
 

	
 
from tg import config, request
 
from tg import tmpl_context as c
 
from tg.i18n import ugettext as _
 
from webhelpers2.html.tools import update_params
 
from whoosh.index import EmptyIndexError, exists_in, open_dir
 
from whoosh.qparser import QueryParser, QueryParserError
 
from whoosh.query import Phrase, Prefix
 
@@ -119,9 +117,6 @@ class SearchController(BaseRepoControlle
 
                        res_ln, results.runtime
 
                    )
 

	
 
                    def url_generator(**kw):
 
                        q = urllib.quote(safe_str(c.cur_query))
 
                        return update_params("?q=%s&type=%s" % (q, safe_str(c.cur_type)), **kw)
 
                    repo_location = RepoModel().repos_path
 
                    c.formated_results = Page(
 
                        WhooshResultWrapper(search_type, searcher, matcher,
 
@@ -129,7 +124,8 @@ class SearchController(BaseRepoControlle
 
                        page=p,
 
                        item_count=res_ln,
 
                        items_per_page=10,
 
                        url=url_generator
 
                        type=safe_str(c.cur_type),
 
                        q=safe_str(c.cur_query),
 
                    )
 

	
 
                except QueryParserError:
kallithea/lib/page.py
Show inline comments
 
@@ -30,10 +30,11 @@ class Page(_Page):
 
    """
 
    Custom pager emitting Bootstrap paginators
 
    """
 

	
 
    def __init__(self, *args, **kwargs):
 
        kwargs.setdefault('url', url.current)
 
        _Page.__init__(self, *args, **kwargs)
 
    def __init__(self, collection,
 
                 page=1, items_per_page=20, item_count=None,
 
                 **kwargs):
 
        _Page.__init__(self, collection, page=page, items_per_page=items_per_page, item_count=item_count,
 
                       url=url.current, **kwargs)
 

	
 
    def _get_pos(self, cur_page, max_page, items):
 
        edge = (items / 2) + 1
0 comments (0 inline, 0 general)