How to use the colander.Length 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 Pylons / colander / colander / tests.py View on Github external
def _makeOne(self, min=None, max=None):
        from colander import Length
        return Length(min=min, max=max)
github mazvv / travelcrm / travelcrm / forms / spassports.py View on Github external
)
    docs_receive_date = colander.SchemaNode(
        Date(),
        missing=None,
    )
    docs_transfer_date = colander.SchemaNode(
        Date(),
        missing=None,
    )
    passport_receive_date = colander.SchemaNode(
        Date(),
        missing=None,
    )
    descr = colander.SchemaNode(
        colander.String(),
        validator=colander.Length(max=255),
        missing=None
    )


class SpassportForm(OrderItemForm):
    _schema = _SpassportSchema

    def submit(self, spassport=None):
        order_item = super(SpassportForm, self).submit(spassport and spassport.order_item)
        if not spassport:
            spassport = Spassport(
                resource=SpassportsResource.create_resource(
                    get_auth_employee(self.request)
                )
            )
        spassport.order_item = order_item
github ANCIR / grano / grano / logic / properties.py View on Github external
def validate_name(project, obj):
    """ Make sure that an entity's `name` attribute is unique
    within the scope of the project. """
    def check(name):
        entity = Entity.by_name(project, name)
        if entity is not None:
            if obj is None or obj.id != entity.id:
                return False
        return True
    name_unique = colander.Function(check,
                                    message="An entity with this name exists")
    return colander.All(name_unique, colander.Length(min=1))
github mazvv / travelcrm / travelcrm / forms / invoices.py View on Github external
SelectInteger(Order),
        validator=order_id_validator
    )
    account_id = colander.SchemaNode(
        SelectInteger(Account),
    )
    date = colander.SchemaNode(
        Date(),
    )
    active_until = colander.SchemaNode(
        Date(),
        validator=valid_until_validator
    )
    descr = colander.SchemaNode(
        colander.String(),
        validator=colander.Length(max=255),
        missing=None
    )


class _InvoiceSearchSchema(ResourceSearchSchema):
    currency_id = colander.SchemaNode(
        colander.Integer(),
        missing=None,
    )
    sum_from = colander.SchemaNode(
        colander.Money(),
        missing=None,
    )
    sum_to = colander.SchemaNode(
        colander.Money(),
        missing=None,
github mazvv / travelcrm / travelcrm / forms / tickets.py View on Github external
)
    ticket_class_id = colander.SchemaNode(
        SelectInteger(TicketClass),
    )
    transport_id = colander.SchemaNode(
        SelectInteger(Transport),
    )
    start_additional_info = colander.SchemaNode(
        colander.String(),
        missing=None,
        validator=colander.Length(max=128),
    )
    end_additional_info = colander.SchemaNode(
        colander.String(),
        missing=None,
        validator=colander.Length(max=128),
    )
    start_dt = colander.SchemaNode(
        DateTime()
    )
    end_dt = colander.SchemaNode(
        DateTime()
    )
    descr = colander.SchemaNode(
        colander.String(),
        validator=colander.Length(max=255),
        missing=None
    )


class TicketForm(OrderItemForm):
    _schema = _TicketSchema
github mazvv / travelcrm / travelcrm / forms / positions.py View on Github external
)
        if (
            position
            and (
                str(position.id) != request.params.get('id')
                or (
                    str(position.id) == request.params.get('id')
                    and request.view_name == 'copy'
                )
            )
        ):
            raise colander.Invalid(
                node,
                _(u'Position with the same name for structure exists'),
            )
    return colander.All(colander.Length(max=128), validator,)
github mazvv / travelcrm / travelcrm / forms / mails.py View on Github external
def name_validator(node, kw):
    request = kw.get('request')

    def validator(node, value):
        mail = Mail.by_name(value)
        if (
            mail
            and str(mail.id) != request.params.get('id')
        ):
            raise colander.Invalid(
                node,
                _(u'Mail with the same name exists'),
            )
    return colander.All(colander.Length(max=255), validator,)
github nandoflorestan / bag / bag / web / deform / __init__.py View on Github external
typ='input', placeholder=None, validators=None):
    '''Use this to easily create well-sized inputs.

    Returns a dict containing *widget* and *validator*,
    all concerned about length.

    If the parameter *max* is not an integer, it is treated as a model property
    from which the real *max* can be inferred.
    '''
    if not isinstance(max, int):
        max = length(max)
    if not size:
        size = max if max <= 35 else 35 + (max - 35) / 4
    if size > 60:
        size = 60
    validator = c.Length(min=min, max=max)
    if validators:
        validator = c.All(validator, *validators)
    return dict(widget=widget_cls(size=size, maxlength=max,
        placeholder=placeholder, typ=typ), validator=validator)
github mazvv / travelcrm / travelcrm / forms / orders_items.py View on Github external
missing=0,
    )
    person_id = colander.SchemaNode(
        colander.Set(),
    )
    status = colander.SchemaNode(
        colander.String(),
    )
    status_date = colander.SchemaNode(
        Date(),
        missing=None
    )
    status_info = colander.SchemaNode(
        colander.String(),
        missing=None,
        validator=colander.Length(max=128)
    )

    def deserialize(self, cstruct):
        if (
            'person_id' in cstruct
            and not isinstance(cstruct.get('person_id'), list)
        ):
            val = cstruct['person_id']
            cstruct['person_id'] = list()
            cstruct['person_id'].append(val)

        return super(OrderItemSchema, self).deserialize(cstruct)


class OrderItemForm(BaseForm):
    _schema = OrderItemSchema
github mazvv / travelcrm / travelcrm / forms / leads.py View on Github external
advsource_id = colander.SchemaNode(
        SelectInteger(Advsource),
    )
    status = colander.SchemaNode(
        colander.String(),
    )
    lead_offer_id = colander.SchemaNode(
        colander.Set(),
        missing=[]
    )
    lead_item_id = colander.SchemaNode(
        colander.Set(),
    )
    descr = colander.SchemaNode(
        colander.String(),
        validator=colander.Length(max=255),
        missing=None
    )

    def deserialize(self, cstruct):
        if (
            'lead_item_id' in cstruct
            and not isinstance(cstruct.get('lead_item_id'), list)
        ):
            val = cstruct['lead_item_id']
            cstruct['lead_item_id'] = list()
            cstruct['lead_item_id'].append(val)

        if (
            'lead_offer_id' in cstruct
            and not isinstance(cstruct.get('lead_offer_id'), list)
        ):