class GetCommentParameterSchema(ma.Schema): post_id = ma.Integer(data_key="post-id", required=False) username = ma.Str(required=False) page = ma.Integer(required=False, validate=Range(min=0)) per_page = ma.Integer(data_key="per-page", required=False, validate=Range(min=1))
class ReportCommentInputSchema(ma.Schema): reason = ma.Integer(required=True, validate=Range(min=1, max=10)) detail_reason = ma.Str(required=True, validate=Length(max=500)) reported_content_type = ma.Integer( required=True, validate=Range(min=1, max=2) ) post_id = ma.Integer(required=False, allow_none=True) comment_id = ma.Integer(required=True)
class PostGetQueryParameterValidateSchema(ma.Schema): page = ma.Integer(required=False, validate=Range(min=1)) per_page = ma.Integer(required=False, validate=Range(min=1), data_key="per-page") username = ma.Str(required=False, validate=Length(min=2, max=20)) gallery_id = ma.String(required=False, validate=Length(min=1, max=30), data_key="gallery-id")
class PostValidateSchema(ma.Schema): id = ma.Integer() user_id = ma.Integer(required=True) body = ma.String(required=True) @validates('body') def validate_body(self, body): if len(body) <= 0: raise ValidationError("This field can't be empty.") elif len(body) > 255: raise ValidationError('max character of 255 characters exceeded.')
class NotificationSchema(ma.Schema): id = ma.Integer() body = ma.String(required=True) created_by = ma.Integer(required=True) target_user = ma.Integer(required=True) notification_date = ma.DateTime() @validates('body') def validate_body(self, body): if len(body) <= 0: raise ValidationError("This field can't be empty.") elif len(body) > 255: raise ValidationError('max character of 255 characters exceeded.')
class PostSchema(ma.Schema): id = ma.Integer() body = ma.String(required=True) created_by = ma.Integer() no_likes = ma.Integer() no_comments = ma.Integer() posted_date = ma.DateTime() liked = ma.Boolean() @validates('body') def validate_body(self, body): if len(body) <= 0: raise ValidationError("This field can't be empty.") elif len(body) > 255: raise ValidationError('max character of 255 characters exceeded.')
class GetGalleriesQueryParameterValidateSchema(ma.Schema): gallery_type = ma.Integer( requierd=False, allow_none=False, validate=Range(min=0, max=2), data_key="gallery-type", )
class FeatureRequestListArgsSchema(ma.Schema): limit = ma.Integer(required=False, validate=[validate.Range(1, 100)], missing=20) offset = ma.Integer(required=False, validate=[validate.Range(0)], missing=0) include_archived = ma.Boolean(required=False, missing=False) area = ma.Function(deserialize=load_from_id(Area), required=False) client = ma.Function(deserialize=load_from_id(Client), required=True, validate=[validate.NoneOf([None])]) search = ma.String(required=False) sort = ma.String( required=False, validate=[validate.OneOf(['priority', 'id', 'target_date'])], missing='priority')
class PostGalleryValidateSchema(ma.Schema): name = ma.Str(required=True, validate=Length(max=30, min=1), allow_none=False) explain = ma.Str(required=True, validate=Length(max=255, min=0)) gallery_id = ma.Str(required=True, validate=Length(max=30, min=1)) gallery_type = ma.Integer( required=True, allow_none=False, validate=Range(min=0, max=2), )
class UserSchema(ma.Schema): id = ma.Integer() username = ma.String(required=True) email = ma.Email(required=True) password = ma.String(required=True) profile_pic = ma.String() bio = ma.String() location = ma.String() website = ma.Url() is_active = ma.Boolean() is_admin = ma.Boolean() joined_date = ma.DateTime()
class TodoSchema(ma.Schema): id = ma.Integer() title = ma.String(required=True) done = ma.Boolean() created_by = ma.UUID() @validates('title') def validate_title(self, title): if len(title) <= 0: raise ValidationError("This field can't be empty.") elif len(title) > 120: raise ValidationError('max character of 120 characters exceeded.')
class AnalysisSchema(ma.ModelSchema): class Meta: model = Analysis current_asset = ma.Float(required=True) current_liability = ma.Float(required=True) total_assets = ma.Float(required=True) third_party_liability = ma.Float(required=True) financial_obligations = ma.Float(required=True) net_sales = ma.Float(required=True) gross_utility = ma.Float(required=True) net_utility = ma.Float(required=True) status = EnumField(AnalysisStatus) entity_id = ma.Integer(required=True) # calculated fields current_ratio = ma.Method('get_current_ratio') net_work_capital = ma.Method('get_net_work_capital') gross_margin = ma.Method('get_gross_margin') net_margin = ma.Method('get_net_margin') debt_level = ma.Method('get_debt_level') financial_debt = ma.Method('get_financial_debt') def get_current_ratio(self, obj): current_ratio = obj.current_asset / obj.current_liability return round(current_ratio * 0.25, 2) def get_net_work_capital(self, obj): net_work_capital = obj.current_asset - obj.current_liability return round(net_work_capital, 2) def get_gross_margin(self, obj): gross_margin = obj.gross_utility / obj.net_sales return round(gross_margin * 0.25, 2) def get_net_margin(self, obj): net_margin = obj.net_utility / obj.net_sales return round(net_margin * 0.10, 2) def get_debt_level(self, obj): debt_level = obj.third_party_liability / obj.total_assets return round(debt_level * 0.30, 2) def get_financial_debt(self, obj): financial_debt = obj.financial_obligations / obj.net_sales return round(financial_debt * 0.10, 2)
class HotPostGetQueryParameterValidateSchema(ma.Schema): page = ma.Integer(required=False, validate=Range(min=1)) per_page = ma.Integer(required=False, validate=Range(min=1), data_key="per-page")
class NameCountSchema(ma.SQLAlchemyAutoSchema): username = ma.String() count = ma.Integer()
class ListArgsSchema(ma.Schema): limit = ma.Integer(required=False, validate=[ validate.Range(1, 100)], missing=100) offset = ma.Integer(required=False, validate=[ validate.Range(0)], missing=0)
class UnitsDeliveredByProductByCountrySchema(ma.Schema): product_name = ma.String() product_id = ma.Integer() country_name = ma.String() country_id = ma.Integer() units = ma.Integer()
class SellsByProductSchema(ma.Schema): product = ma.Nested(ProductSchema) sells = ma.Integer()
class OrdersByStatusSchema(ma.Schema): count = ma.Integer() status = ma.Function(lambda row: row.status.value)
class CustomersByCountrySchema(ma.Schema): country = ma.Nested(CountrySchema) count = ma.Integer()
class ProductsByCategorySchema(ma.Schema): category = ma.Nested(CategorySchema) count = ma.Integer()
class OrderDetailCreateSchema(ma.Schema): product = ma.Function(deserialize=lambda v: models.Product.query.get( v), required=True, validate=[validate.NoneOf([None])]) quantity = ma.Integer(required=True, validate=[validate.Range(1)])
class CommentInputSchema(ma.Schema): content = ma.Str(required=True, validate=Length(min=1, max=100)) upper_comment_id = ma.Integer(required=False, allow_none=True) is_anonymous = ma.Boolean(required=True)
class RequestPostlikeApiQueryParameterVaidateSchema(ma.Schema): post_id = ma.Integer( required=True, validate=Range(min=0) )
class PaginationSchema(ma.Schema): page = ma.Integer() pages = ma.Integer() per_page = ma.Integer() total = ma.Integer()
class PostCommentParameterSchema(ma.Schema): post_id = ma.Integer(data_key="post-id", required=True, validate=Range(min=0))
class CommentSchema(ma.Schema): id = ma.Integer() body = ma.String(required=True) post_id = ma.Integer() commented_by = ma.Integer(required=True) comment_date = ma.DateTime()