--- a/app/soc/logic/cleaning.py Sat Mar 07 18:16:54 2009 +0000
+++ b/app/soc/logic/cleaning.py Sat Mar 07 19:17:02 2009 +0000
@@ -277,6 +277,26 @@
return wrapped
+def clean_ascii_only(field_name):
+ """Clean method for cleaning a field that may only contain ASCII-characters.
+ """
+ @check_field_is_empty(field_name)
+ def wrapper(self):
+ """Decorator wrapper method.
+ """
+ value = self.cleaned_data.get(field_name)
+
+ try:
+ # encode to ASCII
+ value = value.encode("ascii")
+ except UnicodeEncodeError:
+ # can not encode as ASCII
+ raise forms.ValidationError("Only ASCII characters are allowed")
+
+ return value
+ return wrapper
+
+
def clean_feed_url(self):
"""Clean method for cleaning feed url.
"""
@@ -316,6 +336,7 @@
return wrapped
+
def clean_url(field_name):
"""Clean method for cleaning a field belonging to a LinkProperty.
"""