Update LowerCaseCharField to subclass proper CharField
[ganeti_webmgr.git] / ganeti_web / forms / vm_template.py
blob936412ed4dfc4746d68d56b4b368c3bb037e54f5
1 # Copyright (C) 2010 Oregon State University et al.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
16 # USA.
18 from django.forms import Form, CharField, ModelChoiceField, ValidationError
19 from django.utils.translation import ugettext_lazy as _
21 from ganeti_web.models import ClusterUser
24 class VirtualMachineTemplateCopyForm(Form):
25 """
26 Form used to when copying a VirtualMachineTemplate
27 """
28 template_name = CharField(label=_('Template Name'), max_length=255)
29 description = CharField(label=_('Description'), max_length=255,
30 required=False)
33 class VMInstanceFromTemplate(Form):
34 owner = ModelChoiceField(label=_('Owner'),
35 queryset=ClusterUser.objects.all(),
36 empty_label=None)
37 hostname = CharField(label=_('Instance Name'), max_length=255)
39 def clean_hostname(self):
40 hostname = self.cleaned_data.get('hostname')
42 # Spaces in hostname will always break things.
43 if ' ' in hostname:
44 self.errors["hostname"] = self.error_class(
45 ["Hostnames cannot contain spaces."])
46 return hostname
49 class TemplateFromVMInstance(Form):
50 template_name = CharField(label=_("Template Name"), max_length=255)
52 def clean_template_name(self):
53 name = self.cleaned_data['template_name']
54 if name.strip(' ') == '':
55 raise ValidationError(_("Name cannot consist of spaces."))
56 return name