示例#1
0
文件: test_url.py 项目: alkadis/vcv
 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)
示例#3
0
文件: tag_helper.py 项目: alkadis/vcv
 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)
示例#4
0
 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)
示例#5
0
def url(instance, member=None, format=None, **kwargs):
    return _url.build(instance,
                      'instance',
                      instance.key,
                      member=member,
                      format=format,
                      **kwargs)
示例#6
0
    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)
示例#7
0
 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)
示例#8
0
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)})
示例#9
0
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)})
示例#10
0
 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')
示例#11
0
 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')
示例#12
0
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)
示例#13
0
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)
示例#14
0
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)
示例#15
0
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)
示例#16
0
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)
示例#17
0
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)
示例#18
0
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)
示例#19
0
 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')
示例#20
0
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)
示例#21
0
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)
示例#22
0
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
示例#23
0
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)
示例#24
0
文件: __init__.py 项目: alkadis/vcv
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})
示例#25
0
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
示例#26
0
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})
示例#27
0
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)
示例#28
0
def for_url(url):
    instance = c.instance if c.instance else None
    return _url.build(instance, 'abuse', 'new', query={'url': url})
示例#29
0
def for_url(url):
    instance = c.instance if c.instance else None
    return _url.build(instance, "abuse", "new", query={"url": url})
示例#30
0
def url(proposal, **kwargs):
    ext = str(proposal.id) + '-' + label2url(proposal.title)
    return _url.build(proposal.instance, 'proposal', ext, **kwargs)
示例#31
0
def url(milestone, **kwargs):
    return _url.build(milestone.instance, 'milestone', milestone.id, **kwargs)
示例#32
0
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)
示例#34
0
文件: test_url.py 项目: alkadis/vcv
 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')
示例#35
0
def url(category, member=None, **kwargs):
    return _url.build(category.instance, 'category', category.id,
                      member=member, **kwargs)
示例#36
0
文件: test_url.py 项目: alkadis/vcv
 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')
示例#37
0
文件: test_url.py 项目: alkadis/vcv
 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')
示例#38
0
文件: test_url.py 项目: alkadis/vcv
 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')
示例#39
0
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)})
示例#40
0
def url(category, member=None, **kwargs):
    return _url.build(category.instance, 'category', category.id,
                      member=member, **kwargs)
示例#41
0
def url(proposal, **kwargs):
    ext = str(proposal.id) + '-' + label2url(proposal.title)
    return _url.build(proposal.instance, 'proposal', ext, **kwargs)
示例#42
0
def url(entity, **kwargs):
    return _url.build(None, 'admin/treatment', entity.key, **kwargs)
示例#43
0
def url(poll, **kwargs):
    return _url.build(poll.scope.instance, 'poll', poll.id, **kwargs)
示例#44
0
def url(entity, **kwargs):
    return _url.build(entity.instance, 'message', entity.id, **kwargs)
示例#45
0
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)
示例#46
0
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)
示例#47
0
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)
示例#48
0
def for_url(url):
    instance = c.instance if c.instance else None
    return _url.build(instance, 'abuse', 'new', query={'url': url})
示例#49
0
 def url_(user, instance, **kwargs):
     return _url.build(instance, 'user', user.user_name, **kwargs)
示例#50
0
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)
示例#51
0
def url(instance, member=None, format=None, **kwargs):
    return _url.build(instance, 'instance', instance.key,
                      member=member, format=format, **kwargs)
示例#52
0
 def url_(user, instance, **kwargs):
     return _url.build(instance, 'user', user.user_name, **kwargs)
示例#53
0
def url(staticpage, **kwargs):
    pid = staticpage.key
    return _url.build(None, 'static', pid, **kwargs)
示例#54
0
def url(poll, **kwargs):
    return _url.build(poll.scope.instance, 'poll', poll.id, **kwargs)
示例#55
0
def url(delegation, **kwargs):
    return _url.build(delegation.scope.instance, 'delegation', delegation.id,
                      **kwargs)
示例#56
0
 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')
示例#57
0
def url(milestone, **kwargs):
    return _url.build(milestone.instance, 'milestone', milestone.id, **kwargs)
示例#58
0
 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')