from django import template
import django.template.base as base

register = template.Library()

@register.tag(name='revisions_link')
def revisions_link(parser, token):
    try:
        # split_contents() knows not to split quoted strings.
        tag_name, revision_type, object_uuid = token.split_contents()
    except ValueError:
        raise template.TemplateSyntaxError("%r tag requires two arguments" % token.contents.split()[0])

    return RevisionLinkNode(revision_type, object_uuid)

class RevisionLinkNode(template.Node):
    def __init__(self, revision_type, object_uuid):
        self.revision_type = self._convert_to_template_variable_if_not_in_quotes(revision_type)
        self.object_uuid   = self._convert_to_template_variable_if_not_in_quotes(object_uuid)

    def render(self, context):
        revision_type = self._resolve_if_template_variable(self.revision_type, context)
        object_uuid   = self._resolve_if_template_variable(self.object_uuid, context)

        return '<a class="revisions_link" href="/fpr/revisions/' + revision_type + '/' + object_uuid + '/">Revision History</a>'

    def _convert_to_template_variable_if_not_in_quotes(self, value):
        if (self._in_quotes(value)):
            return value[1:-1]
        else:
            return template.Variable(value) 

    def _in_quotes(self, value):
        return value[0] == '"' or value[0] == "'"

    def _resolve_if_template_variable(self, value, context):
        if (value.__class__ == base.Variable):
            return value.resolve(context)
        else:
            return value

@@ -57,16 +57,62 @@
 as base%0A
+from django.core.urlresolvers import reverse%0A%0A
 %0Aregiste
@@ -135,16 +135,17 @@
 rary()%0A%0A
+%0A
 @registe
@@ -534,16 +534,17 @@
 _uuid)%0A%0A
+%0A
 class Re
@@ -1075,26 +1075,88 @@
 ef=%22
-/fpr/revisions/' +
+%7B%7D%22%3ERevision history%3C/a%3E'.format(reverse('revision_list', kwargs=%7B'entity_name':
  rev
@@ -1169,16 +1169,17 @@
 type
- + '/' +
+, 'uuid':
  obj
@@ -1190,36 +1190,11 @@
 uuid
- + '/%22%3ERevision History%3C/a%3E'
+%7D))
 %0A%0A  

Use reverse in revisions_link tag