Added a cleaning method for a LinkProperty Field.
authorLennard de Rijk <ljvderijk@gmail.com>
Thu, 22 Jan 2009 13:50:25 +0000
changeset 898 adf5b7e98dcf
parent 897 6ba5bf4b3fea
child 899 91a43d0aa29a
Added a cleaning method for a LinkProperty Field. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/logic/cleaning.py
--- 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
+