def test_build_global_omit_base(self): from adhocracy.lib.helpers.url import build url = build(None, None, 'id', query={'param': u'arg'}, anchor='anchor', member='member', format="html") self.assertEqual(url, u'http://test.lan/id/member.html?param=arg#anchor') url = build(None, '', 'id', query={'param': u'arg'}, anchor='anchor', member='member', format="html") self.assertEqual(url, u'http://test.lan/id/member.html?param=arg#anchor')
def url(comment, member=None, format=None, comment_page=False, in_overlay=True, **kwargs): if member is None and format is None and not comment_page: if isinstance(comment.topic, model.Page): if comment.topic.function == model.Page.DESCRIPTION: return (proposal.url(comment.topic.proposal, anchor=u'c%i' % comment.id, **kwargs)) if comment.topic.is_sectionpage(): if not u'anchor' in kwargs: kwargs[u'anchor'] = u'c%i' % comment.id if in_overlay: kwargs[u'format'] = u'overlay' query = { u'overlay_path': page.url(comment.topic, member=u'comments', **kwargs), u'overlay_type': u'#overlay-url', } return page.url(comment.topic.sectionpage_root(), query=query) else: return page.url(comment.topic, member=u'comments', **kwargs), return (text.url(comment.topic.variant_head(comment.variant), anchor=u'c%i' % comment.id, **kwargs)) elif isinstance(comment.topic, model.Proposal): return (proposal.url(comment.topic, anchor=u'c%i' % comment.id, **kwargs)) return _url.build(comment.topic.instance, 'comment', comment.id, member=member, format=format, **kwargs)
def url_(tag, instance, **kwargs): ident = None try: ident = _url.quote(tag.name) except KeyError: ident = tag.id return _url.build(instance, u'tag', ident, **kwargs)
def url_(tag, instance, **kwargs): ident = None try: ident = urllib.quote(tag.name.encode('utf-8')) except KeyError: ident = tag.id return _url.build(instance, u'tag', ident, **kwargs)
def url(instance, member=None, format=None, **kwargs): return _url.build(instance, 'instance', instance.key, member=member, format=format, **kwargs)
def render_navigation_item(item, path='', toplevel=False): from adhocracy.lib.templating import render_def if path != '': path = '%s/%s' % (path, item['name']) else: path = item['name'] url = _url.build(instance, 'static', path, format='html') contains_current = (path == current_key) if item['children']: children, contained_list = izip( *map(lambda child: render_navigation_item(child, path), item['children'])) contains_current = contains_current or any(contained_list) else: children = [] html = render_def('static/tiles.html', 'navigation_item', href=url, title=item['title'], current=toplevel and contains_current, children=children) return (html, contains_current)
def icon_url(instance, y, x=None): if x is None: size = "%s" % y else: size = "%sx%s" % (x, y) filename = "%s_%s.png" % (instance.key, size) (path, mtime) = logo.path_and_mtime(instance.key) return _url.build(instance, 'instance', filename, query={'t': str(mtime)})
def test_build_global_omit_anchor_member_and_format(self): from adhocracy.lib.helpers.url import build url = build(None, 'base', 'id', query={'param': u'arg'}, anchor='anchor') self.assertEqual(url, u'http://test.lan/base/id?param=arg#anchor')
def test_build_global_omit_query(self): from adhocracy.lib.helpers.url import build url = build(None, 'base', 'id', anchor='anchor', member='member', format="html") self.assertEqual(url, u'http://test.lan/base/id/member.html#anchor')
def url(page, in_context=True, member=None, **kwargs): if in_context and page.proposal and not member: return proposal.url(page.proposal, **kwargs) if in_context and page.is_sectionpage() and page.parent and member is None: if u'anchor' not in kwargs: kwargs[u'anchor'] = u'subpage-%i' % page.id return url(page.root, in_context=False, **kwargs) label = urllib.quote(page.label.encode('utf-8')) return _url.build(page.instance, 'page', label, member=member, **kwargs)
def url(proposal, member=None, in_overlay=True, **kwargs): if proposal.is_amendment and member is None: base = u'page/%s/amendment' % proposal.selection.page.label if in_overlay: from adhocracy.lib.helpers import page_helper as page kwargs[u'format'] = u'overlay' query = { u'overlay_path': _url.build(proposal.instance, base, proposal.id, **kwargs), u'overlay_type': u'#overlay-url-big', } return page.url(proposal.selection.page, query=query) else: return _url.build(proposal.instance, base, proposal.id, **kwargs) else: ext = str(proposal.id) + '-' + label2url(proposal.title) return _url.build(proposal.instance, 'proposal', ext, member=member, **kwargs)
def url(user, instance=CURRENT_INSTANCE, **kwargs): ''' Generate the url for a user. If *instance* is `None`, it will fallback to the current instance (taken from c.instance) for urls that are supposed to be in an instance subdomain, and ignore the instance argument for all other urls so they are always in the main domain. ''' return _url.build(instance, 'user', user.user_name, **kwargs)
def url(page, in_context=True, member=None, **kwargs): if in_context and page.proposal and not member: return proposal.url(page.proposal, **kwargs) if (in_context and member is None and page.is_sectionpage() and page.sectionpage_root() != page): if u'anchor' not in kwargs: kwargs[u'anchor'] = u'subpage-%i' % page.id return url(page.sectionpage_root(), in_context=False, **kwargs) label = _url.quote(page.label) return _url.build(page.instance, 'page', label, member=member, **kwargs)
def page_variant_url(page, variant): ''' TODO: Hacked together to implement new page views. Refactor url functions. ''' label = _url.quote(page.label) if variant == model.Text.HEAD: variant = None else: variant = _url.quote(variant) return _url.build(page.instance, 'page', label, member=variant)
def page_variant_url(page, variant): ''' TODO: Hacked together to implement new page views. Refactor url functions. ''' label = urllib.quote(page.label.encode('utf-8')) if variant == model.Text.HEAD: variant = None else: variant = urllib.quote(variant.encode('utf-8')) return _url.build(page.instance, 'page', label, member=variant)
def url(comment, member=None, format=None, comment_page=False, **kwargs): if member is None and format is None and not comment_page: if isinstance(comment.topic, model.Page): if comment.topic.function == model.Page.DESCRIPTION: return (proposal.url(comment.topic.proposal) + '#c' + str(comment.id)) return (text.url(comment.topic.variant_head(comment.variant)) + '#c' + str(comment.id)) elif isinstance(comment.topic, model.Proposal): return proposal.url(comment.topic) + '#c' + str(comment.id) return _url.build(comment.topic.instance, 'comment', comment.id, member=member, format=format, **kwargs)
def register_redirect_url(entity=None, **kwargs): ''' Builds an ".../login?came_from=http...." pointing to the /login form in the current instance domain. If ``entity`` is set, this will redirect to the given entity after successful login. If ``entity`` is None, it will redirect to the current URL. ''' if entity is None: came_from_url = request.path_url else: came_from_url = entity_url(entity, **kwargs) login_url = build(c.instance, '', 'register', query={'came_from': came_from_url}) return login_url
def get_redirect_url(target=u'login', entity=None, **kwargs): ''' Builds an URL similar to ".../login?came_from=http...." pointing to the target path in the current instance domain. If we already have a ``came_from`` parameter in the path, this is going to be used as the new ``came_from`` target. Otherwise, if ``entity`` is set, this will redirect to the given entity after successful login. If ``entity`` is None, it will redirect to the current URL. ''' if c.came_from == u'': if entity is None: c.came_from = base_url(request.path, query_string=request.query_string) else: c.came_from = entity_url(entity, **kwargs) return build(c.instance, '', target, query={'came_from': c.came_from})
def url(comment, member=None, format=None, comment_page=False, in_overlay=True, **kwargs): if member is None and format is None and not comment_page: if isinstance(comment.topic, model.Page): if comment.topic.function == model.Page.DESCRIPTION: return (proposal.url(comment.topic.proposal, anchor=u'c%i' % comment.id, **kwargs)) if comment.topic.is_sectionpage(): if u'anchor' not in kwargs: kwargs[u'anchor'] = u'c%i' % comment.id if in_overlay: kwargs[u'format'] = u'overlay' query = { u'overlay_path': page.url(comment.topic, member=u'comments', **kwargs), u'overlay_type': u'#overlay-url', } return page.url(comment.topic.sectionpage_root(), query=query) else: return page.url(comment.topic, member=u'comments', **kwargs), return (text.url(comment.topic.variant_head(comment.variant), anchor=u'c%i' % comment.id, **kwargs)) elif isinstance(comment.topic, model.Proposal): return (proposal.url(comment.topic, anchor=u'c%i' % comment.id, **kwargs)) return _url.build(comment.topic.instance, 'comment', comment.id, member=member, format=format, **kwargs)
def for_url(url): instance = c.instance if c.instance else None return _url.build(instance, 'abuse', 'new', query={'url': url})
def for_url(url): instance = c.instance if c.instance else None return _url.build(instance, "abuse", "new", query={"url": url})
def url(proposal, **kwargs): ext = str(proposal.id) + '-' + label2url(proposal.title) return _url.build(proposal.instance, 'proposal', ext, **kwargs)
def url(milestone, **kwargs): return _url.build(milestone.instance, 'milestone', milestone.id, **kwargs)
def page_text_url(page, text, member=None): label = '%s;%d' % (urllib.quote(page.label.encode('utf-8')), text.id) return _url.build(page.instance, 'page', label, member=member)
def url(delegation, **kwargs): return _url.build(delegation.scope.instance, 'delegation', delegation.id, **kwargs)
def test_build_global_omit_all_except_id(self): from adhocracy.lib.helpers.url import build url = build(None, None, 'id') self.assertEqual(url, u'http://test.lan/id')
def url(category, member=None, **kwargs): return _url.build(category.instance, 'category', category.id, member=member, **kwargs)
def test_build_query_is_encoded(self): from adhocracy.lib.helpers.url import build url = build(None, 'base', 'id', query={'param': u'http://a@b:x'}) self.assertEqual( url, u'http://test.lan/base/id?param=http%3A%2F%2Fa%40b%3Ax')
def logo_url(instance, y, x=None): size = "%s" % y if x is None else "%sx%s" % (x, y) filename = "%s_%s.png" % (instance.key, size) (path, mtime) = logo.path_and_mtime(instance, fallback=logo.INSTANCE) return _url.build(instance, 'instance', filename, query={'t': str(mtime)})
def url(entity, **kwargs): return _url.build(None, 'admin/treatment', entity.key, **kwargs)
def url(poll, **kwargs): return _url.build(poll.scope.instance, 'poll', poll.id, **kwargs)
def url(entity, **kwargs): return _url.build(entity.instance, 'message', entity.id, **kwargs)
def url(page, in_context=True, member=None, **kwargs): if in_context and page.proposal and not member: return proposal.url(page.proposal, **kwargs) label = urllib.quote(page.label.encode('utf-8')) return _url.build(page.instance, 'page', label, member=member, **kwargs)
def page_text_url(page, text, member=None): label = '%s;%d' % (_url.quote(page.label), text.id) return _url.build(page.instance, 'page', label, member=member)
def url_(user, instance, **kwargs): return _url.build(instance, 'user', user.user_name, **kwargs)
def url(staticpage, **kwargs): pid = staticpage.key return _url.build(None, 'static', pid, **kwargs)