本文整理汇总了Python中horizon.forms.ValidationError方法的典型用法代码示例。如果您正苦于以下问题:Python forms.ValidationError方法的具体用法?Python forms.ValidationError怎么用?Python forms.ValidationError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizon.forms
的用法示例。
在下文中一共展示了forms.ValidationError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ValidationError [as 别名]
def clean(self):
'''Check to make sure password fields match.'''
data = super(SignupForm, self).clean()
# basic check for now
if 'username' in data:
if User.objects.filter(
username=data['username'],
email=data['email']).exists():
raise validators.ValidationError(
_('Username or email exists in database.'))
if 'password' in data:
if data['password'] != data.get('confirm_password', None):
raise validators.ValidationError(_('Passwords do not match.'))
else:
data.pop('confirm_password')
return data
示例2: clean
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ValidationError [as 别名]
def clean(self):
cleaned_data = super(DefinitionForm, self).clean()
if cleaned_data.get('definition_upload'):
files = self.request.FILES
cleaned_data['definition'] = files['definition_upload'].read()
elif cleaned_data.get('definition_data'):
cleaned_data['definition'] = cleaned_data['definition_data']
else:
raise forms.ValidationError(
_('You must specify the definition source.'))
try:
validated = api.workflow_validate(
self.request,
cleaned_data['definition']
)
except Exception as e:
raise forms.ValidationError(str(e))
if not validated.get('valid'):
raise forms.ValidationError(
validated.get('error', _('Validated failed')))
return cleaned_data
示例3: clean
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ValidationError [as 别名]
def clean(self):
cleaned_data = super(DefinitionForm, self).clean()
if cleaned_data.get('definition_upload'):
files = self.request.FILES
cleaned_data['definition'] = files['definition_upload'].read()
elif cleaned_data.get('definition_data'):
cleaned_data['definition'] = cleaned_data['definition_data']
else:
raise forms.ValidationError(
_('You must specify the definition source.'))
try:
validated = api.workbook_validate(
self.request,
cleaned_data['definition']
)
except Exception as e:
raise forms.ValidationError(str(e))
if not validated.get('valid'):
raise forms.ValidationError(
validated.get('error', _('Validated failed')))
return cleaned_data
示例4: _check_allocation_pools
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ValidationError [as 别名]
def _check_allocation_pools(self, allocation_pools):
for p in allocation_pools.split('\n'):
p = p.strip()
if not p:
continue
pool = p.split(',')
if len(pool) != 2:
msg = _('Start and end addresses must be specified '
'(value=%s)') % p
raise forms.ValidationError(msg)
start, end = [self._convert_ip_address(ip, "allocation_pools")
for ip in pool]
if start > end:
msg = _('Start address is larger than end address '
'(value=%s)') % p
raise forms.ValidationError(msg)
示例5: clean_uploaded_files
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ValidationError [as 别名]
def clean_uploaded_files(self, prefix, files):
upload_str = prefix + "_upload"
has_upload = upload_str in files
if has_upload:
upload_file = files[upload_str]
log_script_name = upload_file.name
LOG.info('got upload %s' % log_script_name)
if upload_file._size > 16 * 1024: # 16kb
msg = _('File exceeds maximum size (16kb)')
raise forms.ValidationError(msg)
else:
script = upload_file.read()
if script != "":
try:
normalize_newlines(script)
except Exception as e:
msg = _('There was a problem parsing the'
' %(prefix)s: %(error)s')
msg = msg % {'prefix': prefix, 'error': e}
raise forms.ValidationError(msg)
return script
else:
return None
示例6: clean
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ValidationError [as 别名]
def clean(self):
cleaned_data = super(SetAggregateInfoAction, self).clean()
name = cleaned_data.get('name')
try:
aggregates = api.nova.aggregate_details_list(self.request)
except Exception:
msg = _('Unable to get host aggregate list')
exceptions.check_message(["Connection", "refused"], msg)
raise
if aggregates is not None:
for aggregate in aggregates:
if aggregate.name.lower() == name.lower():
raise forms.ValidationError(
_('The name "%s" is already used by '
'another host aggregate.')
% name
)
return cleaned_data
示例7: clean_qos_spec_choice
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ValidationError [as 别名]
def clean_qos_spec_choice(self):
# ensure that new association isn't the same as current association
cleaned_new_spec_id = self.cleaned_data.get('qos_spec_choice')
cur_spec_id = self.initial['cur_qos_spec_id']
found_error = False
if cur_spec_id:
# new = current
if cur_spec_id == cleaned_new_spec_id:
found_error = True
else:
# no current association
if cleaned_new_spec_id == '-1':
# new = current
found_error = True
if found_error:
raise forms.ValidationError(
_('New associated QoS Spec must be different than '
'the current associated QoS Spec.'))
return cleaned_new_spec_id
示例8: clean
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ValidationError [as 别名]
def clean(self):
cleaned_data = super(CreateFlavorInfoAction, self).clean()
name = cleaned_data.get('name')
flavor_id = cleaned_data.get('flavor_id')
try:
flavors = api.nova.flavor_list(self.request, None)
except Exception:
flavors = []
msg = _('Unable to get flavor list')
exceptions.check_message(["Connection", "refused"], msg)
raise
if flavors is not None:
for flavor in flavors:
if flavor.name == name:
raise forms.ValidationError(
_('The name "%s" is already used by another flavor.')
% name
)
if flavor.id == flavor_id:
raise forms.ValidationError(
_('The ID "%s" is already used by another flavor.')
% flavor_id
)
return cleaned_data
示例9: clean
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ValidationError [as 别名]
def clean(self):
cleaned_data = super(UpdateProjectQuotaAction, self).clean()
usages = quotas.tenant_quota_usages(
self.request, tenant_id=self.initial['project_id'])
# Validate the quota values before updating quotas.
bad_values = []
for key, value in cleaned_data.items():
used = usages[key].get('used', 0)
if value is not None and value >= 0 and used > value:
bad_values.append(_('%(used)s %(key)s used') %
{'used': used,
'key': quotas.QUOTA_NAMES.get(key, key)})
if bad_values:
value_str = ", ".join(bad_values)
msg = (_('Quota value(s) cannot be less than the current usage '
'value(s): %s.') %
value_str)
raise forms.ValidationError(msg)
return cleaned_data
示例10: clean_uploaded_files
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ValidationError [as 别名]
def clean_uploaded_files(self, prefix, files):
upload_str = prefix + "_upload"
has_upload = upload_str in files
if has_upload:
upload_file = files[upload_str]
log_script_name = upload_file.name
LOG.info('got upload %s' % log_script_name)
script = upload_file.read()
if script != "":
try:
normalize_newlines(script)
except Exception as e:
msg = _('There was a problem parsing the'
' %(prefix)s: %(error)s')
msg = msg % {'prefix': prefix, 'error': e}
raise forms.ValidationError(msg)
return script
else:
return None
示例11: clean_period
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ValidationError [as 别名]
def clean_period(self):
'''Check to make sure period is zero unless type is WEBHOOK.
For WEBHOOK period must be set to 0 or 60.
'''
data = self.cleaned_data
if data['type'] != constants.NotificationType.WEBHOOK and data['period'] != '0':
raise forms.ValidationError(
_('Period must be zero except for type webhook.'))
return data['period']
示例12: clean_expression
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ValidationError [as 别名]
def clean_expression(self):
data = self.cleaned_data['expression']
value = data.split(' ')[2]
if not value.isdigit():
raise forms.ValidationError("Value must be an integer")
# Always return the cleaned data, whether you have changed it or
# not.
return data
示例13: clean
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ValidationError [as 别名]
def clean(self):
data = super(OnBoardVNF, self).clean()
# The key can be missing based on particular upload
# conditions. Code defensively for it here...
toscal_file = data.get('toscal_file', None)
toscal_raw = data.get('direct_input', None)
source_type = data.get("source_type")
if source_type == "file" and not toscal_file:
raise ValidationError(
_("No TOSCA template file selected."))
if source_type == "raw" and not toscal_raw:
raise ValidationError(
_("No direct input specified."))
if toscal_file and not toscal_file.name.endswith(('.yaml', '.csar')):
raise ValidationError(_("Only .yaml or .csar file uploads \
are supported"))
try:
if toscal_file:
toscal_str = self.files['toscal_file'].read()
else:
toscal_str = data['direct_input']
# toscal = yaml.loads(toscal_str)
data['tosca'] = toscal_str
except Exception as e:
msg = _('There was a problem loading the namespace: %s.') % e
raise forms.ValidationError(msg)
return data
示例14: clean
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ValidationError [as 别名]
def clean(self):
data = super(OnBoardVNFFG, self).clean()
# The key can be missing based on particular upload
# conditions. Code defensively for it here...
toscal_file = data.get('toscal_file', None)
toscal_raw = data.get('direct_input', None)
if toscal_raw and toscal_file:
raise ValidationError(
_("Cannot specify both file and direct input."))
if not toscal_raw and not toscal_file:
raise ValidationError(
_("No input was provided for the namespace content."))
if toscal_file and not toscal_file.name.endswith(('.yaml', '.csar')):
raise ValidationError(_("Only .yaml or .csar file uploads \
are supported"))
try:
if toscal_file:
toscal_str = self.files['toscal_file'].read()
else:
toscal_str = data['direct_input']
toscal = yaml.safe_load(toscal_str)
data['tosca'] = toscal
except Exception as e:
msg = _('There was a problem loading the namespace: %s.') % e
raise forms.ValidationError(msg)
return data
示例15: clean
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ValidationError [as 别名]
def clean(self):
data = super(OnBoardNS, self).clean()
# The key can be missing based on particular upload
# conditions. Code defensively for it here...
toscal_file = data.get('toscal_file', None)
toscal_raw = data.get('direct_input', None)
source_type = data.get("source_type")
if source_type == "file" and not toscal_file:
raise ValidationError(
_("No TOSCA template file selected."))
if source_type == "raw" and not toscal_raw:
raise ValidationError(
_("No direct input specified."))
if toscal_file and not toscal_file.name.endswith(('.yaml', '.csar')):
raise ValidationError(_("Only .yaml or .csar file uploads \
are supported"))
try:
if toscal_file:
toscal_str = self.files['toscal_file'].read()
else:
toscal_str = data['direct_input']
# toscal = yaml.loads(toscal_str)
data['tosca'] = toscal_str
except Exception as e:
msg = _('There was a problem loading the namespace: %s.') % e
raise forms.ValidationError(msg)
return data