from django import forms


class BugReportForm(forms.Form):

    bug = forms.CharField(label="Bug (required)", required=True)
    description = forms.CharField(
        label="Description (required)",
        widget=forms.Textarea(attrs={'rows': 4, 'cols': 50}), required=True)
    reproduce = forms.CharField(
        label="How to reproduce the error",
        widget=forms.Textarea(attrs={'rows': 4, 'cols': 50}), required=False)
    expected = forms.CharField(
        label="The expected result",
        widget=forms.Textarea(attrs={'rows': 4, 'cols': 50}), required=False)
    actual = forms.CharField(
        label="The actual result",
        widget=forms.Textarea(attrs={'rows': 4, 'cols': 50}), required=False)
    session_data = forms.CharField(widget=forms.HiddenInput())


class EditUserForm(forms.Form):
    user = forms.CharField(
        widget=forms.TextInput(attrs={'id': 'user-searchbox'}))
    action = forms.ChoiceField(
        widget=forms.RadioSelect, choices=(
            ('Promote', 'Promote to Superuser'),
            ('Demote', 'Demote from Superuser'),
            ('Create', 'Create a user'),
            ('Delete', 'Permanently delete user')))


def strip_charfield(self, value):
    return charfield_clean(self, value.strip())


charfield_clean = forms.fields.CharField.clean
forms.fields.CharField.clean = strip_charfield

from django import forms


class BugReportForm(forms.Form):

    bug = forms.CharField(label="Bug (required)", required=True)
    description = forms.CharField(
        label="Description (required)",
        widget=forms.Textarea(attrs={'rows': 4, 'cols': 50}), required=True)
    reproduce = forms.CharField(
        label="How to reproduce the error",
        widget=forms.Textarea(attrs={'rows': 4, 'cols': 50}), required=False)
    expected = forms.CharField(
        label="The expected result",
        widget=forms.Textarea(attrs={'rows': 4, 'cols': 50}), required=False)
    actual = forms.CharField(
        label="The actual result",
        widget=forms.Textarea(attrs={'rows': 4, 'cols': 50}), required=False)
    session_data = forms.CharField(widget=forms.HiddenInput())


class EditUserForm(forms.Form):
    user = forms.CharField(
        widget=forms.TextInput(attrs={'id': 'user-searchbox'}))
    action = forms.ChoiceField(
        widget=forms.RadioSelect, choices=(
            ('Promote', 'Promote to Superuser'),
            ('Demote', 'Demote from Superuser'),
            ('Create', 'Create a user'),
            ('Delete', 'Permanently delete user')))


charfield_clean = forms.fields.CharField.clean


def strip_charfield(self, value):
    if hasattr(value, 'strip'):
        value = value.strip()
    return charfield_clean(self, value)


forms.fields.CharField.clean = strip_charfield

Check for strip attr for none values
Check for strip attr for none values
