Ejemplo n.º 1
0
def make_schema(cls, **kwargs):
    """
    Requires a class
    Returns a colander schema
    """
    schema = SchemaNode(Mapping())
    columns = make_columns(cls)
    map(lambda elem: columns.pop(elem), kwargs.get('excludes', []))
    # remove the id from the form
    columns.pop('id')
    if 'type' in columns.keys():
        columns.pop('type')
    if 'uuid' in columns.keys():
        columns.pop('uuid')
    for k, v in columns.iteritems():
        if isinstance(v, list):
            values = []
            for elem in v[1]:
                values.append((elem[1], elem[2]))
            schema.add(SchemaNode(
                String(),
                widget=widget.SelectWidget(values=values),
                name=k
                ))
        else:
            schema.add(SchemaNode(v(), name=k))
    return schema
Ejemplo n.º 2
0
    def test_invalid(self):
        from colander import Invalid, SchemaNode
        n = SchemaNode(JobQuery.File(), name='filefield')
        with self.assertRaises(Invalid) as e:
            n.deserialize(12345)

        self.assertDictEqual(e.exception.asdict(),
                             {'filefield': '12345 is not a cgi.FieldStorage'})
Ejemplo n.º 3
0
class ItemsValid(object):
    def __init__(self, field):
        fieldtype = field['type']
        nodetype = registry.validation(fieldtype, **field)
        self.schema = SchemaNode(Sequence(), nodetype)

    def __call__(self, node, value):
        self.schema.deserialize(value)
Ejemplo n.º 4
0
def users(request):
    db = request.db

    # Schema
    schema = SchemaNode(Mapping(),
                        SchemaNode(Integer(), name='id'))
    payload = schema.deserialize(request.json)

    users = User.by_params(db, **payload)
    return users
Ejemplo n.º 5
0
def user_by_key(request):
    db = request.db

    # Schema
    schema = SchemaNode(Mapping(),
                        SchemaNode(String(), name='key_key'))
    payload = schema.deserialize(request.json)

    key = Key.by_key_key(db, payload['key_key'])
    if key:
        return key.user
Ejemplo n.º 6
0
 def deserialize(self, cstruct=null):
     if cstruct:
         self.children = []
         self.add(SchemaNode(String(), name='title', missing=drop))
         self.add(SchemaNode(String(), name='description', missing=drop))
         roles = [key for key in six.iterkeys(cstruct)
                  if key not in ('title', 'description')]
         for key in roles:
             permSchema = SchemaNode(Mapping(unknown='raise'), name=key)
             for domain in ('definition', 'records', 'users', 'policy'):
                 permSchema.add(self._crudSchema(domain))
             self.add(permSchema)
     return super(PolicyValidator, self).deserialize(cstruct)
Ejemplo n.º 7
0
def apps_create(request):
    db = request.db

    schema = SchemaNode(Mapping(),
                        SchemaNode(String(), name='name'))
    payload = schema.deserialize(request.json)

    app = App(created=datetime.datetime.now(),
              name=payload['name'],
              user=request.user)
    db.add(app)

    db.flush()
    return app
Ejemplo n.º 8
0
def add_post_data_subschemas(node: SchemaNode, kw: dict):
    """Add the resource sheet colander schemas that are 'creatable'."""
    context = kw['context']
    request = kw['request']
    content_type = _get_resource_type_based_on_request_type(request)
    try:
        iresource = ContentType().deserialize(content_type)
    except colander.Invalid:
        return  # the content type is validated later, so we just ignore errors
    registry = request.registry.content
    creates = registry.get_sheets_create(context, request, iresource)
    for sheet in creates:
        name = sheet.meta.isheet.__identifier__
        is_mandatory = sheet.meta.create_mandatory
        missing = colander.required if is_mandatory else colander.drop
        schema = sheet.meta.schema_class(name=name, missing=missing)
        node.add(schema.bind(**kw))
Ejemplo n.º 9
0
 def definition(cls):
     schema = SchemaNode(Mapping())
     schema.add(SchemaNode(String(), name='name'))
     schema.add(SchemaNode(String(), name='description', missing=''))
     schema.add(SchemaNode(String(), name='type',
                           validator=OneOf(registry.names)))
     return schema
Ejemplo n.º 10
0
 def _crudSchema(self, domain):
     crudSchema = SchemaNode(Mapping(unknown='raise'),
                             name=domain, missing=drop)
     crudSchema.add(SchemaNode(Boolean(), name='create', missing=drop))
     crudSchema.add(SchemaNode(Boolean(), name='read', missing=drop))
     crudSchema.add(SchemaNode(Boolean(), name='update', missing=drop))
     crudSchema.add(SchemaNode(Boolean(), name='delete', missing=drop))
     return crudSchema
Ejemplo n.º 11
0
def keys_add(request):
    db = request.db

    schema = SchemaNode(Mapping(),
                        SchemaNode(String(), name='key_type'),
                        SchemaNode(String(), name='key_key'),
                        SchemaNode(String(), name='key_comment'))
    payload = schema.deserialize(request.json)

    key = Key.by_key_key(db, payload['key_key'])
    if not key:
        key = Key(created=datetime.datetime.now(),
                  key_type=payload['key_type'],
                  key_key=payload['key_key'],
                  key_comment=payload['key_comment'],
                  user=request.user)
        db.add(key)

    return key
Ejemplo n.º 12
0
class StatusSchema(MappingSchema):
    """Base status response schema"""
    status = SchemaNode(String(),
                        title=_("Response status"),
                        validator=OneOf(('success', 'error')))
Ejemplo n.º 13
0
 def definition(cls):
     schema = SchemaNode(Mapping())
     schema.add(SchemaNode(String(), name='name',
                           validator=Regex(r'^[a-zA-Z][a-zA-Z0-9_\-]*$')))
     schema.add(SchemaNode(String(), name='label', missing=u''))
     schema.add(SchemaNode(String(), name='hint', missing=cls.hint))
     schema.add(SchemaNode(Boolean(), name='required',
                           missing=cls.required))
     schema.add(SchemaNode(String(), name='type',
                           validator=OneOf(registry.names)))
     return schema
Ejemplo n.º 14
0
class ComicSchema(MappingSchema):
    title = SchemaNode(String(encoding='utf-8'), validator=Length(max=64))
Ejemplo n.º 15
0
    class DefaultSchema(MappingSchema):
        foo = SchemaNode(String(), type="str", location="querystring", missing="foo")
        bar = SchemaNode(String(), type="str", location="querystring", default="bar")

    class DefaultValueSchema(MappingSchema):
        foo = SchemaNode(Int(), type="int")
        bar = SchemaNode(Int(), type="int", missing=10)

    class QsSchema(MappingSchema):
        foo = SchemaNode(String(), type="str", location="querystring", missing=drop)

    class StrictQsSchema(StrictMappingSchema):
        foo = SchemaNode(String(), type="str", location="querystring", missing=drop)

    imperative_schema = SchemaNode(Mapping())
    imperative_schema.add(SchemaNode(String(), name="foo", type="str"))
    imperative_schema.add(SchemaNode(String(), name="bar", type="str", location="body"))
    imperative_schema.add(SchemaNode(String(), name="baz", type="str", location="querystring"))

    class TestingSchemaWithHeader(MappingSchema):
        foo = SchemaNode(String(), type="str")
        bar = SchemaNode(String(), type="str", location="body")
        baz = SchemaNode(String(), type="str", location="querystring")
        qux = SchemaNode(String(), type="str", location="header")

    class PreserveUnkownSchema(MappingSchema):
        bar = SchemaNode(String(), type="str")

        @staticmethod
        def schema_type():
Ejemplo n.º 16
0
class RunningAverageSchema(base_schema.ObjType):
    'Time series object schema'
    timeseries = TimeSeriesSchema(missing=drop)
    name = 'running average'
    past_hours_to_average = SchemaNode(Float(), missing=drop)
Ejemplo n.º 17
0
 class MySchema(MappingSchema):
     name = SchemaNode(String())
     title = SchemaNode(String())
     cool = SchemaNode(Boolean(), default=True, missing=True)
     series = SeriesSchema()
Ejemplo n.º 18
0
 class DatesSchema(SequenceSchema):
     date = SchemaNode(Date())
Ejemplo n.º 19
0
class ChemicalDispersionSchema(WeathererSchema):
    fraction_sprayed = SchemaNode(Float(), validator=Range(0, 1.0))
    efficiency = SchemaNode(Float(), missing=drop, validator=Range(0, 1.0))
Ejemplo n.º 20
0
class SkimmerSchema(WeathererSchema):
    amount = SchemaNode(Float())
    units = SchemaNode(String())
    efficiency = SchemaNode(Float())
Ejemplo n.º 21
0
class VariableSchema(VariableSchemaBase):
    varname = SchemaNode(
        String(), missing=drop, read_only=True
    )
Ejemplo n.º 22
0
class GridSchema(base_schema.ObjTypeSchema):
    name = SchemaNode(String(), test_equal=False) #remove this once gridded stops using _def_count
    filename = FilenameSchema(
        isdatafile=True, test_equal=False, update=False
    )
Ejemplo n.º 23
0
class MergeSchema(MappingSchema):
    source_document_id = SchemaNode(Integer(), missing=required)
    target_document_id = SchemaNode(Integer(), missing=required)
Ejemplo n.º 24
0
class HalfLifeWeathererSchema(WeathererSchema):
    half_lives = SchemaNode(NumpyArray())
Ejemplo n.º 25
0
class ClaimsSchema(ClaimsObjectSchema):
    """Token claims schema"""
    sub = SchemaNode(String(), title=_("Principal ID"))
    iat = SchemaNode(Int(), title=_("Token issue timestamp, in seconds"))
    exp = SchemaNode(Int(), title=_("Token expiration timestamp, in seconds"))
Ejemplo n.º 26
0
class ClaimsObjectSchema(MappingSchema):
    """Claims getter schema"""
    obj = SchemaNode(String(),
                     title=_("Token object"),
                     validator=OneOf((ACCESS_OBJECT, REFRESH_OBJECT)),
                     missing=drop)
Ejemplo n.º 27
0
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)
    name = 'windage_range'
Ejemplo n.º 28
0
class SourceSchema(MappingSchema):
    url = SchemaNode(String(), validator=colander.url)
    active = SchemaNode(Boolean(), missing=False)
Ejemplo n.º 29
0
 class SeriesSchema(MappingSchema):
     name = SchemaNode(String())
     dates = DatesSchema()
Ejemplo n.º 30
0
class MediaSchema(MappingSchema):
    license = default_schema_node()
    url = SchemaNode(String(), validator=colander.url)
Ejemplo n.º 31
0
class UVTuple(DefaultTupleSchema):
    'Tide object schema'
    u = SchemaNode(Float())
    v = SchemaNode(Float())
Ejemplo n.º 32
0
class EventSchema(MappingSchema):
    id = SchemaNode(String(),
                    missing=drop,
                    validator=Length(1, SAFE_MAX_LENGTH))
    provider_id = default_schema_node()
    title = SchemaNode(String(),
                       missing='',
                       validator=Length(1, SAFE_MAX_LENGTH))
    email = SchemaNode(String(), validator=colander.Email())
    firstname = default_schema_node()
    lastname = default_schema_node()
    telephone = default_schema_node()
    description = SchemaNode(String(), missing='')
    event_id = default_schema_node()
    email = SchemaNode(String(), missing='', validator=colander.Email())
    firstname = default_schema_node()
    language = default_schema_node()
    lastname = default_schema_node()
    latlong = default_schema_node()
    price_information = default_schema_node()
    organiser = default_schema_node()
    performers = default_schema_node()
    press_url = SchemaNode(String(), missing='', validator=colander.url)
    source_id = default_schema_node()
    source = default_schema_node()
    target = default_schema_node()
    telephone = default_schema_node()
    url = SchemaNode(String(), missing='', validator=colander.url)

    location_name = default_schema_node()
    location_address = default_schema_node()
    location_post_code = default_schema_node()
    location_town = default_schema_node()
    location_capacity = default_schema_node()
    location_country = default_schema_node()

    start_time = SchemaNode(DateTime(default_tzinfo=None),
                            preparer=remove_timezone)
    end_time = SchemaNode(DateTime(default_tzinfo=None),
                          missing=None,
                          preparer=remove_timezone)
    publication_start = SchemaNode(DateTime(default_tzinfo=None),
                                   missing=None,
                                   preparer=remove_timezone)
    publication_end = SchemaNode(DateTime(default_tzinfo=None),
                                 missing=None,
                                 preparer=remove_timezone)

    press_contact_email = SchemaNode(String(),
                                     missing='',
                                     validator=colander.Email())
    press_contact_name = default_schema_node()
    press_contact_phone_number = default_schema_node()
    ticket_contact_email = SchemaNode(String(),
                                      missing='',
                                      validator=colander.Email())
    ticket_contact_name = default_schema_node()
    ticket_contact_phone_number = default_schema_node()

    @instantiate(missing=[])
    class videos(SequenceSchema):
        video = MediaSchema()

    @instantiate(missing=[])
    class sounds(SequenceSchema):
        sound = MediaSchema()

    @instantiate(missing=[])
    class images(SequenceSchema):
        image = MediaSchema()

    @instantiate(missing=[])
    class tags(SequenceSchema):
        name = SchemaNode(String(), validator=Length(1, TAG_MAX_LENGTH))

    @instantiate(missing=[])
    class categories(SequenceSchema):
        name = SchemaNode(String(), validator=Length(1, TAG_MAX_LENGTH))
Ejemplo n.º 33
0
from deform import widget
from deform.widget import MappingWidget, SequenceWidget

registry = widget.default_resource_registry
registry.set_js_resources(
    "magicsuggest", None,
    "c2cgeoportal_admin:node_modules/magicsuggest-alpine/magicsuggest-min.js")
registry.set_css_resources(
    "magicsuggest", None,
    "c2cgeoportal_admin:node_modules/magicsuggest-alpine/magicsuggest-min.css")

# temporary workaround for https://github.com/Pylons/deform/pull/369
widget.DateTimeInputWidget._pstruct_schema = SchemaNode(  # pylint: disable=protected-access
    Mapping(),
    SchemaNode(widget._StrippedString(), name="date"),  # pylint: disable=protected-access
    SchemaNode(widget._StrippedString(), name="time"),  # pylint: disable=protected-access
    SchemaNode(widget._StrippedString(), name="date_submit", missing=""),  # pylint: disable=protected-access
    SchemaNode(widget._StrippedString(), name="time_submit", missing=""),  # pylint: disable=protected-access
)


class ChildWidget(MappingWidget):

    template = "child"

    def serialize(self, field, cstruct, **kw):
        from c2cgeoportal_commons.models.main import TreeItem  # pylint: disable=import-outside-toplevel

        if cstruct["treeitem_id"] == colander.null:
            kw["treeitem"] = TreeItem()
        else:
Ejemplo n.º 34
0
def default_schema_node():
    return SchemaNode(String(),
                      missing='',
                      validator=Length(1, SAFE_MAX_LENGTH))
Ejemplo n.º 35
0
class Person(SequenceSchema):
    person = SchemaNode(
        String(),
        widget=ExtendedAutocompleteInputWidget(
            display_value=lambda field, person_id: PERSONS.get(person_id, ''),
            values='/ajax_search'))
Ejemplo n.º 36
0
 def __init__(self, field):
     fieldtype = field['type']
     nodetype = registry.validation(fieldtype, **field)
     self.schema = SchemaNode(Sequence(), nodetype)
Ejemplo n.º 37
0
    def definition(cls, **kwargs):
        schema = SchemaNode(Mapping(unknown="preserve"))

        schema.add(SchemaNode(String(), name="label", missing=u""))
        schema.add(SchemaNode(String(), name="type", validator=OneOf(["annotation"])))
        return schema
Ejemplo n.º 38
0
def _add_node(schema: SchemaNode, node: SchemaNode, name: str):
    node = node.bind(**schema.bindings)
    node.name = name
    schema.add(node)
Ejemplo n.º 39
0
    def definition(cls, **kwargs):
        schema = SchemaNode(Mapping(unknown="preserve"))

        if kwargs.get('named', True):
            schema.add(SchemaNode(String(), name='name',
                       validator=Regex(r'^[a-zA-Z][a-zA-Z0-9_\-]*$')))

        schema.add(SchemaNode(String(), name='label', missing=u''))
        schema.add(SchemaNode(String(), name='hint', missing=cls.hint))
        schema.add(SchemaNode(Boolean(), name='required',
                              missing=cls.required))
        schema.add(SchemaNode(String(), name='type',
                              validator=OneOf(registry.names)))
        return schema
Ejemplo n.º 40
0
class LoginSchema(ClaimsSetterSchema):
    """Login schema"""
    login = SchemaNode(String(), title=_("Login"))
    password = SchemaNode(String(), title=_("Password"))
Ejemplo n.º 41
0
 def _bind(self, schema: colander.SchemaNode) -> colander.SchemaNode:
     return schema.bind(context=self.context)
Ejemplo n.º 42
0
class TokensSchema(StatusSchema):
    """Tokens response schema"""
    accessToken = SchemaNode(String(), title=_("Access token"))
    refreshToken = SchemaNode(String(), title=_("Refresh token"))
Ejemplo n.º 43
0
class ErrorSchema(MappingSchema):
    """Base error schema"""
    status = SchemaNode(String(), title=_("Response status"))
    message = SchemaNode(String(), title=_("Error message"), missing=drop)
Ejemplo n.º 44
0
class DeviceIdsSchema(SequenceSchema):
    device_id = SchemaNode(String())
Ejemplo n.º 45
0
 class tags(SequenceSchema):
     name = SchemaNode(String(), validator=Length(1, TAG_MAX_LENGTH))
Ejemplo n.º 46
0
class ClaimsSetterSchema(MappingSchema):
    """Claims setter schema"""
    claims = SchemaNode(PropertiesMapping(),
                        title=_("Custom claims"),
                        missing=drop)
Ejemplo n.º 47
0
        bar = SchemaNode(String(), type='str')

    class StrictMappingSchema(MappingSchema):
        @staticmethod
        def schema_type():
            return MappingSchema.schema_type(unknown='raise')

    class StrictSchema(StrictMappingSchema):
        foo = SchemaNode(String(), type='str', location="body", missing=drop)
        bar = SchemaNode(String(), type='str', location="body")

    class NestedSchema(MappingSchema):
        egg = StrictSchema(location='querystring')
        ham = StrictSchema(location='body')

    imperative_schema = SchemaNode(Mapping())
    imperative_schema.add(SchemaNode(String(), name='foo', type='str'))
    imperative_schema.add(SchemaNode(String(), name='bar', type='str',
                          location="body"))
    imperative_schema.add(SchemaNode(String(), name='baz', type='str',
                          location="querystring"))

    class TestingSchemaWithHeader(MappingSchema):
        foo = SchemaNode(String(), type='str')
        bar = SchemaNode(String(), type='str', location="body")
        baz = SchemaNode(String(), type='str', location="querystring")
        qux = SchemaNode(String(), type='str', location="header")

    class MockRequest(object):
        def __init__(self, body, get=None):
            self.content_type = 'application/json'
Ejemplo n.º 48
0
class HalfLifeWeathererSchema(WeathererSchema):
    half_lives = SchemaNode(NumpyArray(), save=True, update=True)
Ejemplo n.º 49
0
 def _bind(self, schema: colander.SchemaNode) -> colander.SchemaNode:
     return schema.bind(request=self.request)
Ejemplo n.º 50
0
class GeoSubmitSchema(MappingSchema):
    # The first portion of the GeoSubmitSchema is identical to the
    # Gelocate schema with the exception that the radioType validator
    # can accept one more radioType (lte)
    homeMobileCountryCode = SchemaNode(
        Integer(), missing=-1)
    homeMobileNetworkCode = SchemaNode(
        Integer(), missing=-1)

    # mapped to 'radio' for submit
    radioType = SchemaNode(String(),
                           validator=OneOf(GEOSUBMIT_RADIO_TYPE_KEYS),
                           missing='')
    carrier = SchemaNode(String(), missing='')
    cellTowers = CellTowersSchema(missing=())
    wifiAccessPoints = WifiAccessPointsSchema(missing=())

    # The fields below are extra fields which are not part of the
    # geolocate API, but are part of the submit schema

    # mapped to 'lat' for submit
    latitude = SchemaNode(Float(), missing=-255)

    # mapped to 'lon' for submit
    longitude = SchemaNode(Float(), missing=-255)

    # parsed and mapped to 'time' for submit
    timestamp = SchemaNode(Integer(), missing=0)

    # mapped to 'accuracy' for submit
    accuracy = SchemaNode(Float(), missing=0)

    # mapped to 'altitude' for submit
    altitude = SchemaNode(Float(), missing=0)

    # mapped to 'altitude_accuracy' for submit
    altitudeAccuracy = SchemaNode(Float(), missing=0)
    # radio is taken from radioType
    # cell is taken from cellTowers
    # wifi is taken from wifiAccessPoints

    heading = SchemaNode(Float(), missing=-1.0)
    speed = SchemaNode(Float(), missing=-1.0)