
from django import forms
from django.utils.translation import ugettext_lazy as _


class IkiwikiCreateForm(forms.Form):
    """Form to create a wiki or blog."""
    site_type = forms.ChoiceField(
        label=_('Type'),
        choices=[('wiki', 'Wiki'), ('blog', 'Blog')])

    name = forms.CharField(label=_('Name'))

    admin_name = forms.CharField(label=_('Admin Account Name'))

    admin_password = forms.CharField(
        label=_('Admin Account Password'),
        widget=forms.PasswordInput())


from django import forms
from django.utils.translation import ugettext_lazy as _
from django.core.validators import RegexValidator


class IkiwikiCreateForm(forms.Form):
    """Form to create a wiki or blog."""
    site_type = forms.ChoiceField(
        label=_('Type'),
        choices=[('wiki', 'Wiki'), ('blog', 'Blog')])

    name = forms.CharField(label=_('Name'),
                           validators=[RegexValidator(regex='^[a-zA-Z0-9]+$')])

    admin_name = forms.CharField(label=_('Admin Account Name'))

    admin_password = forms.CharField(
        label=_('Admin Account Password'),
        widget=forms.PasswordInput())

Allow only alphanumerics in wiki/blog name
ikiwiki: Allow only alphanumerics in wiki/blog name

  
  from django import forms
  from django.utils.translation import ugettext_lazy as _
+ from django.core.validators import RegexValidator
  
  
  class IkiwikiCreateForm(forms.Form):
      """Form to create a wiki or blog."""
      site_type = forms.ChoiceField(
          label=_('Type'),
          choices=[('wiki', 'Wiki'), ('blog', 'Blog')])
  
-     name = forms.CharField(label=_('Name'))
+     name = forms.CharField(label=_('Name'),
+                            validators=[RegexValidator(regex='^[a-zA-Z0-9]+$')])
  
      admin_name = forms.CharField(label=_('Admin Account Name'))
  
      admin_password = forms.CharField(
          label=_('Admin Account Password'),
          widget=forms.PasswordInput())
  
Allow only alphanumerics in wiki/blog name
## Code Before:

from django import forms
from django.utils.translation import ugettext_lazy as _


class IkiwikiCreateForm(forms.Form):
    """Form to create a wiki or blog."""
    site_type = forms.ChoiceField(
        label=_('Type'),
        choices=[('wiki', 'Wiki'), ('blog', 'Blog')])

    name = forms.CharField(label=_('Name'))

    admin_name = forms.CharField(label=_('Admin Account Name'))

    admin_password = forms.CharField(
        label=_('Admin Account Password'),
        widget=forms.PasswordInput())

## Instruction:
Allow only alphanumerics in wiki/blog name
## Code After:

from django import forms
from django.utils.translation import ugettext_lazy as _
from django.core.validators import RegexValidator


class IkiwikiCreateForm(forms.Form):
    """Form to create a wiki or blog."""
    site_type = forms.ChoiceField(
        label=_('Type'),
        choices=[('wiki', 'Wiki'), ('blog', 'Blog')])

    name = forms.CharField(label=_('Name'),
                           validators=[RegexValidator(regex='^[a-zA-Z0-9]+$')])

    admin_name = forms.CharField(label=_('Admin Account Name'))

    admin_password = forms.CharField(
        label=_('Admin Account Password'),
        widget=forms.PasswordInput())
