Ejemplo n.º 1
0
class GameSchema(ma.SQLAlchemyAutoSchema):

    id = ma.Int(dump_only=True)

    class Meta:
        model = Game
        sqla_session = db.session
        load_instance = True
Ejemplo n.º 2
0
class UserSchema(ma.SQLAlchemyAutoSchema):

    id = ma.Int(dump_only=True)
    password = ma.String(load_only=True, required=True)

    class Meta:
        model = User
        sqla_session = db.session
        load_instance = True
Ejemplo n.º 3
0
class ReservationSchema(ma.SQLAlchemyAutoSchema):
    id = ma.Int(dump_only=True)
    timestamp = ma.DateTime(dump_only=True)
    confirmed = ma.Boolean(dump_only=True)

    start = ma.Date(required=True)
    end = ma.Date(required=True)
    customer_id = ma.Int(load_only=True, required=True)

    customer = ma.Pluck(CustomerSchema, 'id', many=False)

    class Meta:
        model = Reservation
        sqla_session = db.session
        load_instance = True

    @validates("customer_id")
    def validate_customer_id(self, customer_id):
        customer = Customer.query.get(customer_id)
        if not customer:
            raise ValidationError("Customer with id: #%d does not exist." %
                                  customer_id)

    @validates_schema(skip_on_field_errors=True)
    def validate_date(self, data, **kwargs):
        if not data['start'] <= data['end']:
            raise marshmallow.ValidationError(
                'start should not be less than end', 'start')

        if data['start'] < datetime.today().date():
            raise marshmallow.ValidationError('start can not be in the past',
                                              'start')

        if not Reservation.is_free(data['start'], data['end']):
            raise marshmallow.ValidationError(
                'there is already an existing reservation', 'start')
Ejemplo n.º 4
0
class CustomerSchema(ma.SQLAlchemyAutoSchema):
    id = ma.Int(dump_only=True)
    registered_on = ma.DateTime(dump_only=True)

    first_name = ma.String(required=True, validate=Length(1, 255))
    last_name = ma.String(required=True, validate=Length(1, 255))
    street = ma.String(required=True, validate=Length(1, 255))
    zip_code = ma.String(required=True, validate=Length(1, 10))
    city = ma.String(required=True, validate=Length(1, 255))
    tel = ma.String(required=False, allow_none=True, validate=Length(max=64))
    email = ma.Email(required=True, validate=Length(1, 255))

    class Meta:
        model = Customer
        sqla_session = db.session
        load_instance = True