1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-07-31 12:41:08 +00:00

format python code with black

This commit is contained in:
catborise 2022-11-02 08:54:35 +03:00
parent ea409ca863
commit 217e106c8b
55 changed files with 2510 additions and 1454 deletions

View file

@ -5,9 +5,15 @@ from django.utils.translation import gettext_lazy as _
class AddStgPool(forms.Form):
name = forms.CharField(error_messages={'required': _('No pool name has been entered')}, max_length=20)
name = forms.CharField(
error_messages={"required": _("No pool name has been entered")}, max_length=20
)
stg_type = forms.CharField(max_length=10)
target = forms.CharField(error_messages={'required': _('No path has been entered')}, max_length=100, required=False)
target = forms.CharField(
error_messages={"required": _("No path has been entered")},
max_length=100,
required=False,
)
source = forms.CharField(max_length=100, required=False)
ceph_user = forms.CharField(required=False)
ceph_host = forms.CharField(required=False)
@ -17,49 +23,62 @@ class AddStgPool(forms.Form):
source_format = forms.CharField(required=False)
def clean_name(self):
name = self.cleaned_data['name']
have_symbol = re.match('^[a-zA-Z0-9._-]+$', name)
name = self.cleaned_data["name"]
have_symbol = re.match("^[a-zA-Z0-9._-]+$", name)
if not have_symbol:
raise forms.ValidationError(_('The pool name must not contain any special characters'))
raise forms.ValidationError(
_("The pool name must not contain any special characters")
)
elif len(name) > 20:
raise forms.ValidationError(_('The pool name must not exceed 20 characters'))
raise forms.ValidationError(
_("The pool name must not exceed 20 characters")
)
return name
def clean_target(self):
storage_type = self.cleaned_data['stg_type']
target = self.cleaned_data['target']
have_symbol = re.match('^[a-zA-Z0-9/]+$', target)
if storage_type == 'dir' or storage_type == 'netfs':
storage_type = self.cleaned_data["stg_type"]
target = self.cleaned_data["target"]
have_symbol = re.match("^[a-zA-Z0-9/]+$", target)
if storage_type == "dir" or storage_type == "netfs":
if not have_symbol:
raise forms.ValidationError(_('The target must not contain any special characters'))
if storage_type == 'dir' or storage_type == 'netfs':
raise forms.ValidationError(
_("The target must not contain any special characters")
)
if storage_type == "dir" or storage_type == "netfs":
if not target:
raise forms.ValidationError(_('No path has been entered'))
raise forms.ValidationError(_("No path has been entered"))
return target
def clean_source(self):
storage_type = self.cleaned_data['stg_type']
source = self.cleaned_data['source']
have_symbol = re.match('^[a-zA-Z0-9\/]+$', source)
if storage_type == 'logical' or storage_type == 'netfs':
storage_type = self.cleaned_data["stg_type"]
source = self.cleaned_data["source"]
have_symbol = re.match("^[a-zA-Z0-9\/]+$", source)
if storage_type == "logical" or storage_type == "netfs":
if not source:
raise forms.ValidationError(_('No device or path has been entered'))
raise forms.ValidationError(_("No device or path has been entered"))
if not have_symbol:
raise forms.ValidationError(_('The disk source must not contain any special characters'))
raise forms.ValidationError(
_("The disk source must not contain any special characters")
)
return source
class CreateVolumeForm(forms.Form):
name = forms.CharField(max_length=120)
format = forms.ChoiceField(required=True, choices=(('qcow2', 'qcow2 (recommended)'), ('qcow', 'qcow'), ('raw', 'raw')))
format = forms.ChoiceField(
required=True,
choices=(("qcow2", "qcow2 (recommended)"), ("qcow", "qcow"), ("raw", "raw")),
)
size = forms.IntegerField()
meta_prealloc = forms.BooleanField(required=False)
def clean_name(self):
name = self.cleaned_data['name']
have_symbol = re.match('^[a-zA-Z0-9._-]+$', name)
name = self.cleaned_data["name"]
have_symbol = re.match("^[a-zA-Z0-9._-]+$", name)
if not have_symbol:
raise forms.ValidationError(_('The image name must not contain any special characters'))
raise forms.ValidationError(
_("The image name must not contain any special characters")
)
return name
@ -67,14 +86,21 @@ class CloneImage(forms.Form):
name = forms.CharField(max_length=120)
image = forms.CharField(max_length=120)
convert = forms.BooleanField(required=False)
format = forms.ChoiceField(required=False, choices=(('qcow2', 'qcow2 (recommended)'), ('qcow', 'qcow'), ('raw', 'raw')))
format = forms.ChoiceField(
required=False,
choices=(("qcow2", "qcow2 (recommended)"), ("qcow", "qcow"), ("raw", "raw")),
)
meta_prealloc = forms.BooleanField(required=False)
def clean_name(self):
name = self.cleaned_data['name']
have_symbol = re.match('^[a-zA-Z0-9._-]+$', name)
name = self.cleaned_data["name"]
have_symbol = re.match("^[a-zA-Z0-9._-]+$", name)
if not have_symbol:
raise forms.ValidationError(_('The image name must not contain any special characters'))
raise forms.ValidationError(
_("The image name must not contain any special characters")
)
elif len(name) > 120:
raise forms.ValidationError(_('The image name must not exceed 120 characters'))
raise forms.ValidationError(
_("The image name must not exceed 120 characters")
)
return name