
from flask_babel import lazy_gettext
from wtforms import StringField, TextAreaField
from wtforms.validators import Optional

from ....util.l10n import LocalizedForm


class CreateForm(LocalizedForm):
    hostname = StringField(lazy_gettext('Hostname'), validators=[Optional()])
    notes = TextAreaField(lazy_gettext('Notes'), validators=[Optional()])


import re

from flask_babel import lazy_gettext
from wtforms import StringField, TextAreaField
from wtforms.validators import Length, Optional, Regexp

from ....util.l10n import LocalizedForm


HOSTNAME_REGEX = re.compile('^[a-z][a-z0-9-\.]+$')


class CreateForm(LocalizedForm):
    hostname = StringField(
        lazy_gettext('Hostname'),
        validators=[Optional(), Length(max=32), Regexp(HOSTNAME_REGEX)],
    )
    notes = TextAreaField(
        lazy_gettext('Notes'), validators=[Optional(), Length(max=1000)]
    )

Make guest server form validation more strict
Make guest server form validation more strict

+ 
+ import re
  
  from flask_babel import lazy_gettext
  from wtforms import StringField, TextAreaField
- from wtforms.validators import Optional
+ from wtforms.validators import Length, Optional, Regexp
  
  from ....util.l10n import LocalizedForm
  
  
+ HOSTNAME_REGEX = re.compile('^[a-z][a-z0-9-\.]+$')
+ 
+ 
  class CreateForm(LocalizedForm):
-     hostname = StringField(lazy_gettext('Hostname'), validators=[Optional()])
-     notes = TextAreaField(lazy_gettext('Notes'), validators=[Optional()])
+     hostname = StringField(
+         lazy_gettext('Hostname'),
+         validators=[Optional(), Length(max=32), Regexp(HOSTNAME_REGEX)],
+     )
+     notes = TextAreaField(
+         lazy_gettext('Notes'), validators=[Optional(), Length(max=1000)]
+     )
  
Make guest server form validation more strict
## Code Before:

from flask_babel import lazy_gettext
from wtforms import StringField, TextAreaField
from wtforms.validators import Optional

from ....util.l10n import LocalizedForm


class CreateForm(LocalizedForm):
    hostname = StringField(lazy_gettext('Hostname'), validators=[Optional()])
    notes = TextAreaField(lazy_gettext('Notes'), validators=[Optional()])

## Instruction:
Make guest server form validation more strict
## Code After:

import re

from flask_babel import lazy_gettext
from wtforms import StringField, TextAreaField
from wtforms.validators import Length, Optional, Regexp

from ....util.l10n import LocalizedForm


HOSTNAME_REGEX = re.compile('^[a-z][a-z0-9-\.]+$')


class CreateForm(LocalizedForm):
    hostname = StringField(
        lazy_gettext('Hostname'),
        validators=[Optional(), Length(max=32), Regexp(HOSTNAME_REGEX)],
    )
    notes = TextAreaField(
        lazy_gettext('Notes'), validators=[Optional(), Length(max=1000)]
    )
