예제 #1
0
class PlaySchema(ma.SQLAlchemyAutoSchema):

    id = ma.Int(dump_only=True)
    turn_number = ma.Int(required=True)
    score = ma.Int(required=True)
    cumulative_score = ma.Int()

    word = ma.Nested("WordSchema", required=True)
    game = ma.Nested("GameSchema", exclude=("plays", ), required=True)
    player = ma.Nested("PlayerSchema", exclude=("plays", ), required=True)

    class Meta:
        model = Play
        sqla_session = db.session
        load_instance = True
        include_fk = True
        include_relationships = True
        exclude = ("word_id", "game_id", "player_id")
예제 #2
0
class PlayerSchema(ma.SQLAlchemyAutoSchema):

    id = ma.Int(dump_only=True)
    name = ma.String(required=True)

    plays = ma.Nested("PlaySchema", many=True)

    class Meta:
        model = Player
        sqla_session = db.session
        load_instance = True
        include_relationships = True
예제 #3
0
class GameSchema(ma.SQLAlchemyAutoSchema):

    id = ma.Int(dump_only=True)
    date = ma.DateTime(required=True)
    gametype = EnumField(GametypeEnum, by_value=True, required=True)

    winner = ma.Nested("PlayerSchema")

    players = ma.Nested("PlayerSchema", many=True)
    plays = ma.Nested("PlaySchema", many=True)

    @validates("date")
    def validate_date(self, date):
        if date > datetime.now():
            raise ValidationError("Date cannot be in the future")

    class Meta:
        model = Game
        sqla_session = db.session
        load_instance = True
        include_fk = True
        include_relationships = True
예제 #4
0
class WordSchema(ma.SQLAlchemyAutoSchema):

    id = ma.Integer(dump_only=True)
    word = ma.String(required=True)

    language = ma.Nested("LanguageSchema", required=True)

    class Meta:
        model = Word
        sqla_session = db.session
        load_instance = True
        include_relationships = True
        include_fk = True
        unknown = RAISE
예제 #5
0
class PlayerPaginationSchema(PaginationSchema):
    data = ma.Nested("PlayerSchema", attribute="items", many=True)
예제 #6
0
class WordPaginationSchema(PaginationSchema):
    data = ma.Nested("WordSchema", attribute="items", many=True)
예제 #7
0
class GamePaginationSchema(PaginationSchema):
    data = ma.Nested("GameSchema", attribute="items", many=True)