Show More
@@ -38,8 +38,7 b' from pylons import request, session, tmp' | |||||
38 |
|
38 | |||
39 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
|
39 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator | |
40 | from rhodecode.lib.base import BaseRepoController, render |
|
40 | from rhodecode.lib.base import BaseRepoController, render | |
41 |
|
41 | from rhodecode.lib.helpers import RepoPage | ||
42 | from webhelpers.paginate import Page |
|
|||
43 |
|
42 | |||
44 | log = logging.getLogger(__name__) |
|
43 | log = logging.getLogger(__name__) | |
45 |
|
44 | |||
@@ -68,7 +67,7 b' class ChangelogController(BaseRepoContro' | |||||
68 |
|
67 | |||
69 | p = int(request.params.get('page', 1)) |
|
68 | p = int(request.params.get('page', 1)) | |
70 | c.total_cs = len(c.rhodecode_repo) |
|
69 | c.total_cs = len(c.rhodecode_repo) | |
71 | c.pagination = Page(c.rhodecode_repo, page=p, item_count=c.total_cs, |
|
70 | c.pagination = RepoPage(c.rhodecode_repo, page=p, item_count=c.total_cs, | |
72 | items_per_page=c.size) |
|
71 | items_per_page=c.size) | |
73 |
|
72 | |||
74 | self._graph(c.rhodecode_repo, c.size, p) |
|
73 | self._graph(c.rhodecode_repo, c.size, p) |
@@ -29,13 +29,15 b' import logging' | |||||
29 |
|
29 | |||
30 | from pylons import tmpl_context as c, request |
|
30 | from pylons import tmpl_context as c, request | |
31 |
|
31 | |||
32 | from webhelpers.paginate import Page |
|
|||
33 |
|
||||
34 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
|
32 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator | |
35 | from rhodecode.lib.base import BaseRepoController, render |
|
33 | from rhodecode.lib.base import BaseRepoController, render | |
|
34 | from rhodecode.lib.helpers import RepoPage | |||
36 |
|
35 | |||
37 | log = logging.getLogger(__name__) |
|
36 | log = logging.getLogger(__name__) | |
38 |
|
37 | |||
|
38 | ||||
|
39 | ||||
|
40 | ||||
39 | class ShortlogController(BaseRepoController): |
|
41 | class ShortlogController(BaseRepoController): | |
40 |
|
42 | |||
41 | @LoginRequired() |
|
43 | @LoginRequired() | |
@@ -46,7 +48,7 b' class ShortlogController(BaseRepoControl' | |||||
46 |
|
48 | |||
47 | def index(self): |
|
49 | def index(self): | |
48 | p = int(request.params.get('page', 1)) |
|
50 | p = int(request.params.get('page', 1)) | |
49 | c.repo_changesets = Page(c.rhodecode_repo, page=p, items_per_page=20) |
|
51 | c.repo_changesets = RepoPage(c.rhodecode_repo, page=p, items_per_page=20) | |
50 | c.shortlog_data = render('shortlog/shortlog_data.html') |
|
52 | c.shortlog_data = render('shortlog/shortlog_data.html') | |
51 | if request.params.get('partial'): |
|
53 | if request.params.get('partial'): | |
52 | return c.shortlog_data |
|
54 | return c.shortlog_data |
@@ -43,8 +43,7 b' from rhodecode.lib.utils import OrderedD' | |||||
43 |
|
43 | |||
44 | from rhodecode.lib.celerylib import run_task |
|
44 | from rhodecode.lib.celerylib import run_task | |
45 | from rhodecode.lib.celerylib.tasks import get_commits_stats |
|
45 | from rhodecode.lib.celerylib.tasks import get_commits_stats | |
46 |
|
46 | from rhodecode.lib.helpers import RepoPage | ||
47 | from webhelpers.paginate import Page |
|
|||
48 |
|
47 | |||
49 | try: |
|
48 | try: | |
50 | import json |
|
49 | import json | |
@@ -70,7 +69,7 b' class SummaryController(BaseRepoControll' | |||||
70 | def url_generator(**kw): |
|
69 | def url_generator(**kw): | |
71 | return url('shortlog_home', repo_name=c.repo_name, **kw) |
|
70 | return url('shortlog_home', repo_name=c.repo_name, **kw) | |
72 |
|
71 | |||
73 | c.repo_changesets = Page(c.repo, page=1, items_per_page=10, |
|
72 | c.repo_changesets = RepoPage(c.repo, page=1, items_per_page=10, | |
74 | url=url_generator) |
|
73 | url=url_generator) | |
75 |
|
74 | |||
76 | e = request.environ |
|
75 | e = request.environ |
@@ -29,7 +29,7 b' from webhelpers.text import chop_at, col' | |||||
29 | convert_misc_entities, lchop, plural, rchop, remove_formatting, \ |
|
29 | convert_misc_entities, lchop, plural, rchop, remove_formatting, \ | |
30 | replace_whitespace, urlify, truncate, wrap_paragraphs |
|
30 | replace_whitespace, urlify, truncate, wrap_paragraphs | |
31 | from webhelpers.date import time_ago_in_words |
|
31 | from webhelpers.date import time_ago_in_words | |
32 |
|
32 | from webhelpers.paginate import Page | ||
33 | from webhelpers.html.tags import _set_input_attrs, _set_id_attr, \ |
|
33 | from webhelpers.html.tags import _set_input_attrs, _set_id_attr, \ | |
34 | convert_boolean_attrs, NotGiven |
|
34 | convert_boolean_attrs, NotGiven | |
35 |
|
35 | |||
@@ -575,6 +575,92 b' def gravatar_url(email_address, size=30)' | |||||
575 |
|
575 | |||
576 | return gravatar_url |
|
576 | return gravatar_url | |
577 |
|
577 | |||
|
578 | ||||
|
579 | #============================================================================== | |||
|
580 | # REPO PAGER | |||
|
581 | #============================================================================== | |||
|
582 | class RepoPage(Page): | |||
|
583 | ||||
|
584 | def __init__(self, collection, page=1, items_per_page=20, | |||
|
585 | item_count=None, url=None, **kwargs): | |||
|
586 | ||||
|
587 | """Create a "RepoPage" instance. special pager for paging | |||
|
588 | repository | |||
|
589 | """ | |||
|
590 | self._url_generator = url | |||
|
591 | ||||
|
592 | # Safe the kwargs class-wide so they can be used in the pager() method | |||
|
593 | self.kwargs = kwargs | |||
|
594 | ||||
|
595 | # Save a reference to the collection | |||
|
596 | self.original_collection = collection | |||
|
597 | ||||
|
598 | self.collection = collection | |||
|
599 | ||||
|
600 | # The self.page is the number of the current page. | |||
|
601 | # The first page has the number 1! | |||
|
602 | try: | |||
|
603 | self.page = int(page) # make it int() if we get it as a string | |||
|
604 | except (ValueError, TypeError): | |||
|
605 | self.page = 1 | |||
|
606 | ||||
|
607 | self.items_per_page = items_per_page | |||
|
608 | ||||
|
609 | # Unless the user tells us how many items the collections has | |||
|
610 | # we calculate that ourselves. | |||
|
611 | if item_count is not None: | |||
|
612 | self.item_count = item_count | |||
|
613 | else: | |||
|
614 | self.item_count = len(self.collection) | |||
|
615 | ||||
|
616 | # Compute the number of the first and last available page | |||
|
617 | if self.item_count > 0: | |||
|
618 | self.first_page = 1 | |||
|
619 | self.page_count = ((self.item_count - 1) / self.items_per_page) + 1 | |||
|
620 | self.last_page = self.first_page + self.page_count - 1 | |||
|
621 | ||||
|
622 | # Make sure that the requested page number is the range of valid pages | |||
|
623 | if self.page > self.last_page: | |||
|
624 | self.page = self.last_page | |||
|
625 | elif self.page < self.first_page: | |||
|
626 | self.page = self.first_page | |||
|
627 | ||||
|
628 | # Note: the number of items on this page can be less than | |||
|
629 | # items_per_page if the last page is not full | |||
|
630 | self.first_item = max(0, (self.item_count) - (self.page * items_per_page)) | |||
|
631 | self.last_item = ((self.item_count - 1) - items_per_page * (self.page - 1)) + 1 | |||
|
632 | ||||
|
633 | iterator = self.collection.get_changesets(start=self.first_item, | |||
|
634 | end=self.last_item, | |||
|
635 | reverse=True) | |||
|
636 | self.items = list(iterator) | |||
|
637 | ||||
|
638 | # Links to previous and next page | |||
|
639 | if self.page > self.first_page: | |||
|
640 | self.previous_page = self.page - 1 | |||
|
641 | else: | |||
|
642 | self.previous_page = None | |||
|
643 | ||||
|
644 | if self.page < self.last_page: | |||
|
645 | self.next_page = self.page + 1 | |||
|
646 | else: | |||
|
647 | self.next_page = None | |||
|
648 | ||||
|
649 | # No items available | |||
|
650 | else: | |||
|
651 | self.first_page = None | |||
|
652 | self.page_count = 0 | |||
|
653 | self.last_page = None | |||
|
654 | self.first_item = None | |||
|
655 | self.last_item = None | |||
|
656 | self.previous_page = None | |||
|
657 | self.next_page = None | |||
|
658 | self.items = [] | |||
|
659 | ||||
|
660 | # This is a subclass of the 'list' type. Initialise the list now. | |||
|
661 | list.__init__(self, self.items) | |||
|
662 | ||||
|
663 | ||||
578 | def safe_unicode(str): |
|
664 | def safe_unicode(str): | |
579 | """safe unicode function. In case of UnicodeDecode error we try to return |
|
665 | """safe unicode function. In case of UnicodeDecode error we try to return | |
580 | unicode with errors replace, if this failes we return unicode with |
|
666 | unicode with errors replace, if this failes we return unicode with |
General Comments 0
You need to be logged in to leave comments.
Login now