# HG changeset patch # User Lennard de Rijk # Date 1232632225 0 # Node ID adf5b7e98dcf2592724b3c28d17f6cae21ab1364 # Parent 6ba5bf4b3fea90ff251f02c30f98c9970bcb1587 Added a cleaning method for a LinkProperty Field. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed diff -r 6ba5bf4b3fea -r adf5b7e98dcf 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 +