from django forms util import ErrorDict from django utils encoding imp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from django.forms.util import ErrorDict
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe
def markup_error(self, label, messages):
self.js_errors.append("""$.jGrowl("%s - %s", { sticky: true });""" % (label, u'<br />'.join(messages)))
def as_js(self):
for k, v in self.items():
messages = []
for i in v:
messages.append(force_unicode(i))
self.markup_error(k, messages)
if self.js_errors:
js = mark_safe("<script>%s</script>" % " ".join(self.js_errors))
else:
js = u""
self.js_errors = []
return js
ErrorDict.__unicode__ = as_js
ErrorDict.markup_error = markup_error
ErrorDict.js_errors = []