class ListComments(CodeComments): implements(IRequestHandler) COMMENTS_PER_PAGE = 50 # IRequestHandler methods def match_request(self, req): return req.path_info == '/' + self.href def process_request(self, req): req.perm.require('TRAC_ADMIN') self.data = {} self.args = {} self.req = req self.per_page = int(req.args.get('per-page', self.COMMENTS_PER_PAGE)) self.page = int(req.args.get('page', 1)) self.order_by = req.args.get('orderby', 'id') self.order = req.args.get('order', 'DESC') self.add_path_and_author_filters() self.comments = Comments(req, self.env); self.data['comments'] = self.comments.search(self.args, self.order, self.per_page, self.page, self.order_by) self.data['reponame'], repos, path = RepositoryManager(self.env).get_repository_by_path('/') self.data['can_delete'] = 'TRAC_ADMIN' in req.perm self.data['paginator'] = self.get_paginator() self.data['current_sorting_method'] = self.order_by self.data['current_order'] = self.order self.data['sortable_headers'] = [] self.data.update(self.comments.get_filter_values()) self.prepare_sortable_headers() return 'comments.html', self.data, None def post_process_request(self, req, template, data, content_type): add_stylesheet(req, 'code-comments/sort/sort.css') add_script(req, 'code-comments/code-comments-list.js') return template, data, content_type def add_path_and_author_filters(self): self.data['current_path_selection'] = ''; self.data['current_author_selection'] = ''; if self.req.args.get('filter-by-path'): self.args['path__prefix'] = self.req.args['filter-by-path']; self.data['current_path_selection'] = self.req.args['filter-by-path'] if self.req.args.get('filter-by-author'): self.args['author'] = self.req.args['filter-by-author'] self.data['current_author_selection'] = self.req.args['filter-by-author'] def get_paginator(self): def href_with_page(page): args = copy.copy(self.req.args) args['page'] = page return self.req.href(self.href, args) paginator = Paginator(self.data['comments'], self.page-1, self.per_page, Comments(self.req, self.env).count(self.args)) if paginator.has_next_page: add_link(self.req, 'next', href_with_page(self.page + 1), 'Next Page') if paginator.has_previous_page: add_link(self.req, 'prev', href_with_page(self.page - 1), 'Previous Page') shown_pages = paginator.get_shown_pages(page_index_count = 11) links = [{'href': href_with_page(page), 'class': None, 'string': str(page), 'title': 'Page %d' % page} for page in shown_pages] paginator.shown_pages = links paginator.current_page = {'href': None, 'class': 'current', 'string': str(paginator.page + 1), 'title': None} return paginator def prepare_sortable_headers(self): displayed_sorting_methods = ('id', 'author', 'time', 'path', 'text') displayed_sorting_method_names = ('ID', 'Author', 'Date', 'Path', 'Text') query_args = self.req.args if ( query_args.has_key('page') ): del query_args['page'] for sorting_method, sorting_method_name in zip(displayed_sorting_methods, displayed_sorting_method_names): query_args['orderby'] = sorting_method html_class = 'header' if self.order_by == sorting_method: if 'ASC' == self.order: query_args['order'] = 'DESC' html_class += ' headerSortUp' else: query_args['order'] = 'ASC' html_class += ' headerSortDown' link = self.req.href(self.href, query_args) self.data['sortable_headers'].append({ 'name': sorting_method_name, 'link': link, 'html_class': html_class })
class ListComments(CodeComments): implements(IRequestHandler) COMMENTS_PER_PAGE = 50 # IRequestHandler methods def match_request(self, req): return req.path_info == '/' + self.href def process_request(self, req): req.perm.require('TRAC_ADMIN') self.data = {} self.args = {} self.req = req self.per_page = int(req.args.get('per-page', self.COMMENTS_PER_PAGE)) self.page = int(req.args.get('page', 1)) self.order_by = req.args.get('orderby', 'id') self.order = req.args.get('order', 'DESC') self.add_path_and_author_filters() self.comments = Comments(req, self.env) self.data['comments'] = self.comments.search(self.args, self.order, self.per_page, self.page, self.order_by) self.data['reponame'], repos, path = RepositoryManager( self.env).get_repository_by_path('/') self.data['can_delete'] = 'TRAC_ADMIN' in req.perm self.data['paginator'] = self.get_paginator() self.data['current_sorting_method'] = self.order_by self.data['current_order'] = self.order self.data['sortable_headers'] = [] self.data.update(self.comments.get_filter_values()) self.prepare_sortable_headers() return 'comments.html', self.data, None def post_process_request(self, req, template, data, content_type): add_stylesheet(req, 'code-comments/sort/sort.css') add_script(req, 'code-comments/code-comments-list.js') return template, data, content_type def add_path_and_author_filters(self): self.data['current_path_selection'] = '' self.data['current_author_selection'] = '' if self.req.args.get('filter-by-path'): self.args['path__prefix'] = self.req.args['filter-by-path'] self.data['current_path_selection'] = self.req.args[ 'filter-by-path'] if self.req.args.get('filter-by-author'): self.args['author'] = self.req.args['filter-by-author'] self.data['current_author_selection'] = self.req.args[ 'filter-by-author'] def get_paginator(self): def href_with_page(page): args = copy.copy(self.req.args) args['page'] = page return self.req.href(self.href, args) paginator = Paginator(self.data['comments'], self.page - 1, self.per_page, Comments(self.req, self.env).count(self.args)) if paginator.has_next_page: add_link(self.req, 'next', href_with_page(self.page + 1), 'Next Page') if paginator.has_previous_page: add_link(self.req, 'prev', href_with_page(self.page - 1), 'Previous Page') shown_pages = paginator.get_shown_pages(page_index_count=11) links = [{ 'href': href_with_page(page), 'class': None, 'string': str(page), 'title': 'Page %d' % page } for page in shown_pages] paginator.shown_pages = links paginator.current_page = { 'href': None, 'class': 'current', 'string': str(paginator.page + 1), 'title': None } return paginator def prepare_sortable_headers(self): displayed_sorting_methods = ('id', 'author', 'time', 'path', 'text') displayed_sorting_method_names = ('ID', 'Author', 'Date', 'Path', 'Text') query_args = self.req.args if (query_args.has_key('page')): del query_args['page'] for sorting_method, sorting_method_name in zip( displayed_sorting_methods, displayed_sorting_method_names): query_args['orderby'] = sorting_method html_class = 'header' if self.order_by == sorting_method: if 'ASC' == self.order: query_args['order'] = 'DESC' html_class += ' headerSortUp' else: query_args['order'] = 'ASC' html_class += ' headerSortDown' link = self.req.href(self.href, query_args) self.data['sortable_headers'].append({ 'name': sorting_method_name, 'link': link, 'html_class': html_class })