2016-01-11 15:07:13 +00:00
|
|
|
from . import ma
|
2016-01-08 17:51:46 +00:00
|
|
|
from . import models
|
|
|
|
|
|
2016-01-11 15:07:13 +00:00
|
|
|
# TODO I think marshmallow provides a better integration and error handling.
|
|
|
|
|
# Would be better to replace functionality in dao with the marshmallow supported
|
|
|
|
|
# functionality.
|
|
|
|
|
# http://marshmallow.readthedocs.org/en/latest/api_reference.html
|
2016-01-08 17:51:46 +00:00
|
|
|
|
2016-01-11 15:07:13 +00:00
|
|
|
|
|
|
|
|
class UserSchema(ma.ModelSchema):
|
2016-01-08 17:51:46 +00:00
|
|
|
class Meta:
|
|
|
|
|
model = models.User
|
2016-01-21 17:29:24 +00:00
|
|
|
exclude = (
|
|
|
|
|
"updated_at", "created_at", "user_to_service",
|
|
|
|
|
"_password", "verify_codes")
|
2016-01-11 15:07:13 +00:00
|
|
|
|
2016-01-08 17:51:46 +00:00
|
|
|
|
|
|
|
|
# TODO process users list, to return a list of user.id
|
2016-01-11 15:07:13 +00:00
|
|
|
# Should that list be restricted by the auth parsed??
|
|
|
|
|
class ServiceSchema(ma.ModelSchema):
|
2016-01-08 17:51:46 +00:00
|
|
|
class Meta:
|
|
|
|
|
model = models.Service
|
2016-01-19 13:11:22 +00:00
|
|
|
exclude = ("updated_at", "created_at", "api_keys", "templates", "jobs")
|
2016-01-13 11:04:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class TemplateSchema(ma.ModelSchema):
|
|
|
|
|
class Meta:
|
|
|
|
|
model = models.Template
|
2016-01-15 15:48:05 +00:00
|
|
|
exclude = ("updated_at", "created_at", "service_id", "jobs")
|
2016-01-11 15:07:13 +00:00
|
|
|
|
2016-01-08 17:51:46 +00:00
|
|
|
|
2016-01-19 12:07:00 +00:00
|
|
|
class ApiKeySchema(ma.ModelSchema):
|
2016-01-13 09:25:46 +00:00
|
|
|
class Meta:
|
2016-01-19 12:07:00 +00:00
|
|
|
model = models.ApiKey
|
2016-01-20 15:23:32 +00:00
|
|
|
exclude = ("service", "secret")
|
2016-01-14 11:30:45 +00:00
|
|
|
|
2016-01-13 09:25:46 +00:00
|
|
|
|
2016-01-15 15:48:05 +00:00
|
|
|
class JobSchema(ma.ModelSchema):
|
|
|
|
|
class Meta:
|
|
|
|
|
model = models.Job
|
|
|
|
|
|
|
|
|
|
|
2016-01-21 17:29:24 +00:00
|
|
|
class VerifyCodeSchema(ma.ModelSchema):
|
|
|
|
|
class Meta:
|
|
|
|
|
model = models.VerifyCode
|
|
|
|
|
exclude = ('user', "_code", "expiry_datetime", "code_used", "created_at")
|
|
|
|
|
|
|
|
|
|
|
2016-01-11 15:07:13 +00:00
|
|
|
user_schema = UserSchema()
|
2016-01-08 17:51:46 +00:00
|
|
|
users_schema = UserSchema(many=True)
|
|
|
|
|
service_schema = ServiceSchema()
|
|
|
|
|
services_schema = ServiceSchema(many=True)
|
2016-01-13 11:04:13 +00:00
|
|
|
template_schema = TemplateSchema()
|
|
|
|
|
templates_schema = TemplateSchema(many=True)
|
2016-01-19 12:07:00 +00:00
|
|
|
api_key_schema = ApiKeySchema()
|
|
|
|
|
api_keys_schema = ApiKeySchema(many=True)
|
2016-01-15 15:48:05 +00:00
|
|
|
job_schema = JobSchema()
|
|
|
|
|
jobs_schema = JobSchema(many=True)
|
2016-01-21 17:29:24 +00:00
|
|
|
verify_code_schema = VerifyCodeSchema()
|