coding utf-8 from django forms util import ErrorDict ErrorList from dj

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# -*- coding: utf-8 -*-
from django.forms.util import ErrorDict, ErrorList
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("<br />%s", { header: '%s', sticky: true });""" % (u'<br />'.join(messages), label))
def as_js(self):
self.js_errors = []
for k, v in self.items():
messages = []
for i in v:
messages.append(force_unicode(i))
self.markup_error(k, messages)
if not self.js_errors:
return u""
return mark_safe("<script>%s</script>" % " ".join(self.js_errors))
ErrorDict.__unicode__ = as_js
ErrorDict.markup_error = markup_error