Exemple #1
0
class Field(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    field_name = db.Column(db.String(20), unique=False, nullable=False)
    sport = db.Column(db.String(20), unique=False, nullable=False)
    max_people = db.Column(db.Integer, unique=False, nullable=True)
    club_id = db.Column(db.Integer, db.ForeignKey('club.id'), nullable=False)
    booking = db.relationship('Booking', backref='field', lazy=True)

    def __repr__(self):
        club = Club.query.filter_by(id=self.club_id).first()
        return "Field(%s, %s, %s)" % (club.name, self.field_name, self.sport)
Exemple #2
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    urole = db.Column(db.String(20), nullable=False)
    password = db.Column(db.String(60), nullable=False)
    clubs = db.relationship('Club', backref='club_user', lazy=True)
    player = db.relationship('Player', backref='player-user', lazy=True)

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'u': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['u']
            return User.query.get(user_id)
        except:
            return None

    def __repr__(self):
        return "User(%s, %s, %s)" % (self.username, self.email, self.urole)
Exemple #3
0
class Booking(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(64), nullable=False, unique=False)
    date = db.Column(db.DateTime, nullable=False)
    startTime = db.Column(db.Integer, nullable=False)
    endTime = db.Column(
        db.Integer,
        nullable=False)  # should be calculated with startTime and duration
    duration = db.Column(db.Integer, nullable=False)
    booker_id = db.Column(db.Integer,
                          db.ForeignKey('player.id'),
                          nullable=False)
    field_id = db.Column(db.Integer, db.ForeignKey('field.id'), nullable=False)
    post = db.relationship('Post', backref='booking', lazy=True)

    # How Bookings are printed when the object is called
    def __repr__(self):
        return "Booking(%s, %s, %s)" % (self.booker_id, self.startTime,
                                        self.endTime)
Exemple #4
0
class Player(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), nullable=False)
    surname = db.Column(db.String(60), nullable=False)
    gender = db.Column(db.String(10), nullable=False)
    country = db.Column(db.String(20), nullable=False)
    phone_number = db.Column(db.String(20), unique=False, nullable=False)
    address = db.Column(db.String(60), nullable=False)
    birthdate = db.Column(db.Date, nullable=False)
    subscription_date = db.Column(db.Date,
                                  nullable=False,
                                  default=datetime.utcnow)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    booking = db.relationship('Booking', backref='booker', lazy=True)
    post = db.relationship('Post', backref='player_post', lazy=True)
    rating = db.relationship('PlayerRate', backref='player_rate', lazy=True)

    def __repr__(self):
        return "Player(%s, %s, %s)" % (self.name, self.surname,
                                       self.subscription_date)
Exemple #5
0
class Club(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), unique=True, nullable=False)
    phone_number = db.Column(db.String(20), unique=False, nullable=False)
    city = db.Column(db.String(60), nullable=False)
    address = db.Column(db.String(60), nullable=False)
    lat = db.Column(db.Float(10), nullable=False)
    lon = db.Column(db.Float(10), nullable=False)
    piva = db.Column(db.String(20), unique=True, nullable=False)
    subscription_date = db.Column(db.Date,
                                  nullable=False,
                                  default=datetime.utcnow)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default_club.jpg')
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    field = db.relationship('Field', backref='club_field', lazy=True)
    rating = db.relationship('ClubRate', backref='club_rate', lazy=True)

    def __repr__(self):
        return "Club(%s, %s)" % (self.name, self.address)