diff --git a/README.txt b/README.txt index b833068..7c4738e 100644 --- a/README.txt +++ b/README.txt @@ -48,13 +48,14 @@ There are really 5 steps to setting it up with your projects. your objects_list: - {% anchor first_name Name %} - {% anchor creation_date Creation %} + {% anchor "first_name" "Name" %} + {% anchor "creation_date" _("Creation") %} ... The first argument is a field of the objects list, and the second - one(optional) is a title that would be displayed. The previous + one(optional) is a title that would be displayed, you can use + django translation syntax _("") for the second argument. The previous snippet will be rendered like this: diff --git a/django_sorting/templatetags/sorting_tags.py b/django_sorting/templatetags/sorting_tags.py index 7cdeb42..acb5cae 100644 --- a/django_sorting/templatetags/sorting_tags.py +++ b/django_sorting/templatetags/sorting_tags.py @@ -19,7 +19,7 @@ def anchor(parser, token): """ Parses a tag that's supposed to be in this format: {% anchor field title %} """ - bits = [b.strip('"\'') for b in token.split_contents()] + bits = token.split_contents() if len(bits) < 2: raise TemplateSyntaxError, "anchor tag takes at least 1 argument" try: @@ -42,10 +42,12 @@ class SortAnchorNode(template.Node): """ def __init__(self, field, title): - self.field = field - self.title = title + self.field = template.Variable(field) + self.title = template.Variable(title) def render(self, context): + field = self.field.resolve(context) + title = self.title.resolve(context) request = context['request'] getvars = request.GET.copy() if 'sort' in getvars: @@ -58,7 +60,7 @@ def render(self, context): del getvars['dir'] else: sortdir = '' - if sortby == self.field: + if sortby == field: getvars['dir'] = sort_directions[sortdir]['inverse'] icon = sort_directions[sortdir]['icon'] else: @@ -68,16 +70,16 @@ def render(self, context): else: urlappend = '' if icon: - title = "%s %s" % (self.title, icon) + title_icon = u"%s %s" % (title, icon) else: - title = self.title + title_icon = title - url = '%s?sort=%s%s' % (request.path, self.field, urlappend) - return '%s' % (url, self.title, title) + url = '%s?sort=%s%s' % (request.path, field, urlappend) + return u'%s' % (url, title, title_icon) def autosort(parser, token): - bits = [b.strip('"\'') for b in token.split_contents()] + bits = token.split_contents() if len(bits) != 2: raise TemplateSyntaxError, "autosort tag takes exactly one argument" return SortedDataNode(bits[1])