Added a cleaning method for a LinkProperty Field.
Patch by: Lennard de Rijk
Reviewed by: to-be-reviewed
--- a/app/soc/logic/cleaning.py Thu Jan 22 00:07:36 2009 +0000
+++ b/app/soc/logic/cleaning.py Thu Jan 22 13:50:25 2009 +0000
@@ -87,3 +87,20 @@
raise forms.ValidationError('This URL is not a valid ATOM or RSS feed.')
return feed_url
+
+def clean_url(field_name):
+ """Clean method for cleaning a field belonging to a LinkProperty.
+ """
+
+ def wrapped(self):
+
+ value = self.cleaned_data.get(field_name)
+
+ # LinkProperty does not accept the empty string so we must return None
+ if not value or value == u'':
+ return None
+
+ # call the Django URLField cleaning method to properly clean/validate this field
+ return forms.URLField.clean(self, value )
+ return wrapped
+