Exemplo n.º 1
0
def absurl(parser, token):
    """Just like {% url 'urlname' %} but ads the domain of the current site."""
    node_instance = url(parser, token)
    return AbsoluteURLNode(view_name=node_instance.view_name,
                           args=node_instance.args,
                           kwargs=node_instance.kwargs,
                           asvar=node_instance.asvar,
                           legacy_view_name=node_instance.legacy_view_name)
def new_style_url(parser, token):
    bits = token.split_contents()
    view = bits[1]

    if view[0] not in "\"'" or view[0] != view[-1]:
        _error("New style url tag without quotes around view name: {%% %s %%}" % (" ".join(bits)), token)

    return future.url(parser, token)
Exemplo n.º 3
0
def absolute_url(parser, token, node_cls=AbsoluteURLNode):
    """Just like {% url %} but adds the domain of the current site."""
    node_instance = url(parser, token)
    return node_cls(
        view_name=node_instance.view_name,
        args=node_instance.args,
        kwargs=node_instance.kwargs,
        asvar=node_instance.asvar
    )
Exemplo n.º 4
0
def absurl(parser, token):
    """Just like {% url 'urlname' %} but ads the domain of the current site."""
    node_instance = url(parser, token)
    return AbsoluteURLNode(
        view_name=node_instance.view_name,
        args=node_instance.args,
        kwargs=node_instance.kwargs,
        asvar=node_instance.asvar,
        legacy_view_name=node_instance.legacy_view_name,
    )
Exemplo n.º 5
0
def clink_tag(parser, token):
    bits = token.split_contents()
    if len(bits) < 2:
        raise TemplateSyntaxError("'%s' takes at least one argument"
                                  " (path to a view)" % bits[0])
    tp = parser.compile_filter(bits[1])
    p = re.compile("^'")
    if p.match(bits[1]):
        u = url(parser, token)
        return Link(u)
    else:
        return ObjectLink(tp)
Exemplo n.º 6
0
    def site(parser, token):
        '''
        Returns a full absolute URL based on the current site.

        This template tag takes exactly the same paramters as url template tag.
        '''
        node = url(parser, token)
        view_name = str(node.view_name).strip('"\'')
        return SiteUrlNode(view_name=view_name,
                           args=node.args,
                           kwargs=node.kwargs,
                           asvar=node.asvar)
Exemplo n.º 7
0
def clink_tag(parser, token):
    bits = token.split_contents()
    if len(bits) < 2:
        raise TemplateSyntaxError("'%s' takes at least one argument"
                                  " (path to a view)" % bits[0])
    tp = parser.compile_filter(bits[1])
    p = re.compile("^'")
    if p.match(bits[1]):
        u = url(parser, token)
        return Link(u)
    else:
        return ObjectLink(tp)
Exemplo n.º 8
0
    def site(parser, token):
        '''
        Returns a full absolute URL based on the current site.

        This template tag takes exactly the same paramters as url template tag.
        '''
        node = url(parser, token)
        view_name = str(node.view_name).strip('"\'')
        return SiteUrlNode(
            view_name=view_name,
            args=node.args,
            kwargs=node.kwargs,
            asvar=node.asvar
        )
Exemplo n.º 9
0
def blogurl(parser, token):
    """
    Compatibility tag to allow django-fluent-blogs to operate stand-alone.
    Either the app can be hooked in the URLconf directly, or it can be added as a pagetype of django-fluent-pages.
    For the former, URL resolving works via the normal '{% url "viewname" arg1 arg2 %}' syntax.
    For the latter, the URL resolving works via '{% appurl "viewname" arg1 arg2 %}' syntax.
    """
    if HAS_APP_URLS:
        from fluent_pages.templatetags.appurl_tags import appurl
        return appurl(parser, token)
    else:
        # Using url from future, so the syntax is the same modern style.
        from django.templatetags.future import url
        return url(parser, token)
def blogurl(parser, token):
    """
    Compatibility tag to allow django-fluent-blogs to operate stand-alone.
    Either the app can be hooked in the URLconf directly, or it can be added as a pagetype of django-fluent-pages.
    For the former, URL resolving works via the normal '{% url "viewname" arg1 arg2 %}' syntax.
    For the latter, the URL resolving works via '{% appurl "viewname" arg1 arg2 %}' syntax.
    """
    if HAS_APP_URLS:
        from fluent_pages.templatetags.appurl_tags import appurl
        return appurl(parser, token)
    else:
        # Using url from future, so the syntax is the same modern style.
        from django.templatetags.future import url
        return url(parser, token)
Exemplo n.º 11
0
def locale_url(parser, token):
    """
    Renders the url for the view with another locale prefix. The syntax is
    like the 'url' tag, only with a locale before the view.

    Examples:
      {% locale_url "de" cal.views.day day %}
      {% locale_url "nl" cal.views.home %}
      {% locale_url "en-gb" cal.views.month month as month_url %}
    """
    bits = token.split_contents()
    if len(bits) < 3:
        raise TemplateSyntaxError("'%s' takes at least two arguments:"
                                  " the locale and a view" % bits[0])
    urltoken = Token(token.token_type, bits[0] + ' ' + ' '.join(bits[2:]))
    urlnode = future.url(parser, urltoken)
    return LocaleURLNode(bits[1], urlnode)
Exemplo n.º 12
0
def locale_url(parser, token):
    """
    Renders the url for the view with another locale prefix. The syntax is
    like the 'url' tag, only with a locale before the view.

    Examples:
      {% locale_url "de" cal.views.day day %}
      {% locale_url "nl" cal.views.home %}
      {% locale_url "en-gb" cal.views.month month as month_url %}
    """
    bits = token.split_contents()
    if len(bits) < 3:
        raise TemplateSyntaxError("'%s' takes at least two arguments:"
                " the locale and a view" % bits[0])
    urltoken = Token(token.token_type, bits[0] + ' ' + ' '.join(bits[2:]))
    urlnode = future.url(parser, urltoken)
    return LocaleURLNode(bits[1], urlnode)
Exemplo n.º 13
0
def breadcrumb_url(parser, token):
    """
    Same as breadcrumb
    but instead of url context variable takes in all the
    arguments URL tag takes.
        {% breadcrumb "Title of breadcrumb" person_detail person.id %}
        {% breadcrumb person.name person_detail person.id %}
    """

    bits = token.split_contents()
    if len(bits) == 2:
        return breadcrumb(parser, token)

    # Extract our extra title parameter
    title = bits.pop(1)
    token.contents = ' '.join(bits)

    url_node = url(parser, token)

    return UrlBreadcrumbNode(title, url_node)
Exemplo n.º 14
0
 def url(parser, token):
     return future.url(parser=parser, token=token)
Exemplo n.º 15
0
def url(parser, token):
    return defaulttags.url(parser, token)
Exemplo n.º 16
0
def fqdn_url(parser, token):
    # NB change with defaulttags.url for Django 1.5 and later
    retval = future.url(parser, token)
    retval.__class__ = FQDN_URLNode

    return retval
Exemplo n.º 17
0
def ifstartswith(parser, token):
    urlnode = url(parser, token)
    var, nodelist_true, nodelist_false = parse(parser, token,
                                               'endifstartswith')
    return ActiveLinkStartsWithNode(urlnode, var, nodelist_true,
                                    nodelist_false)
Exemplo n.º 18
0
def ifactive(parser, token):
    urlnode = url(parser, token)
    var, nodelist_true, nodelist_false = parse(parser, token, 'endifactive')
    return ActiveLinkEqualNode(urlnode, var, nodelist_true, nodelist_false)
Exemplo n.º 19
0
def ifcontains(parser, token):
    urlnode = url(parser, token)
    var, nodelist_true, nodelist_false = parse(parser, token, 'endifcontains')
    return ActiveLinkContainsNode(urlnode, var, nodelist_true, nodelist_false)
Exemplo n.º 20
0
def absurl(parser, token):
    return  ABSURLNode(url(parser, token))
Exemplo n.º 21
0
def ifcontains(parser, token):
    urlnode = url(parser, token)
    var, nodelist_true, nodelist_false = parse(parser, token, 'endifcontains')
    return ActiveLinkContainsNode(urlnode, var, nodelist_true, nodelist_false)
Exemplo n.º 22
0
def absurl(parser, token):
    return ABSURLNode(url(parser, token))
Exemplo n.º 23
0
def ifnotendswith(parser, token):
    urlnode = url(parser, token)
    var_list, nodelist_true, nodelist_false = parse(parser, token,
                                                    'endifnotendswith')
    return ActiveLinkNotEndsWithNode(urlnode, var_list, nodelist_true,
                                     nodelist_false)
Exemplo n.º 24
0
def ifstartswith(parser, token):
    urlnode = url(parser, token)
    var, nodelist_true, nodelist_false = activelink.parse(parser, token,
                                                          'endifstartswith')
    return ActiveLinkStartsWithNode(urlnode, var, nodelist_true,
                                    nodelist_false)
Exemplo n.º 25
0
def fburl(parser, token):
    return FacebookUrlNode(url(parser, token))
Exemplo n.º 26
0
def ifactive(parser, token):
    urlnode = url(parser, token)
    var, nodelist_true, nodelist_false = parse(parser, token, 'endifactive')
    return ActiveLinkEqualNode(urlnode, var, nodelist_true, nodelist_false)