code: def clean(self):
          
          cleaned_data = super(CleanWhiteSpacesMixin, self).clean()
          for k in self.cleaned_data:
              if isinstance(self.cleaned_data[k], six.string_types):
                  cleaned_data[k] = re.sub(extra_spaces_pattern, ' ',
                                           self.cleaned_data[k] or '').strip()
          return cleaned_data
docs: >>> import django.forms
          >>> class MyForm(CleanWhiteSpacesMixin, django.forms.Form):
          ...     some_field = django.forms.CharField()
          >>>
          >>> form = MyForm({'some_field': ' a   weird value  '})
          >>> assert form.is_valid()
          >>> assert form.cleaned_data == {'some_field': 'a weird value'}