Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@peterbe
Created February 22, 2011 11:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterbe/838529 to your computer and use it in GitHub Desktop.
Save peterbe/838529 to your computer and use it in GitHub Desktop.
Use these instead of django.forms.Form or django.forms.ModelForm
class _BaseForm(object):
def clean(self):
cleaned_data = super(_BaseForm, self).clean()
for field in cleaned_data:
if isinstance(cleaned_data[field], basestring):
cleaned_data[field] = \
cleaned_data[field].replace('\r\n','\n')\
.replace(u'\u2018',"'").replace(u'\u2019',"'").strip()
return cleaned_data
class BaseForm(_BaseForm, forms.Form):
pass
class BaseModelForm(_BaseForm, forms.ModelForm):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment