How to use the colander.All function in colander

To help you get started, we’ve selected a few colander examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mazvv / travelcrm / travelcrm / forms / refunds.py View on Github external
)
        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,)
github mazvv / travelcrm / travelcrm / forms / countries.py View on Github external
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,)
github mazvv / travelcrm / travelcrm / forms / licence.py View on Github external
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)
github Kotti / Kotti / kotti / views / users.py View on Github external
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,
github mazvv / travelcrm / travelcrm / forms / locations.py View on Github external
)
        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,)
github ANCIR / grano / grano / logic / projects.py View on Github external
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)
github mazvv / travelcrm / travelcrm / forms / __init__.py View on Github external
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,)
github mazvv / travelcrm / travelcrm / forms / permisions.py View on Github external
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,)
github mazvv / travelcrm / travelcrm / forms / accounts.py View on Github external
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,)
github Cornices / cornice.ext.swagger / cornice_swagger / converters / schema.py View on Github external
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