本文整理汇总了Python中colander.Invalid方法的典型用法代码示例。如果您正苦于以下问题:Python colander.Invalid方法的具体用法?Python colander.Invalid怎么用?Python colander.Invalid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类colander
的用法示例。
在下文中一共展示了colander.Invalid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Invalid [as 别名]
def validate(data, schema):
"""Validate data against a Colander schema class.
This is a helper function used by :py:class:`ColanderSchemaValidationMixin`
to validate data against a Colander schema. If validation fails this function
will raise a :py:class:`pyramid.httpexceptions.HTTPBadRequest` exception
describing the validation error.
:raises pyramid.httpexceptions.HTTPBadRequest: if validation fails this
exception is raised to abort any further processing.
"""
schema_instance = schema()
try:
schema_instance.deserialize(data)
except colander.Invalid as e:
raise HTTPBadRequest(e.msg)
示例2: photo_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Invalid [as 别名]
def photo_validator(node, kw):
request = kw.get('request')
def validator(node, value):
if not is_allowed_file_size(value.file):
raise colander.Invalid(
node,
_(u'File is too big')
)
try:
request.storage.file_allowed(value, IMAGES)
except:
raise colander.Invalid(
node,
_(u'Only images allowed'),
)
value.file.seek(0)
return colander.All(validator,)
示例3: status_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Invalid [as 别名]
def status_validator(node, kw):
request = kw.get('request')
def validator(node, value):
campaign_id = request.params.get('id')
campaign = Campaign.get(campaign_id)
if value not in ('ready', 'in_work'):
return
if not campaign or (
campaign and not campaign.is_status_ready()
and not campaign.is_status_in_work()
):
raise colander.Invalid(
node,
_(u'This is automatic status, can\'t set it manualy'),
)
return validator
示例4: subaccount_from_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Invalid [as 别名]
def subaccount_from_validator(node, kw):
request = kw.get('request')
def validator(node, value):
date = parse_datetime(request.params.get('date'))
sum = request.params.get('sum', 0) or 0
sum = Decimal(sum)
subaccount = Subaccount.get(value)
balance = get_account_balance(subaccount.account_id, None, date)
if balance < sum:
raise colander.Invalid(
node,
_(u'Max sum for transfer %s' % balance),
)
subaccount_to_id = cast_int(request.params.get('subaccount_to_id'))
if not any(
[value, subaccount_to_id]
):
raise colander.Invalid(
node,
_(u'Set at least subaccount from any section'),
)
return colander.All(validator,)
示例5: subaccount_to_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Invalid [as 别名]
def subaccount_to_validator(node, kw):
request = kw.get('request')
def validator(node, value):
subaccount_id = cast_int(request.params.get('subaccount_from_id'))
subaccount = Subaccount.get(value)
subaccount_from = Subaccount.get(subaccount_id)
if(
subaccount
and subaccount_from
and (
subaccount.account_id != subaccount_from.account_id
or (
subaccount.account.currency_id
!= subaccount_from.account.currency.id
)
)
):
raise colander.Invalid(
node,
_(u'Cashflow with same currency allowed only'),
)
return colander.All(validator,)
示例6: employee_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Invalid [as 别名]
def employee_validator(node, kw):
request = kw.get('request')
def validator(node, value):
employee = Employee.get(value)
if is_employee_currently_dismissed(employee):
raise colander.Invalid(
node,
_(u'Employee is dismissed already.')
)
if not get_employee_position(employee):
raise colander.Invalid(
node,
_(u'Can\'t dismiss employee without position.')
)
return validator
示例7: maintainer_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Invalid [as 别名]
def maintainer_validator(node, kw):
request = kw.get('request')
def validator(node, value):
employee = Employee.get(value)
if is_employee_currently_dismissed(employee):
raise colander.Invalid(
node,
_(u'Employee is dismissed'),
)
if not get_employee_position(employee):
raise colander.Invalid(
node,
_(u'Employee has no appointment'),
)
return validator
示例8: order_id_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Invalid [as 别名]
def order_id_validator(node, kw):
request = kw.get('request')
def validator(node, value):
invoice = (
DBSession.query(Invoice)
.filter(Invoice.order_id == value)
.first()
)
if (
invoice
and str(invoice.id) != request.params.get('id')
):
raise colander.Invalid(
node,
_(u'Invoice for this order already exists'),
)
order = Order.get(value)
for order_item in order.orders_items:
if not order_item.calculation and order_item.is_success():
raise colander.Invalid(
node,
_(u'Some order items has no calculations'),
)
return colander.All(validator,)
示例9: sum_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Invalid [as 别名]
def sum_validator(node, kw):
request = kw.get('request')
def validator(node, value):
if value <= 0:
raise colander.Invalid(
node,
_(u'Sum must be more then zero'),
)
subaccount_id = int(request.params.get('subaccount_id'))
date = parse_datetime(request.params.get('date'))
sum = Decimal(request.params.get('sum'))
subaccount = Subaccount.get(subaccount_id)
balance = get_account_balance(subaccount.account_id, None, date)
if balance < sum:
raise colander.Invalid(
node,
_(u'Max sum for payment %s' % balance),
)
return validator
示例10: source_id_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Invalid [as 别名]
def source_id_validator(node, kw):
request = kw.get('request')
def validator(node, value):
resource_cls = get_resource_class(
request.params.get('subaccount_type')
)
rt = get_resource_type_by_resource_cls(resource_cls)
account_id = request.params.get('account_id') or 0
subaccount = get_subaccount_by_source_id(
value, rt.id, account_id
)
if (
subaccount
and str(subaccount.id) != request.params.get('id')
):
raise colander.Invalid(
node,
_(u'Subaccount for this account already exists'),
)
return colander.All(validator,)
示例11: upload_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Invalid [as 别名]
def upload_validator(node, kw):
request = kw.get('request')
def validator(node, value):
if not is_allowed_file_size(value.file):
raise colander.Invalid(
node,
_(u'File is too big')
)
try:
request.storage.file_allowed(value, request.storage.extensions)
except:
raise colander.Invalid(
node,
_(u'This files types is not allowed'),
)
value.file.seek(0)
return colander.All(validator,)
示例12: date_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Invalid [as 别名]
def date_validator(node, kw):
request = kw.get('request')
def validator(node, value):
vat = (
DBSession.query(Vat)
.filter(
Vat.date == value,
Vat.account_id == request.params.get('account_id'),
Vat.service_id == request.params.get('service_id'),
)
.first()
)
if (
vat
and str(vat.id) != request.params.get('id')
):
raise colander.Invalid(
node,
_(u'Vat for this date exists'),
)
return colander.All(validator,)
示例13: maintainer_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Invalid [as 别名]
def maintainer_validator(node, kw):
request = kw.get('request')
def validator(node, value):
employee = Employee.get(value)
if request.params.get('employee_id') == str(value):
raise colander.Invalid(
node,
_(u'Select another employee.')
)
if is_employee_currently_dismissed(employee):
raise colander.Invalid(
node,
_(u'Employee is dismissed.')
)
if not get_employee_position(employee):
raise colander.Invalid(
node,
_(u'Can\'t assign resources to employee without position.')
)
return validator
示例14: name_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Invalid [as 别名]
def name_validator(node, kw):
request = kw.get('request')
def validator(node, value):
region = (
DBSession.query(Region).filter(
Region.name == value,
Region.country_id == request.params.get('country_id')
).first()
)
if (
region
and str(region.id) != request.params.get('id')
):
raise colander.Invalid(
node,
_(u'Region already exists'),
)
return colander.All(colander.Length(max=128), validator,)
示例15: name_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Invalid [as 别名]
def name_validator(node, kw):
request = kw.get('request')
def validator(node, value):
resource_type = ResourceType.by_name(value)
if (
resource_type
and (
str(resource_type.id) != request.params.get('id')
or (
str(resource_type.id) == request.params.get('id')
and request.view_name == 'copy'
)
)
):
raise colander.Invalid(
node,
_(u'Resource Type with the same name exists'),
)
return colander.All(colander.Length(max=128), validator,)