Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)
invoice_id = request.params.get('invoice_id')
date = request.params.get('date')
date = parse_date(date, locale=get_locale_name())
invoice = Invoice.get(invoice_id)
if not invoice:
return
account_balance = get_account_balance(
invoice.account_id, None, date
)
if account_balance <= value:
raise colander.Invalid(
node,
_(u'Account Balance is not enough for refund'),
)
return colander.All(validator,)
def iso_code_validator(node, kw):
request = kw.get('request')
def validator(node, value):
country = Country.by_iso_code(value)
if (
country
and str(country.id) != request.params.get('id')
):
raise colander.Invalid(
node,
_(u'Country with the same iso code exists'),
)
return colander.All(colander.Length(min=2, max=2), validator,)
def date_validator(node, kw):
request = kw.get('request')
def validator(node, value):
if value >= parse_date(request.params.get('date_to')):
raise colander.Invalid(node, _(u"Invalid dates, please check"))
return colander.All(validator)
widget=AutocompleteInputWidget(),
)
class PrincipalBasic(colander.MappingSchema):
title = colander.SchemaNode(colander.String(), title=_("Title"))
email = colander.SchemaNode(
colander.String(), title=_("Email"), validator=deferred_email_validator
)
class PrincipalFull(PrincipalBasic):
name = colander.SchemaNode(
colander.String(),
title=_("Name"),
validator=colander.All(name_pattern_validator, name_new_validator),
)
password = colander.SchemaNode(
colander.String(),
title=_("Password"),
validator=colander.Length(min=5),
missing=None,
widget=CheckedPasswordWidget(),
)
active = colander.SchemaNode(
colander.Boolean(),
title=_("Active"),
description=_("Untick this to deactivate the account."),
)
roles = colander.SchemaNode(
colander.Set(),
validator=roleset_validator,
)
if (
location
and (
str(location.id) != request.params.get('id')
or (
str(location.id) == request.params.get('id')
and request.view_name == 'copy'
)
)
):
raise colander.Invalid(
node,
_(u'Location with the same name exists'),
)
return colander.All(colander.Length(max=128), validator,)
def validate(data, project):
same_project = lambda s: Project.by_slug(s) == project
same_project = colander.Function(same_project, message="Project exists")
class ProjectValidator(colander.MappingSchema):
slug = colander.SchemaNode(colander.String(),
validator=colander.All(database_name,
same_project))
label = colander.SchemaNode(colander.String(),
validator=colander.Length(min=3))
private = colander.SchemaNode(colander.Boolean(),
missing=False)
author = colander.SchemaNode(AccountRef())
settings = colander.SchemaNode(colander.Mapping(),
missing={})
validator = ProjectValidator()
return validator.deserialize(data)
def csrf_token_validator(node, kw):
request = kw.get('request')
def validator(node, value):
if value != request.session.get_csrf_token():
raise colander.Invalid(
node,
_(u'Invalid CSRF token'),
)
return colander.All(colander.Length(max=255), validator,)
def scope_type_validator(node, kw):
request = kw.get('request')
def validator(node, value):
if value == 'structure' and not request.params.get('structure_id'):
raise colander.Invalid(
node,
_(u'Set structure for scope'),
)
return colander.All(validator,)
def name_validator(node, kw):
request = kw.get('request')
def validator(node, value):
account = Account.by_name(value)
if (
account
and str(account.id) != request.params.get('id')
):
raise colander.Invalid(
node,
_(u'Account with the same name exists'),
)
return colander.All(colander.Length(max=255), validator,)
def convert_all_validator(self, validator):
if isinstance(validator, colander.All):
converted = {}
for v in validator.validators:
ret = self(None, v)
converted.update(ret)
return converted
else:
return None