class FlowSchema(Schema): name = fields.Str() steps = ma.Nested(StepSchema(), many=True)
class ClienteSchema(ma.ModelSchema): contatos = ma.Nested(ContatoSchema, many=True) enderecos = ma.Nested(EnderecoSchema) class Meta: model = Cliente
class WeekSchema(ma.Schema): class Meta: fields = ('id', 'season_id', 'index', 'member_activity_week') member_activity_week = ma.List(ma.Nested(MemberActivityWeekSchema))
class UserSearchSchema(ma.Schema): pages = fields.Integer() total = fields.Integer() items = ma.List(ma.Nested(UserSchema))
class CourseSchema(ma.ModelSchema): course_schedule = ma.Nested(ScheduleSchema, many=True) class Meta: model = Course
class CategorySchema(ma.SQLAlchemyAutoSchema): ingredients = ma.Nested(IngredientSchema, many=True) class Meta: model = Category
class UserSchema(ma.SQLAlchemyAutoSchema): recipes = ma.Nested(RecipeSchema, many=True) class Meta: fields = ("id", "email", "recipes", "username") include_relationships = True
class EditRequestSchema(sqla.ModelSchema): class Meta: model = EditRequest messages = ma.Nested(EditRequestMessageSchema, many=True) dataset_name = fields.Function(lambda obj: obj.dataset.name)
class StudentAddendanceSchemaClass(ma.Schema): class Meta: fields = ('id', 'student', 'present') student = ma.Nested(StudentSchema)
class RoleSchema(ma.Schema): users = ma.Nested(UserSchema, many=True) class Meta: # Fields to expose fields = ('id', 'name', 'default', 'permissions', 'users')
class CountrySchema(ma.Schema): class Meta: fields = ("id", "name", "region") region = ma.Nested(RegionSchema)
class GroupSchema(ma.Schema): users = ma.Nested(UserSchema, many=True) class Meta: # Fields to expose fields = ('id', 'name', 'users')
class UsuarioSchema(ma.SQLAlchemyAutoSchema): class Meta: model = Usuario tipo_usuario = ma.Nested(TipoUsuarioSchema(only=('nome',)))
class AdminNoteSchema(ModelSchema): class Meta(ModelSchema.Meta): model = AdminNote fields = ('id', 'resource_id', 'user_id', 'resource', 'user', 'last_updated', 'note') user = ma.Nested(UserSchema, dump_only=True) resource = ma.Nested(ResourceSchema, dump_only=True)
class ContactSchema(ma.Schema): type_contact = ma.Nested('TypeContactSchema') class Meta: fields = ('id', 'contact', 'description', 'user_id', 'type_contact')
class AttendanceSchemaClass(ma.Schema): class Meta: fields = ('id', 'date', 'subject', 'students') subject = ma.Nested(SubjectSchema) students = ma.Nested(StudentAddendancesSchema)
class VersionDetailSchema(ma.ModelSchema): application = ma.Nested(ApplicationDetailSchema, only=['name']) class Meta: model = Version fields = ('id', 'file', 'application_id', 'application')
class PageOfSessionsSchema(PaginationSchema): items = ma.List(ma.Nested(SessionItemSchema))
class RecipeIngredientsSchema(ma.SQLAlchemyAutoSchema): ingredient = ma.Nested(IngredientSchema) class Meta: fields = ("ingredient.id", "ingredient.name", "quantity")
class AreaSchema(ma.Schema): type_area = ma.Nested('TypeAreaSchema', many=False) class Meta: fields = ('id', 'name', 'description', 'type_area', 'user_id')
class ScrapeSchema(ma.ModelSchema): id = field_for(Scrape, 'id', dump_only=True) status = field_for(Scrape, 'status', dump_only=True) timestamp = field_for(Scrape, 'timestamp', dump_only=True) city = ma.Nested(CitySchema, many=True) tag = ma.Nested(TagSchema, many=True)
class UserSchema(ma.SQLAlchemyAutoSchema): info = ma.Nested(UserInfoSchema) class Meta: model=User() exclude=("password","active")
class CarEntrySchema(ma.ModelSchema): class Meta: model = CarEntry description = ma.Nested(CarDescriptionSchema) image = ma.Nested(CarImageSchema)
class ProductSchema(ma.SQLAlchemyAutoSchema): owner=ma.Nested(UserSchema(only=("name","email"))) category=ma.Nested(CategorySchema) class Meta: model=Product
class PostSchema(ma.SQLAlchemySchema): class Meta: model = PostModel images = ma.Method(serialize="get_image_ids", deserialize="get_image_ids") id = ma.auto_field() uploader = ma.Method("get_writer_with_check_anonymous") content = ma.auto_field() title = ma.auto_field() views = ma.auto_field() posted_datetime = ma.Method(serialize="get_abbreviated_datetime_as_string") is_anonymous = ma.auto_field() number_of_likes = ma.Method(serialize="get_number_of_postlikes") number_of_dislikes = ma.Method(serialize="get_number_of_postdislikes") posted_gallery = ma.Nested("GallerySchema") number_of_comments = ma.Method(serialize="get_number_of_comments") whether_exist_image = ma.Method(serialize="get_whether_image_exist") my_reaction = ma.Method(serialize="get_user_reaction") is_mine = ma.Method(serialize="is_users") def get_abbreviated_datetime_as_string(self, obj): def _get_abbreviated_datetime_as_string(dt): if not isinstance(dt, datetime): raise AttributeError() diff_from_now = datetime.now() - dt if diff_from_now.days >= 1: return f"{dt.year:04d}.{dt.month:02d}.{dt.day:02d}." else: return f"{dt.hour:02d}:{dt.minute:02d}" return _get_abbreviated_datetime_as_string(obj.posted_datetime) def get_writer_with_check_anonymous(self, obj): if obj.is_anonymous: return {"username": "******", "profile_image": None} else: from app.api.v1.user.model import UserSchema return UserSchema(only=["username", "profile_image"]).dump( obj.uploader) def get_image_ids(self, obj): list = [] for image in obj.images: list.append(image.id) return list def get_number_of_postlikes(self, obj): return len(obj.likes) def get_number_of_postdislikes(self, obj): return len(obj.dislikes) def get_number_of_comments(self, obj): return len(obj.comments) def get_whether_image_exist(self, obj): if not obj.images: return False else: return True def get_user_reaction(self, obj): user_id = get_jwt_identity() for like in obj.likes: if like.liker_id == user_id: return 'like' for dislike in obj.dislikes: if dislike.liker_id == user_id: return 'dislike' return 'none' def is_users(self, obj): return obj.uploader_id == get_jwt_identity()
class PostSchema(ma.ModelSchema): topics = ma.Nested(TopicSchema, many=True) class Meta: model = Post
class ActivitySchema(ma.Schema): class Meta: fields = ('id', 'league_id', 'points', 'name', 'bonus', 'limit', 'member_activity_week') member_activity_week = ma.List(ma.Nested(MemberActivityWeekSchema))
class FetchMsgsResultSchema(ma.Schema): class Meta: fields = ("msgs", "has_more", "no_more") msgs = ma.List(ma.Nested(MessageSchema))
class SeasonSchema(ma.Schema): class Meta: fields = ('id', 'league_id', 'weeks_number', 'disabled', 'start_date', 'weeks') weeks = ma.List(ma.Nested(WeekSchema))
class SearchSchema(ma.Schema): class Meta: unknown = EXCLUDE class HitSchema(ma.Schema): id = fields.Integer() content = fields.Str(missing=None) description = fields.Str(missing=None) post_event_description = fields.Str(missing=None) title = fields.Str(missing=None) type = fields.Str() label = fields.Str(missing=None) last_updated = fields.DateTime(missing=None) highlights = fields.Str(missing=None) latitude = fields.Float() longitude = fields.Float() date = fields.DateTime(missing=None) status = fields.Str(missing=None) no_address = fields.Boolean(missing=None) is_draft = fields.Boolean(missing=None) class SortSchema(ma.Schema): field = fields.Str(allow_null=True) latitude = fields.Float(missing=None) longitude = fields.Float(missing=None) order = fields.Str(missing='asc') unit = fields.Str(missing='mi') @post_load def make_sort(self, data, **kwargs): return Sort(**data) class AggCountSchema(ma.Schema): value = fields.String() count = fields.Integer() is_selected = fields.Boolean() class GeoboxSchema(ma.Schema): top_left = ma.Nested(GeopointSchema) bottom_right= ma.Nested(GeopointSchema) @post_load def make_geo_box(self, data, **kwargs): return Geobox(**data) words = fields.Str() start = fields.Integer() size = fields.Integer() sort = ma.Nested(SortSchema, allow_none=True, default=None) types = fields.List(fields.Str()) ages = fields.List(fields.Str()) languages = fields.List(fields.Str()) age_counts = fields.List(ma.Nested(AggCountSchema), dump_only=True) language_counts = fields.List(ma.Nested(AggCountSchema), dump_only=True) type_counts = fields.List(ma.Nested(AggCountSchema), dump_only=True) total = fields.Integer(dump_only=True) hits = ma.Nested(HitSchema(), many=True, dump_only=True) category = ma.Nested(CategoryInSearchSchema) ordered = True date = fields.DateTime(allow_none=True) map_data_only = fields.Boolean() geo_box = ma.Nested(GeoboxSchema, allow_none=True, default=None) @post_load def make_search(self, data, **kwargs): return Search(**data)