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)
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 )
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 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)
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)
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 )
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 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)
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)
def url(parser, token): return future.url(parser=parser, token=token)
def url(parser, token): return defaulttags.url(parser, token)
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
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)
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)
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)
def absurl(parser, token): return ABSURLNode(url(parser, token))
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)
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)
def fburl(parser, token): return FacebookUrlNode(url(parser, token))