def _prepare_results(self, result_docs, hits): ui_docs = [self._process_doc(doc) for doc in result_docs] results = Paginator( ui_docs, self.page - 1, self.pagelen, hits) self._prepare_shown_pages(results) results.current_page = {'href': None, 'class': 'current', 'string': str(results.page + 1), 'title': None} parameters = self.parameters if results.has_next_page: next_href = parameters.create_href(page=parameters.page + 1) add_link(self.req, 'next', next_href, _('Next Page')) if results.has_previous_page: prev_href = parameters.create_href(page=parameters.page - 1) add_link(self.req, 'prev', prev_href, _('Previous Page')) self.data[self.DATA_RESULTS] = results prevnext_nav(self.req, _('Previous'), _('Next'))
def _check_quickjump(self, req, kwd): """Look for search shortcuts""" # pylint: disable=maybe-no-member noquickjump = int(req.args.get('noquickjump', '0')) # Source quickjump FIXME: delegate to ISearchSource.search_quickjump quickjump_href = None if kwd[0] == '/': quickjump_href = req.href.browser(kwd) name = kwd description = _('Browse repository path %(path)s', path=kwd) else: context = web_context(req, 'search') link = find_element(extract_link(self.env, context, kwd), 'href') if link is not None: quickjump_href = link.attrib.get('href') name = link.children description = link.attrib.get('title', '') if quickjump_href: # Only automatically redirect to local quickjump links base_path = req.base_path.replace('@', '%40') redirect_href = quickjump_href.replace('@', '%40') if not redirect_href.startswith(base_path or '/'): noquickjump = True if noquickjump: return { 'href': quickjump_href, 'name': tag.EM(name), 'description': description } else: req.redirect(quickjump_href)
def _check_quickjump(self, req, kwd): """Look for search shortcuts""" # pylint: disable=maybe-no-member noquickjump = int(req.args.get('noquickjump', '0')) # Source quickjump FIXME: delegate to ISearchSource.search_quickjump quickjump_href = None if kwd[0] == '/': quickjump_href = req.href.browser(kwd) name = kwd description = _('Browse repository path %(path)s', path=kwd) else: context = web_context(req, 'search') link = find_element(extract_link(self.env, context, kwd), 'href') if link is not None: quickjump_href = link.attrib.get('href') name = link.children description = link.attrib.get('title', '') if quickjump_href: # Only automatically redirect to local quickjump links base_path = req.base_path.replace('@', '%40') redirect_href = quickjump_href.replace('@', '%40') if not redirect_href.startswith(base_path or '/'): noquickjump = True if noquickjump: return {'href': quickjump_href, 'name': tag.EM(name), 'description': description} else: req.redirect(quickjump_href)
def _add_views_selector(self): active_view = self.parameters.view all_views = [] for view, label in self.VIEWS_SUPPORTED: all_views.append( dict(label=_(label), href=self.parameters.create_href( view=view, skip_view=(view is None)), is_active=(view == active_view))) self.data[self.DATA_ALL_VIEWS] = all_views
def _prepare_product_breadcrumb(self): if not using_multiproduct(self.env): return product_search = lambda x: self.parameters.create_href(product=x) all_products_search = self.parameters.create_href(skip_product=True) global_product = [(u'', _(u'Global product'), product_search(u''))] products = \ ProductModule.get_product_list(self.env, self.req, product_search) all_products = [(None, _(u'All products'), all_products_search)] search_product_list = global_product + products + all_products # pylint: disable=unused-variable for prefix, name, url in search_product_list: if prefix == self.active_product: self.data[self.DATA_ACTIVE_PRODUCT] = name break else: self.data[self.DATA_ACTIVE_PRODUCT] = self.active_product self.data[self.DATA_PRODUCT_LIST] = search_product_list
def _add_views_selector(self): active_view = self.parameters.view all_views = [] for view, label in self.VIEWS_SUPPORTED: all_views.append(dict( label=_(label), href=self.parameters.create_href( view=view, skip_view=(view is None)), is_active=(view == active_view) )) self.data[self.DATA_ALL_VIEWS] = all_views
def _prepare_result_facet_counts(self, result_facets): """ Sample query_result.facets content returned by query { 'component': {None:2}, 'milestone': {None:1, 'm1':1}, } returned facet_count contains href parameters: { 'component': {None: {'count':2, href:'...'}, 'milestone': { None: {'count':1,, href:'...'}, 'm1':{'count':1, href:'...'} }, } """ facet_counts = [] if result_facets: for field in self.facets: if field == IndexFields.PRODUCT and \ not using_multiproduct(self.env): continue facets_dict = result_facets.get(field, {}) per_field_dict = dict() for field_value, count in facets_dict.iteritems(): if field == IndexFields.TYPE: href = self.parameters.create_href( skip_page=True, force_filters=[], type=field_value) elif field == IndexFields.PRODUCT: href = self.parameters.create_href( skip_page=True, product=field_value or u'', ) else: href = self.parameters.create_href( skip_page=True, additional_filter=self._create_term_expression( field, field_value) ) per_field_dict[field_value] = dict( count=count, href=href ) facet_counts.append((_(field), per_field_dict)) self.data[self.DATA_FACET_COUNTS] = facet_counts
def _prepare_results(self, result_docs, hits): ui_docs = [self._process_doc(doc) for doc in result_docs] results = Paginator(ui_docs, self.page - 1, self.pagelen, hits) self._prepare_shown_pages(results) results.current_page = { 'href': None, 'class': 'current', 'string': str(results.page + 1), 'title': None } parameters = self.parameters if results.has_next_page: next_href = parameters.create_href(page=parameters.page + 1) add_link(self.req, 'next', next_href, _('Next Page')) if results.has_previous_page: prev_href = parameters.create_href(page=parameters.page - 1) add_link(self.req, 'prev', prev_href, _('Previous Page')) self.data[self.DATA_RESULTS] = results prevnext_nav(self.req, _('Previous'), _('Next'))
def _prepare_result_facet_counts(self, result_facets): """ Sample query_result.facets content returned by query { 'component': {None:2}, 'milestone': {None:1, 'm1':1}, } returned facet_count contains href parameters: { 'component': {None: {'count':2, href:'...'}, 'milestone': { None: {'count':1,, href:'...'}, 'm1':{'count':1, href:'...'} }, } """ facet_counts = [] if result_facets: for field in self.facets: if field == IndexFields.PRODUCT and \ not using_multiproduct(self.env): continue facets_dict = result_facets.get(field, {}) per_field_dict = dict() for field_value, count in facets_dict.iteritems(): if field == IndexFields.TYPE: href = self.parameters.create_href(skip_page=True, force_filters=[], type=field_value) elif field == IndexFields.PRODUCT: href = self.parameters.create_href( skip_page=True, product=field_value or u'', ) else: href = self.parameters.create_href( skip_page=True, additional_filter=self._create_term_expression( field, field_value)) per_field_dict[field_value] = dict(count=count, href=href) facet_counts.append((_(field), per_field_dict)) self.data[self.DATA_FACET_COUNTS] = facet_counts
def _prepare_active_type(self): active_type = self.parameters.type if active_type and active_type not in self.allowed_participants: raise TracError( _("Unsupported resource type: '%(name)s'", name=active_type))
def _prepare_active_type(self): active_type = self.parameters.type if active_type and active_type not in self.allowed_participants: raise TracError(_("Unsupported resource type: '%(name)s'", name=active_type))