Skip to content

Commit

Permalink
hudoratools taglib, eAP aufgeraumt
Browse files Browse the repository at this point in the history
  • Loading branch information
md committed Aug 22, 2006
0 parents commit f011fd2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Empty file added __init__.py
Empty file.
Empty file added templatetags/__init__.py
Empty file.
37 changes: 37 additions & 0 deletions templatetags/hudoratools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from django import template
from django.template import resolve_variable
import re

register = template.Library()

def html_euro(value):
"Formats a value with two decimal digits and andds an Euro sign in HTML entity notation"

try:
value = float(value)
except ValueError:
return value
return "%.2f €" % (value)
register.filter(html_euro)


class FieldAndErrorInfoNode(template.Node):
def __init__(self, field):
self.field = field

def render(self, context):
field = resolve_variable(self.field, context)
ret = str(field)
if not field.errors():
return ret
#return "*** " + (", ".join([str(x) for x in field.errors()]))
return '<div class="error">%s %s</div>' % (ret, field.html_error_list())

def do_field_and_error_info(parser, token):
try:
# split_contents() knows not to split quoted strings.
tag_name, field = token.contents.split()
except ValueError:
raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents[0]
return FieldAndErrorInfoNode(field)
register.tag('field_and_error_info', do_field_and_error_info)

0 comments on commit f011fd2

Please sign in to comment.