def _get_ticket_href(self, prefix, tid): try: env = lookup_product_env(self.env, prefix) except LookupError: return '#invalid-product-' + prefix else: href = resolve_product_href(env, self.env) return href.ticket(tid)
def _render_list(self, req): """products list""" products = [p for p in Product.select(self.env) if 'PRODUCT_VIEW' in req.perm(Neighborhood('product', p.prefix))] map(lambda p: setattr(p, 'href', resolve_product_href( lookup_product_env(self.env, p.prefix), self.env)), products) data = {'products': products, 'context': web_context(req, Resource('product', None))} return 'product_list.html', data, None
def _render_list(self, req): """products list""" products = [ p for p in Product.select(self.env) if 'PRODUCT_VIEW' in req.perm(Neighborhood('product', p.prefix)) ] map( lambda p: setattr( p, 'href', resolve_product_href(lookup_product_env(self.env, p.prefix), self.env)), products) data = { 'products': products, 'context': web_context(req, Resource('product', None)) } return 'product_list.html', data, None
def ticket_anchor(ticket): try: pvalue = ticket.get('product') or GLOBAL_PRODUCT envhref = hrefcache[pvalue] except KeyError: try: env = lookup_product_env(self.env, prefix= pvalue, name=pvalue) except LookupError: return tag.a('#%s' % ticket['id'], class_='missing product') hrefcache[pvalue] = envhref = resolve_product_href( to_env=env, at_env=self.env) return tag.a('#%s' % ticket['id'], class_=ticket['status'], href=envhref.ticket(int(ticket['id'])), title=shorten_line(ticket['summary']))
def _make_sublink(self, env, sublink, formatter, ns, target, label, fullmatch, extra=''): parent_match = {'ns' : ns, 'target' : target, 'label': Markup(escape(unescape(label) if isinstance(label, Markup) else label)), 'fullmatch' : fullmatch, } # Tweak nested context to work in target product/global scope subctx = formatter.context.child() subctx.href = resolve_product_href(to_env=env, at_env=self.env) try: req = formatter.context.req except AttributeError: pass else: # Authenticate in local context but use foreign permissions subctx.perm = self.FakePermClass() \ if isinstance(req.session, FakeSession) \ else PermissionCache(env, req.authname) subctx.req = req subformatter = EmbeddedLinkFormatter(env, subctx, parent_match) subformatter.auto_quote = True ctxtag = '[%s] ' % (env.product.prefix,) \ if isinstance(env, ProductEnvironment) \ else '<global> ' subformatter.enhance_link = lambda link : ( link(title=ctxtag + link.attrib.get('title')) if isinstance(link, Element) and 'title' in link.attrib else link) link = subformatter.match(sublink + extra) if link: return link else: # Return outermost match unchanged like if it was !-escaped for itype, match in fullmatch.groupdict().items(): if match and not itype in formatter.wikiparser.helper_patterns: return escape(match)
def _render_link(self, context, name, label, extra='', prefix=None): """Render link to product page. """ product_env = product = None env = self.env if isinstance(env, ProductEnvironment): if (prefix is not None and env.product.prefix == prefix) \ or (prefix is None and env.name == name): product_env = env env = env.parent try: if product_env is None: if prefix is not None: product_env = ProductEnvironment(env, to_unicode(prefix)) else: product = Product.select(env, where={'name' : to_unicode(name)}) if not product: raise LookupError("Missing product") product_env = ProductEnvironment(env, to_unicode(product[0])) except LookupError: pass if product_env is not None: product = product_env.product href = resolve_product_href(to_env=product_env, at_env=self.env) if 'PRODUCT_VIEW' in context.perm(product.resource): return tag.a(label, class_='product', href=href() + extra, title=product.name) if 'PRODUCT_CREATE' in context.perm('product', name): params = [('action', 'new')] if prefix: params.append( ('prefix', prefix) ) if name: params.append( ('name', name) ) return tag.a(label, class_='missing product', href=env.href('products', params), rel='nofollow') return tag.a(label, class_='missing product')
def _get_ticket_href(self, prefix, tid): env = lookup_product_env(self.env, prefix) href = resolve_product_href(env, self.env) return href.ticket(tid)