Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Added edit_link template tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
markfinger committed Dec 9, 2011
1 parent 577ba7d commit d7c31b8
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion adminboost/templatetags/adminboost_tags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re

from django.core.urlresolvers import reverse
from django.template import Library, Node, TemplateSyntaxError, loader
from django.conf import settings

Expand Down Expand Up @@ -49,3 +49,27 @@ def sortable_inlines(parser, token):
except IndexError:
raise TemplateSyntaxError("Incorrect syntax for the prefixes passed to {% sortable_inlines %}. Try surrounding prefixes with double quotes")
return SortableInlineNode(bits)

class EditLinkNode(Node):
def render(self, context):
obj = context['object']
static_url = context['STATIC_URL']
url = reverse(
'admin:{0}_{1}_change'.format(
obj._meta.app_label,
obj._meta.verbose_name
),
args=[obj.pk]
)
return '<a href="{0}"><img src="{1}/admin/img/icon_changelink.gif" title="Edit" alt="Edit"/></a>'.format(url, static_url)

@register.tag
def edit_link(parser, token):
"""
Syntax:
{% edit_link obj %}
Renders a clickable image which links to the admin corresponding to :obj.
"""
return EditLinkNode()

0 comments on commit d7c31b8

Please sign in to comment.