# -*- coding: utf-8 -*- from django.template import Node, Library, TemplateSyntaxError, VariableDoesNotExist from django.core.urlresolvers import reverse, resolve from django.template.defaulttags import URLNode from django.contrib.auth.decorators import user_passes_test register = Library() class LinkAllowedNode(Node): def __init__(self, url, name, permission): self.url = url self.permission = permission self.name = name def render(self, context): request = context['request'] url = self.url.resolve(context) if self.permission and not request.user.has_perm(self.permission.resolve(context)): return '' import re pattern = "^%s$" % url if re.search(pattern, request.path): return '