How to use the colander.Float 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 stefanofontanelli / ColanderAlchemy / tests / test_schema.py View on Github external
def test_doc_example_Configuring_within_SQLAlchemy(self):
        """
        Test 'Configuring within SQLAlchemy models' example
        found in docs/source/customization.rst
        """

        Base = declarative_base()

        class Person(Base):
            __tablename__ = 'person'
            # Fully customised schema node
            id = Column(sqlalchemy.Integer,
                        primary_key=True,
                        info={'colanderalchemy': {
                            'typ': colander.Float(),
                            'title': 'Person ID',
                            'description': 'The Person identifier.',
                            'widget': 'Empty Widget'
                        }})
            # Explicitly set as a default field
            name = Column(sqlalchemy.Unicode(128),
                          nullable=False,
                          info={'colanderalchemy': {
                              'default': colander.required
                          }})
            # Explicitly excluded from resulting schema
            surname = Column(sqlalchemy.Unicode(128),
                             nullable=False,
                             info={'colanderalchemy': {'exclude': True}})

        schema = SQLAlchemySchemaNode(Person)
github NOAA-ORR-ERD / PyGnome / py_gnome / gnome / weatherers / roc.py View on Github external
def __init__(self, *args, **kwargs):
        for k in Platform._attr.keys():
            self.add(SchemaNode(Float(), missing=drop, name=k, save=True,
                                update=True))

        units = PlatformUnitsSchema(save=True, update=True)
        units.missing = drop
        units.name = 'units'

        self.add(units)
        self.add(SchemaNode(String(), name="type", missing=drop, save=True,
                            update=True))

        super(PlatformSchema, self).__init__()
github stefanofontanelli / ColanderAlchemy / colanderalchemy / schema.py View on Github external
elif isinstance(column_type, Boolean):
            type_ = colander.Boolean()

        elif isinstance(column_type, Date):
            type_ = colander.Date()

        elif isinstance(column_type, DateTime):
            type_ = colander.DateTime(default_tzinfo=None)

        elif isinstance(column_type, Enum):
            type_ = colander.String()
            kwargs["validator"] = colander.OneOf(column.type.enums)

        elif isinstance(column_type, Float):
            type_ = colander.Float()

        elif isinstance(column_type, Integer):
            type_ = colander.Integer()

        elif isinstance(column_type, String):
            type_ = colander.String()
            kwargs["validator"] = colander.Length(0, column.type.length)

        elif isinstance(column_type, Numeric):
            type_ = colander.Decimal()

        elif isinstance(column_type, Time):
            type_ = colander.Time()

        else:
            raise NotImplementedError(
github NLeSC / MAGMa / web / magmaweb / job.py View on Github external
def _addAnnotateSchema(self, schema):
        schema.add(colander.SchemaNode(colander.Float(), name='precursor_mz_precision'))
        schema.add(colander.SchemaNode(colander.Float(), name='mz_precision'))
        schema.add(colander.SchemaNode(colander.Float(), name='ms_intensity_cutoff'))
        schema.add(colander.SchemaNode(colander.Float(), name='msms_intensity_cutoff'))
        schema.add(colander.SchemaNode(
                                       colander.Integer(),
                                       validator=colander.OneOf([-1, 1]),
                                       name='ionisation_mode'
                                       ))
        schema.add(colander.SchemaNode(colander.Integer(),
                                       validator=colander.Range(min=0),
                                       name='max_broken_bonds'))
        schema.add(colander.SchemaNode(colander.Boolean(), default=False, missing=False, name='use_all_peaks'))
        schema.add(colander.SchemaNode(colander.Boolean(), default=False, missing=False, name='skip_fragmentation'))
github NOAA-ORR-ERD / PyGnome / py_gnome / gnome / spill / elements / initializers.py View on Github external
# set_newparticle_values()
        self.array_types = set()
        super(InitBaseClass, self).__init__(*args,**kwargs)

    def initialize(self, num_new_particles, spill, data_arrays, substance):
        """
        all classes that derive from Base class must implement initialize
        method
        """
        pass


class WindageSchema(TupleSchema):
    min_windage = SchemaNode(Float(), validator=Range(0, 1.0),
                             default=0.01)
    max_windage = SchemaNode(Float(), validator=Range(0, 1.0),
                             default=0.04)


class InitWindagesSchema(base_schema.ObjTypeSchema):
    """
    windages initializer values
    """
    windage_range = WindageSchema(
        save=True, update=True,
    )
    windage_persist = SchemaNode(
        Int(), default=900, save=True, update=True,
    )


class InitWindages(InitBaseClass):
github biteup / snakebite / snakebite / controllers / schema / rating.py View on Github external
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import colander


class MenuRatingSchema(colander.MappingSchema):
    user_id = colander.SchemaNode(colander.String())
    rating = colander.SchemaNode(colander.Float(), validator=colander.Range(min=0.0, max=5.0), missing=1)
github stefanofontanelli / ColanderAlchemy / colanderalchemy / types.py View on Github external
type_ = params.pop('type')

        elif isinstance(column_type, sqlalchemy.types.Boolean):
            type_ = colander.Boolean()

        elif isinstance(column_type, sqlalchemy.types.Date):
            type_ = colander.Date()

        elif isinstance(column_type, sqlalchemy.types.DateTime):
            type_ = colander.DateTime()

        elif isinstance(column_type, sqlalchemy.types.Enum):
            type_ = colander.String()

        elif isinstance(column_type, sqlalchemy.types.Float):
            type_ = colander.Float()

        elif isinstance(column_type, sqlalchemy.types.Integer):
            type_ = colander.Integer()

        elif isinstance(column_type, sqlalchemy.types.String):
            type_ = colander.String()

        elif isinstance(column_type, sqlalchemy.types.Numeric):
            type_ = colander.Decimal()

        elif isinstance(column_type, sqlalchemy.types.Time):
            type_ = colander.Time()

        else:
            raise NotImplementedError('Unknown type: %s' % column.type)
github wujian16 / Cornell-MOE / moe / views / schemas.py View on Github external
.. Note:: Passing ``typ`` or setting ``schema_type`` in subclasses will ***override*** this!

        This solution follows: https://github.com/Pylons/colander/issues/116

        .. Note:: colander's default behavior is ``unknown='ignore'``; the other option
          is ``'preserve'``. See: http://colander.readthedocs.org/en/latest/api.html#colander.Mapping

        """
        return colander.Mapping(unknown='raise')


class PositiveFloat(colander.SchemaNode):

    """Colander positive (finite) float."""

    schema_type = colander.Float
    title = 'Positive Float'

    def validator(self, node, cstruct):
        """Raise an exception if the node value (cstruct) is non-positive or non-finite.

        :param node: the node being validated (usually self)
        :type node: colander.SchemaNode subclass instance
        :param cstruct: the value being validated
        :type cstruct: float
        :raise: colander.Invalid if cstruct value is bad

        """
        if not 0.0 < cstruct < float('inf'):
            raise colander.Invalid(node, msg='Value = {0:f} must be positive and finite.'.format(cstruct))
github NLeSC / MAGMa / web / magmaweb / jobquery.py View on Github external
msdata_stringSchema = colander.SchemaNode(colander.String(),
                                                  validator=filled,
                                                  missing=colander.null,
                                                  name='ms_data')
        schema.add(msdata_stringSchema)

        msdata_fileSchema = colander.SchemaNode(self.File(),
                                                missing=colander.null,
                                                name='ms_data_file')
        schema.add(msdata_fileSchema)

        schema.add(colander.SchemaNode(colander.Integer(),
                                       missing=0,
                                       validator=colander.Range(min=0),
                                       name='max_ms_level'))
        schema.add(colander.SchemaNode(colander.Float(),
                                       missing=0.0,
                                       validator=colander.Range(min=0),
                                       name='abs_peak_cutoff'))
        schema.add(colander.SchemaNode(colander.Integer(),
                                       missing=colander.null,
                                       validator=colander.Range(min=0),
                                       name='scan'))
        schema.add(colander.SchemaNode(colander.Integer(),
                                       missing=1,
                                       validator=colander.OneOf([-1, 1]),
                                       name='ionisation_mode'))
        schema.add(colander.SchemaNode(colander.Float(),
                                       missing=0.0,
                                       validator=colander.Range(0, 1),
                                       name='precursor_mz_precision'))
        schema.add(colander.SchemaNode(colander.Float(),