Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def is_not_future(dt, context=None):
if dt > now:
raise ValidationError(future_error_msg)
def validate_publish(self, data, dt, context):
if data['should_raise'] is True:
raise ValidationError(u'')
return dt
def validate_bar(cls, data, value):
errors = {}
if 'a' not in value:
errors['a'] = ValidationError('Key a must be set.')
if 'b' not in value:
errors['b'] = ValidationError('Key b must be set.')
if errors:
raise DataError(errors)
def test_clean_validation_messages_list():
error = ValidationError(["A", "B", "C"])
assert error.messages, ["A", "B", "C"]
if not relatedItem and data.get('featureOf') in ['item', 'lot']:
raise ValidationError(u'This field is required.')
if (
data.get('featureOf') == 'item'
and isinstance(data['__parent__'], Model)
and relatedItem
not in [i.id for i in data['__parent__'].items]
):
raise ValidationError(u"relatedItem should be one of items")
if (
data.get('featureOf') == 'lot'
and isinstance(data['__parent__'], Model)
and relatedItem
not in [i.id for i in data['__parent__'].lots]
):
raise ValidationError(u"relatedItem should be one of lots")
def validate_parameters(self, data, parameters):
if isinstance(data['__parent__'], Model):
tender = data['__parent__']
if not parameters and tender.features:
raise ValidationError(u'This field is required.')
if tender.lots:
lots = [i.relatedLot for i in data['lotValues']]
items = [i.id for i in tender.items if i.relatedLot in lots]
codes = dict([
(i.code, [x.value for x in i.enum])
for i in (tender.features or [])
if i.featureOf == 'tenderer' or i.featureOf == 'lot' and i.relatedItem in lots or i.featureOf == 'item' and i.relatedItem in items
])
if set([i['code'] for i in parameters]) != set(codes):
raise ValidationError(u"All features parameters is required.")
elif set([i['code'] for i in parameters]) != set([i.code for i in (tender.features or [])]):
raise ValidationError(u"All features parameters is required.")
def validate_relatedItem(self, data, relatedItem):
if not relatedItem and data.get('featureOf') in ['item', 'lot']:
raise ValidationError(u'This field is required.')
if (
data.get('featureOf') == 'item'
and isinstance(data['__parent__'], Model)
and relatedItem
not in [i.id for i in data['__parent__'].items]
):
raise ValidationError(u"relatedItem should be one of items")
if (
data.get('featureOf') == 'lot'
and isinstance(data['__parent__'], Model)
and relatedItem
not in [i.id for i in data['__parent__'].lots]
):
raise ValidationError(u"relatedItem should be one of lots")
def validate_template_path(self, data, value):
if value and data["class_path"]:
raise ValidationError(
"class_path cannot be present when "
"template_path is provided.")
self.validate_stack_source(data)
def validate_stack_source(self, data):
# Locked stacks don't actually need a template, since they're
# read-only.
if data["locked"]:
return
if not (data["class_path"] or data["template_path"]):
raise ValidationError(
"class_path or template_path is required.")
def validate_registrationID(self, data, value):
if value and data['status'] != 'complete':
raise ValidationError(u"You can fill registrationID only when status is complete")