class VariableSchema(DokuSchema, DateSchemaMixin, ApiSchemaMixin): class Meta: model = Variable load_instance = True API_NAME = "variable" id = auto_field() name = auto_field() use_markdown = auto_field() css_class = auto_field() content = auto_field() compiled_content = auto_field(dump_only=True) document_id = auto_field(load_only=True) parent_id = auto_field(load_only=True) parent = Nested("VariableSchema", allow_none=True, exclude=("children", )) document = Nested("DocumentSchema", exclude=("variables", ), dump_only=True) children = Nested("VariableSchema", exclude=("document", ), many=True, partial=True) used = fields.Boolean(dump_only=True) is_list = fields.Boolean(dump_only=True)
def __init__(self, name, *, only=None, exclude=(), many=False, unknown=None, **field_kwargs): Nested.__init__( self, name, only=only, exclude=exclude, many=many, unknown=unknown, **field_kwargs, ) Related.__init__(self, **field_kwargs) self._many = many self._instances = set() self.allow_none = True # Pass through allowed_nests configuration to child schema self._copy_config("allowed_nests") self._copy_config("_show_audit_id")
class ValidatedPathScheme(SQLAlchemyAutoSchema): class Meta(BaseSchema.Meta): model = db_models.ValidatedPath include_relationships = True trust_store = Nested(TrustStoreSchema) chain = Nested(CertificateChainSchema)
class RecipeCreateSchema(SQLAlchemyAutoSchema): class Meta: table = Recipe.__table__ exclude = ('id', 'status', 'created', 'user_id') type = auto_field(validate=validate.OneOf(Recipe.TYPES)) image_id = auto_field() recipe_steps = Nested(RecipeStepCreateSchema, many=True) tags = Nested(TagCreateSchema, many=True) user = Nested(UserRecipeSchema, many=False) @validates('recipe_steps') def validate_recipe_steps(self, recipe_steps): numbers = [] for recipe_step in recipe_steps: number = recipe_step['number'] if number in numbers: raise ValidationError( 'The number of the "{}" step of the recipe is repeated'. format(number)) numbers.append(number) @validates('tags') def validate_tags(self, tags): tags_list = [tag['name'] for tag in tags] if len(tags_list) != len(set(tags_list)): raise ValidationError('The sequence has repeating tags')
class RolePermissionFixture(FixtureSchema): class Meta(FixtureSchema.Meta): model = TRolePermission log = Nested(LogFixture, many=False) role = Nested(RoleFixture, many=False) action = Nested(ActionFixture, many=False)
class ReservationDetailSchema(ma.ModelSchema): """nested schemas replace ids""" id = fields.Int() seat = Nested(SeatSchema, exclude=("reservations",)) show = Nested(ShowMovieNestedSchema) auditorium = Nested(AuditoriumSchema, exclude=("id", "seats", "shows", "reservations"))
class UserPermissionFixture(FixtureSchema): class Meta(FixtureSchema.Meta): model = TUserPermission log = Nested(LogFixture, many=False) user = Nested(UserFixture, many=False) action = Nested(ActionFixture, many=False)
class ScanResultsHistorySchema(SQLAlchemyAutoSchema): class Meta(BaseSchema.Meta): model = db_models.ScanResultsHistory include_relationships = False include_fk = True target = Nested(TargetSchema) scanresult = Nested(ScanResultsSchema)
class RecipeSchema(SQLAlchemyAutoSchema): class Meta: table = Recipe.__table__ image_id = auto_field() recipe_steps = Nested(RecipeStepCreateSchema, many=True) tags = Nested(TagSchema, many=True) user = Nested(UserRecipeSchema, many=False)
class TaskSchema(SQLAlchemyAutoSchema): comments = Nested(CommentSchema, many=True) assignees = Nested(UserSchema, many=True) class Meta: model = Task include_fk = True load_instance = True sqla_session = db.session
class LastScanSchema(SQLAlchemyAutoSchema): class Meta(BaseSchema.Meta): model = db_models.LastScan include_relationships = False include_fk = True target = Nested(TargetSchema) result = Nested(ScanResultsSchema)
class MultipleChoiceQuestionSchema(ModelSchema): class Meta: model = MultipleChoiceQuestion sqla_session = db.session multiple_choice_answers = Nested('MultipleChoiceAnswerSchema', many=True) multiple_choice_question_translations = Nested( 'MultipleChoiceQuestionTranslationSchema', many=True)
class PersonAndPetAndAddressSchema(SQLAlchemyAutoSchema): class Meta: model = Person include_relationships = True load_instance = True pets = Nested(PetSchema, many=True, exclude=("person_id", )) addresses = Nested(AddressSchema, many=True, exclude=("person_id", ))
class ConsumerSchema(ma.SQLALchemySchema): class Meta: model = Consumer fields = ("phone", "product_code", "created_at", "updated_at", "created_at", "deleted_at") members = Nested(MemberSchema, only=["phone", "username"]) product = Nested(ProductSchema, only=["title", "pay"])
class ScanOrderSchema(SQLAlchemyAutoSchema): class Meta(BaseSchema.Meta): model = db_models.ScanOrder include_relationships = True include_fk = True # this needs to be enabled for schema.load to work properly target = Nested(TargetSchema) user = Nested(UserSchema)
class FeiraSchema(SQLAlchemyAutoSchema): class Meta: model = Feira include_fk = False include_relationships = True distrito = Nested(DistritoSchema) subprefeitura = Nested(SubprefeituraSchema)
class PostSchema(SQLAlchemyAutoSchema): class Meta: load_instance = True include_relationships = True model = Post comments = Nested('CommentSchema', many=True, exclude=['post']) reactions = Nested('ReactionSchema', many=True, exclude=['post']) user = Nested("UserSchema", only=['username', 'img'])
class ResearcherSchema(ma.ModelSchema): email_group = Nested(EmailGroupSchema, exclude=('researcher', )) th_name_group = Nested(ThaiNameGroupSchema, exclude=('researcher', )) en_name_group = Nested(EngNameGroupSchema, exclude=('researcher', )) university_group = Nested(UniversityGroupSchema, exclude=('researcher', )) academic_position = Nested(AcademicPositionSchema, only=('title', )) class Meta: model = FactResearcher
class ChargeSchema(SQLAlchemyAutoSchema): class Meta: model = Charge include_fk = True load_instance = True material = Nested(lambda: MaterialSchema(), dump_only=True) chargeShirt = Nested(ChargeShirtSchema()) chargeColor = Nested(ChargeColorSchema())
class submission_schema(SQLAlchemyAutoSchema): class Meta: model = submission include_relationship = True load_instance = True ref = Nested(reference_schema, many=True, exclude=("sub",)) variant = Nested(variant_schema, many=True, exclude=("sub",))
class ReportSchema(SQLAlchemySchema): class Meta: model = Report load_instance = True unknown = EXCLUDE id = auto_field() lecture = Nested(LectureSchema) essays = Nested(EssaySchema, many=True)
class TaskSchema(SQLAlchemyAutoSchema): class Meta: model = WorkLog taskee = Nested( UserSchema(exclude=['password', 'location', 'type', 'email'])) tasker = Nested( WorkerSchema(exclude=['password', 'location', 'type', 'email'])) location = Nested(AddressSchema)
class FileSchema(ModelSchema): keywords = Nested(KeywordSchema, many=True, exclude=("files", "id")) folder = Nested(FolderSchema) @post_load def make_file(self, data, **kwargs): return File(**data) class Meta: model = File
class LogFullFixture(FixtureSchema): class Meta(FixtureSchema.Meta): model = TLog filter_attrs = ["sLog"] sLog = auto_field() user = Nested(UserFixture, many=False) fields = Nested(FieldFixture, many=True) user_permissions = Nested(UserPermissionFixture) role_permissions = Nested(RolePermissionFixture)
class ProductSchema(ma.SQLAlchemySchema): class Meta: model = Product id = ma.auto_field() name = ma.auto_field() description = ma.auto_field(dump_only=False) images = Nested(ImageSchema, many=True) factories = Nested(FactorySchema, many=True) marks = Nested(MarkSchema, many=True) subcategories = Nested(SubcategorySchema, many=True)
class MoviesOnDateSchema(ma.ModelSchema): """excludes shows""" id = fields.Int() title = fields.String() description = fields.String() rating = fields.String() runtime = fields.Time() director = Nested(DirectorSchema, exclude=("movies",)) genre = Nested(GenreSchema, exclude=("movie",)) actors = Nested(ActorSchema, many=True, exclude=("movies",))
class InventorySchema(SQLAlchemyAutoSchema): class Meta: model = Inventory include_fk = True exclude = ['value_of_materials'] value_of_materials = auto_field(dump_only=True) # Override materials field to use a nested representation rather than pks material = Nested(lambda: MaterialSchema(), dump_only=True) place = Nested(lambda: PlaceSchema(), dump_only=True)
class MessageFixture(FixtureSchema): class Meta(FixtureSchema.Meta): model = TMessage # message fixtures are always inserted, never looked up filter_attrs = None log = Nested(LogFixture, many=False) message_type = Nested(MessageTypeFixture, many=False) user = Nested(UserFixture, many=False) utcMessage = auto_field(missing=datetime.utcnow) sMessage = auto_field() tags = Nested(TagFixture, many=True)
class LogFieldFixture(FixtureSchema): class Meta(FixtureSchema.Meta): model = TLogField filter_attrs = [ "log.ixLog", "field.ixField", ] log = Nested(LogFixture, many=False) field = Nested(FieldFixture, many=False) sValue = auto_field() iOrder = auto_field(missing=None)
class UserSchema(SQLAlchemyAutoSchema): class Meta: load_instance = True include_relationships = True model = User posts = Nested('PostSchema', many=True) comments = Nested('CommentSchema', many=True, exclude=['user']) reactions = Nested('ReactionSchema', many=True, exclude=['user']) transactions = Nested('TransactionSchema', many=True, exclude=['user', 'company_amount'])