示例#1
0
    def literal_data(self, data_input):
        node = colander.SchemaNode(
            self.colander_literal_type(data_input),
            name=data_input.identifier,
            title=data_input.title,
            validator=TextValidator(),
        )

        # sometimes abstract is not set
        node.description = getattr(data_input, 'abstract', '')
        # optional value?
        if data_input.minOccurs == 0:
            node.missing = colander.drop
        # TODO: fix init of default
        if hasattr(data_input, 'defaultValue') \
           and data_input.defaultValue is not None:
            if type(node.typ) in (colander.DateTime, colander.Date,
                                  colander.Time):
                node.default = dateutil.parser.parse(data_input.defaultValue)
            elif type(node.typ) == colander.Boolean:
                # TODO: boolean default does not work ...
                node.default = bool(data_input.defaultValue == 'True')
            else:
                node.default = data_input.defaultValue
        self.colander_literal_widget(node, data_input)

        ## Find ranges and use new validator
        if node.name == "elevationOut":
            LOGGER.debug("Looking at the elevationOut node")
            LOGGER.debug("%s" % (node))
            node.validator = RangeValidator()

        # Use validators for longitude and latitude
        if node.name == "latitude":
            node.validator = LatitudeValidator()
        if node.name == "longitude":
            node.validator = LongitudeValidator()
        if node.name == "lon_bounds":
            node.validator = LongitudeBoundaryValidator()
        if node.name == "lat_bounds":
            node.validator = LatitudeBoundaryValidator()
        if node.name == "scale":
            node.validator = TupleFloatValidator()

        # sequence of nodes ...
        if data_input.maxOccurs > 1:
            node = colander.SchemaNode(
                colander.Sequence(),
                node,
                name=data_input.identifier,
                title=data_input.title,
                validator=colander.Length(max=data_input.maxOccurs))

        return node
示例#2
0
    def literal_data(self, data_input):
        node = colander.SchemaNode(
            self.colander_literal_type(data_input),
            name=data_input.identifier,
            title=data_input.title,
            validator=TextValidator(),
        )

        # sometimes abstract is not set
        node.description = getattr(data_input, 'abstract', '')
        # optional value?
        if data_input.minOccurs == 0:
            node.missing = colander.drop
        # TODO: fix init of default
        if hasattr(data_input, 'defaultValue') \
           and data_input.defaultValue is not None:
            if type(node.typ) in (colander.DateTime, colander.Date,
                                  colander.Time):
                node.default = dateutil.parser.parse(data_input.defaultValue)
            elif type(node.typ) == colander.Boolean:
                # TODO: boolean default does not work ...
                node.default = bool(data_input.defaultValue == 'True')
            else:
                node.default = data_input.defaultValue
        self.colander_literal_widget(node, data_input)

        # sequence of nodes ...
        # do not use if we are using a SelectWidget with multiple=True for strings
        if data_input.maxOccurs > 1 and 'string' not in data_input.dataType:
            node = colander.SchemaNode(
                colander.Sequence(),
                node,
                name=data_input.identifier,
                title=data_input.title,
                validator=colander.Length(max=data_input.maxOccurs))

        return node
示例#3
0
 def test_restricted_chars(self):
     validator = TextValidator()
     e = invalid_exc(validator, None, "Hello World!")
     self.assertEqual(e.msg, 'Invalid value ... containts restricted characters.')
示例#4
0
 def test_empty(self):
     validator = TextValidator()
     e = invalid_exc(validator, None, "   ")
     self.assertEqual(e.msg, 'Invalid value ... empty.')
示例#5
0
 def test_default(self):
     validator = TextValidator()
     self.assertEqual(validator(None, "hello world"), None)