mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
fix schema metaclasses
marshmallow v0.22.0 added load_instance and include_relationship options, which we need to keep old ModelSchema code working
This commit is contained in:
@@ -76,6 +76,10 @@ class UUIDsAsStringsMixin:
|
|||||||
|
|
||||||
class BaseSchema(ma.SQLAlchemyAutoSchema):
|
class BaseSchema(ma.SQLAlchemyAutoSchema):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
load_instance = True
|
||||||
|
include_relationships = True
|
||||||
|
|
||||||
def __init__(self, load_json=False, *args, **kwargs):
|
def __init__(self, load_json=False, *args, **kwargs):
|
||||||
self.load_json = load_json
|
self.load_json = load_json
|
||||||
super(BaseSchema, self).__init__(*args, **kwargs)
|
super(BaseSchema, self).__init__(*args, **kwargs)
|
||||||
@@ -108,7 +112,7 @@ class UserSchema(BaseSchema):
|
|||||||
retval[service_id].append(x.permission)
|
retval[service_id].append(x.permission)
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
class Meta:
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.User
|
model = models.User
|
||||||
exclude = (
|
exclude = (
|
||||||
"updated_at",
|
"updated_at",
|
||||||
@@ -145,7 +149,7 @@ class UserSchema(BaseSchema):
|
|||||||
class UserUpdateAttributeSchema(BaseSchema):
|
class UserUpdateAttributeSchema(BaseSchema):
|
||||||
auth_type = field_for(models.User, 'auth_type')
|
auth_type = field_for(models.User, 'auth_type')
|
||||||
|
|
||||||
class Meta:
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.User
|
model = models.User
|
||||||
exclude = (
|
exclude = (
|
||||||
'id', 'updated_at', 'created_at', 'user_to_service',
|
'id', 'updated_at', 'created_at', 'user_to_service',
|
||||||
@@ -182,7 +186,7 @@ class UserUpdateAttributeSchema(BaseSchema):
|
|||||||
|
|
||||||
class UserUpdatePasswordSchema(BaseSchema):
|
class UserUpdatePasswordSchema(BaseSchema):
|
||||||
|
|
||||||
class Meta:
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.User
|
model = models.User
|
||||||
only = ('password')
|
only = ('password')
|
||||||
strict = True
|
strict = True
|
||||||
@@ -197,7 +201,7 @@ class UserUpdatePasswordSchema(BaseSchema):
|
|||||||
class ProviderDetailsSchema(BaseSchema):
|
class ProviderDetailsSchema(BaseSchema):
|
||||||
created_by = fields.Nested(UserSchema, only=['id', 'name', 'email_address'], dump_only=True)
|
created_by = fields.Nested(UserSchema, only=['id', 'name', 'email_address'], dump_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.ProviderDetails
|
model = models.ProviderDetails
|
||||||
exclude = ("provider_rates", "provider_stats")
|
exclude = ("provider_rates", "provider_stats")
|
||||||
strict = True
|
strict = True
|
||||||
@@ -206,7 +210,7 @@ class ProviderDetailsSchema(BaseSchema):
|
|||||||
class ProviderDetailsHistorySchema(BaseSchema):
|
class ProviderDetailsHistorySchema(BaseSchema):
|
||||||
created_by = fields.Nested(UserSchema, only=['id', 'name', 'email_address'], dump_only=True)
|
created_by = fields.Nested(UserSchema, only=['id', 'name', 'email_address'], dump_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.ProviderDetailsHistory
|
model = models.ProviderDetailsHistory
|
||||||
exclude = ("provider_rates", "provider_stats")
|
exclude = ("provider_rates", "provider_stats")
|
||||||
strict = True
|
strict = True
|
||||||
@@ -236,7 +240,7 @@ class ServiceSchema(BaseSchema, UUIDsAsStringsMixin):
|
|||||||
def get_letter_contact(self, service):
|
def get_letter_contact(self, service):
|
||||||
return service.get_default_letter_contact()
|
return service.get_default_letter_contact()
|
||||||
|
|
||||||
class Meta:
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.Service
|
model = models.Service
|
||||||
exclude = (
|
exclude = (
|
||||||
'updated_at',
|
'updated_at',
|
||||||
@@ -296,7 +300,7 @@ class DetailedServiceSchema(BaseSchema):
|
|||||||
statistics = fields.Dict()
|
statistics = fields.Dict()
|
||||||
organisation_type = field_for(models.Service, 'organisation_type')
|
organisation_type = field_for(models.Service, 'organisation_type')
|
||||||
|
|
||||||
class Meta:
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.Service
|
model = models.Service
|
||||||
exclude = (
|
exclude = (
|
||||||
'api_keys',
|
'api_keys',
|
||||||
@@ -337,7 +341,7 @@ class DetailedServiceSchema(BaseSchema):
|
|||||||
|
|
||||||
|
|
||||||
class NotificationModelSchema(BaseSchema):
|
class NotificationModelSchema(BaseSchema):
|
||||||
class Meta:
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.Notification
|
model = models.Notification
|
||||||
strict = True
|
strict = True
|
||||||
exclude = ('_personalisation', 'job', 'service', 'template', 'api_key',)
|
exclude = ('_personalisation', 'job', 'service', 'template', 'api_key',)
|
||||||
@@ -355,7 +359,7 @@ class BaseTemplateSchema(BaseSchema):
|
|||||||
def get_reply_to_text(self, template):
|
def get_reply_to_text(self, template):
|
||||||
return template.get_reply_to_text()
|
return template.get_reply_to_text()
|
||||||
|
|
||||||
class Meta:
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.Template
|
model = models.Template
|
||||||
exclude = ("service_id", "jobs", "service_letter_contact_id", "broadcast_messages")
|
exclude = ("service_id", "jobs", "service_letter_contact_id", "broadcast_messages")
|
||||||
strict = True
|
strict = True
|
||||||
@@ -421,7 +425,7 @@ class TemplateHistorySchema(BaseSchema):
|
|||||||
def get_reply_to_text(self, template):
|
def get_reply_to_text(self, template):
|
||||||
return template.get_reply_to_text()
|
return template.get_reply_to_text()
|
||||||
|
|
||||||
class Meta:
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.TemplateHistory
|
model = models.TemplateHistory
|
||||||
|
|
||||||
|
|
||||||
@@ -430,7 +434,7 @@ class ApiKeySchema(BaseSchema):
|
|||||||
created_by = field_for(models.ApiKey, 'created_by', required=True)
|
created_by = field_for(models.ApiKey, 'created_by', required=True)
|
||||||
key_type = field_for(models.ApiKey, 'key_type', required=True)
|
key_type = field_for(models.ApiKey, 'key_type', required=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.ApiKey
|
model = models.ApiKey
|
||||||
exclude = ("service", "_secret")
|
exclude = ("service", "_secret")
|
||||||
strict = True
|
strict = True
|
||||||
@@ -462,7 +466,7 @@ class JobSchema(BaseSchema):
|
|||||||
_validate_datetime_not_in_past(value)
|
_validate_datetime_not_in_past(value)
|
||||||
_validate_datetime_not_more_than_96_hours_in_future(value)
|
_validate_datetime_not_more_than_96_hours_in_future(value)
|
||||||
|
|
||||||
class Meta:
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.Job
|
model = models.Job
|
||||||
exclude = (
|
exclude = (
|
||||||
'notifications',
|
'notifications',
|
||||||
@@ -515,7 +519,7 @@ class SmsTemplateNotificationSchema(SmsNotificationSchema):
|
|||||||
|
|
||||||
|
|
||||||
class NotificationWithTemplateSchema(BaseSchema):
|
class NotificationWithTemplateSchema(BaseSchema):
|
||||||
class Meta:
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.Notification
|
model = models.Notification
|
||||||
strict = True
|
strict = True
|
||||||
exclude = ('_personalisation', 'scheduled_notification')
|
exclude = ('_personalisation', 'scheduled_notification')
|
||||||
@@ -594,7 +598,7 @@ class NotificationWithPersonalisationSchema(NotificationWithTemplateSchema):
|
|||||||
class InvitedUserSchema(BaseSchema):
|
class InvitedUserSchema(BaseSchema):
|
||||||
auth_type = field_for(models.InvitedUser, 'auth_type')
|
auth_type = field_for(models.InvitedUser, 'auth_type')
|
||||||
|
|
||||||
class Meta:
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.InvitedUser
|
model = models.InvitedUser
|
||||||
strict = True
|
strict = True
|
||||||
|
|
||||||
@@ -697,7 +701,7 @@ class ApiKeyHistorySchema(ma.Schema):
|
|||||||
|
|
||||||
|
|
||||||
class EventSchema(BaseSchema):
|
class EventSchema(BaseSchema):
|
||||||
class Meta:
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.Event
|
model = models.Event
|
||||||
strict = True
|
strict = True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user