Example #1
0
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)
Example #2
0
    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")
Example #3
0
class ValidatedPathScheme(SQLAlchemyAutoSchema):
    class Meta(BaseSchema.Meta):
        model = db_models.ValidatedPath
        include_relationships = True

    trust_store = Nested(TrustStoreSchema)
    chain = Nested(CertificateChainSchema)
Example #4
0
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')
Example #5
0
File: log.py Project: tanj/log-it
class RolePermissionFixture(FixtureSchema):
    class Meta(FixtureSchema.Meta):
        model = TRolePermission

    log = Nested(LogFixture, many=False)
    role = Nested(RoleFixture, many=False)
    action = Nested(ActionFixture, many=False)
Example #6
0
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"))
Example #7
0
File: log.py Project: tanj/log-it
class UserPermissionFixture(FixtureSchema):
    class Meta(FixtureSchema.Meta):
        model = TUserPermission

    log = Nested(LogFixture, many=False)
    user = Nested(UserFixture, many=False)
    action = Nested(ActionFixture, many=False)
Example #8
0
class ScanResultsHistorySchema(SQLAlchemyAutoSchema):
    class Meta(BaseSchema.Meta):
        model = db_models.ScanResultsHistory
        include_relationships = False
        include_fk = True

    target = Nested(TargetSchema)
    scanresult = Nested(ScanResultsSchema)
Example #9
0
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)
Example #10
0
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
Example #11
0
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)
Example #13
0
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", ))
Example #14
0
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"])
Example #15
0
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)
Example #16
0
class FeiraSchema(SQLAlchemyAutoSchema):
    class Meta:
        model = Feira
        include_fk = False
        include_relationships = True

    distrito = Nested(DistritoSchema)
    subprefeitura = Nested(SubprefeituraSchema)
Example #17
0
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'])
Example #18
0
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
Example #19
0
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())
Example #20
0
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",))
Example #21
0
class ReportSchema(SQLAlchemySchema):
    class Meta:
        model = Report
        load_instance = True
        unknown = EXCLUDE

    id = auto_field()
    lecture = Nested(LectureSchema)
    essays = Nested(EssaySchema, many=True)
Example #22
0
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
Example #24
0
File: log.py Project: tanj/log-it
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)
Example #25
0
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)
Example #26
0
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)
Example #28
0
File: log.py Project: tanj/log-it
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)
Example #29
0
File: log.py Project: tanj/log-it
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)
Example #30
0
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'])