Created
February 22, 2011 11:17
-
-
Save peterbe/838529 to your computer and use it in GitHub Desktop.
Use these instead of django.forms.Form or django.forms.ModelForm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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