From b42d3691307d4e3f9c55f6652554e8eef92ead34 Mon Sep 17 00:00:00 2001 From: Ekaterina Fedorova Date: Tue, 18 Jun 2013 12:18:09 +0400 Subject: [PATCH] Add hostname validator Change-Id: Ic735aec1e667d821e2b1aac552ce7731d867accd --- muranodashboard/panel/forms.py | 6 ++++++ muranodashboard/panel/views.py | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/muranodashboard/panel/forms.py b/muranodashboard/panel/forms.py index 9bd9ccdd7..c14b66772 100644 --- a/muranodashboard/panel/forms.py +++ b/muranodashboard/panel/forms.py @@ -101,12 +101,18 @@ class ServiceConfigurationForm(forms.Form): class CommonPropertiesExtension(object): + hostname_re = re.compile( + r'^(([a-zA-Z0-9#][a-zA-Z0-9-#]*[a-zA-Z0-9#])\.)' + r'*([A-Za-z0-9#]|[A-Za-z0-9#][A-Za-z0-9-#]*[A-Za-z0-9#])$') + validate_hostname = RegexValidator(hostname_re, _('text')) + def __init__(self): self.fields.insert( len(self.fields), 'unit_name_template', forms.CharField( label=_('Hostname template'), required=False, + validators=[self.validate_hostname], help_text='You can set a template for machine hostname. \ Use # for incrementation: host# would be host1, host2, etc. \ Note: We do not have validation for this field.\ diff --git a/muranodashboard/panel/views.py b/muranodashboard/panel/views.py index c72b14bdc..3d174679a 100644 --- a/muranodashboard/panel/views.py +++ b/muranodashboard/panel/views.py @@ -159,7 +159,6 @@ class IndexView(tables.DataTableView): 'Service, check connection details.') except HTTPInternalServerError: messages.error(self.request, 'Environment doesn\'t exist') - return environments