-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://cybernetics.hudora.biz/intern/svn/code/trunk/web/lib/hudoratools@1162 2a7d6d32-97f8-0310-8fd3-c67d3a265405
- Loading branch information
md
committed
Aug 22, 2006
0 parents
commit f011fd2
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |