mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
7c9c0d46aa
* fix toastedmarshmallow benchmarks and add marshmallow benchmarks * format benchmarks better * add runtime for netlify * remove sphinxcontrib-spelling==4.0.1 * remove docs linting * adding benchmarks section to docs
44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
from marshmallow import Schema, fields, validate
|
|
|
|
|
|
class TestMarshmallow:
|
|
package = 'marshmallow'
|
|
|
|
def __init__(self, allow_extra):
|
|
class LocationSchema(Schema):
|
|
latitude = fields.Float(allow_none=True)
|
|
longitude = fields.Float(allow_none=True)
|
|
|
|
class SkillSchema(Schema):
|
|
subject = fields.Str(required=True)
|
|
subject_id = fields.Integer(required=True)
|
|
category = fields.Str(required=True)
|
|
qual_level = fields.Str(required=True)
|
|
qual_level_id = fields.Integer(required=True)
|
|
qual_level_ranking = fields.Float(default=0)
|
|
|
|
class Model(Schema):
|
|
id = fields.Integer(required=True)
|
|
client_name = fields.Str(validate=validate.Length(max=255), required=True)
|
|
sort_index = fields.Float(required=True)
|
|
#client_email = fields.Email()
|
|
client_phone = fields.Str(validate=validate.Length(max=255), allow_none=True)
|
|
|
|
location = LocationSchema()
|
|
|
|
contractor = fields.Integer(validate=validate.Range(min=0), allow_none=True)
|
|
upstream_http_referrer = fields.Str(validate=validate.Length(max=1023), allow_none=True)
|
|
grecaptcha_response = fields.Str(validate=validate.Length(min=20, max=1000), required=True)
|
|
last_updated = fields.DateTime(allow_none=True)
|
|
skills = fields.Nested(SkillSchema(many=True))
|
|
|
|
self.allow_extra = allow_extra # unused
|
|
self.schema = Model()
|
|
|
|
def validate(self, data):
|
|
result = self.schema.load(data)
|
|
if result.errors:
|
|
return False, result.errors
|
|
else:
|
|
return True, result.data
|