Show More
@@ -17,8 +17,10 b' Custom paging classes' | |||||
17 | import logging |
|
17 | import logging | |
18 | import re |
|
18 | import re | |
19 |
|
19 | |||
|
20 | import paginate | |||
|
21 | import paginate_sqlalchemy | |||
|
22 | import sqlalchemy.orm | |||
20 | from webhelpers2.html import HTML, literal |
|
23 | from webhelpers2.html import HTML, literal | |
21 | from webhelpers.paginate import Page as _Page |
|
|||
22 |
|
24 | |||
23 | from kallithea.config.routing import url |
|
25 | from kallithea.config.routing import url | |
24 |
|
26 | |||
@@ -26,15 +28,19 b' from kallithea.config.routing import url' | |||||
26 | log = logging.getLogger(__name__) |
|
28 | log = logging.getLogger(__name__) | |
27 |
|
29 | |||
28 |
|
30 | |||
29 |
class Page( |
|
31 | class Page(paginate.Page): | |
30 | """ |
|
32 | ||
31 | Custom pager emitting Bootstrap paginators |
|
|||
32 | """ |
|
|||
33 | def __init__(self, collection, |
|
33 | def __init__(self, collection, | |
34 | page=1, items_per_page=20, item_count=None, |
|
34 | page=1, items_per_page=20, item_count=None, | |
35 | **kwargs): |
|
35 | **kwargs): | |
36 | _Page.__init__(self, collection, page=page, items_per_page=items_per_page, item_count=item_count, |
|
36 | if isinstance(collection, sqlalchemy.orm.query.Query): | |
37 | url=url.current, **kwargs) |
|
37 | collection = paginate_sqlalchemy.SqlalchemyOrmWrapper(collection) | |
|
38 | paginate.Page.__init__(self, collection, page=page, items_per_page=items_per_page, item_count=item_count, | |||
|
39 | url_maker=lambda page: url.current(page=page, **kwargs)) | |||
|
40 | ||||
|
41 | def _pagerlink(self, page, text): | |||
|
42 | """hack to mimic old webhelpers.paginate internals""" | |||
|
43 | return literal('''<li><a class="pager_link" href="%s">%s</a></li>''') % (self.url_maker(page), text) | |||
38 |
|
44 | |||
39 | def _get_pos(self, cur_page, max_page, items): |
|
45 | def _get_pos(self, cur_page, max_page, items): | |
40 | edge = (items / 2) + 1 |
|
46 | edge = (items / 2) + 1 |
@@ -69,6 +69,8 b' requirements = [' | |||||
69 | "bleach >= 3.0, < 3.2", |
|
69 | "bleach >= 3.0, < 3.2", | |
70 | "Click >= 7.0, < 8", |
|
70 | "Click >= 7.0, < 8", | |
71 | "ipaddr >= 2.1.10, < 2.3", |
|
71 | "ipaddr >= 2.1.10, < 2.3", | |
|
72 | "paginate >= 0.5, < 0.6", | |||
|
73 | "paginate_sqlalchemy >= 0.3.0, < 0.4", | |||
72 | ] |
|
74 | ] | |
73 |
|
75 | |||
74 | if not is_windows: |
|
76 | if not is_windows: |
General Comments 0
You need to be logged in to leave comments.
Login now