Пример #1
0
class Seats(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(5), unique=True, nullable=False)
    bookings = db.relationship('Booking', backref='seat')

    def __repr__(self):
        return f"('{self.name}')"
class Reply(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.String(140))
    timestamp = db.Column(db.Integer)
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def __repr__(self):
        return '<Reply %r>' % (self.title)
Пример #3
0
class Thread(db.Model):
    __tablename__ = 'thread'
    id = db.Column(db.Integer, primary_key = True)
    title = db.Column(db.String(100))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    messages = db.relationship('Message', backref = 'thread')

    def __init__(self, title, user_id):
        self.title = title
        self.user_id = user_id
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(140))
    body = db.Column(db.String(256))
    timestamp = db.Column(db.Integer)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    replys = db.relationship('Reply', backref='author', lazy='dynamic')

    def __repr__(self):
        return '<Post %r>' % (self.title)
Пример #5
0
class Route(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), nullable=False)
    time = db.Column(db.String(60), nullable=False)
    amount = db.Column(db.Integer(), nullable=False)
    availability = db.relationship('Availability', backref='route')
    booking = db.relationship('Booking', backref='route')

    def __repr__(self):
        return f"Route('{self.name}','{self.time}','{self.amount}')"
Пример #6
0
class Message(db.Model):
    __tablename__ = 'message'
    id = db.Column(db.Integer, primary_key = True)
    body = db.Column(db.Text)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    thread_id = db.Column(db.Integer, db.ForeignKey('thread.id'))

    def __init__(self, body, user_id, thread_id):
        self.body = body
        self.user_id = user_id
        self.thread_id = thread_id
Пример #7
0
class Buses(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), unique=True, nullable=False)
    number = db.Column(db.String(20), unique=True, nullable=False)
    description = db.Column(db.String(200), nullable=False)
    image_file = db.Column(db.String(60),
                           nullable=False,
                           default='default_bus.jpg')
    bookings = db.relationship('Booking', backref='bus')
    availability = db.relationship('Availability', backref='bus')

    def __repr__(self):
        return f"Bus('{self.name}','{self.number}','{self.description}','{self.image_file}')"
Пример #8
0
class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100))
    email = db.Column(db.String(100))
    password = db.Column(db.String(100))
    token = db.Column(db.String(100))
    threads = db.relationship('Thread', backref='user')
    messages = db.relationship('Message', backref='user')

    def __init__(self, name, email, password, token):
        self.name = name
        self.email = email
        self.password = password
        self.token = token
Пример #9
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    author_name = db.Column(db.Unicode(20), nullable=False)
    title = db.Column(db.Unicode(100), nullable=False)
    body = db.Column(db.UnicodeText, nullable=False)
    created_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.datetime.utcnow)
    views = db.Column(db.Integer, nullable=False, default=0)
Пример #10
0
class Availability(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    route_id = db.Column(db.Integer, db.ForeignKey('route.id'), nullable=False)
    bus_id = db.Column(db.Integer, db.ForeignKey('buses.id'), nullable=False)
    date = db.Column(db.Date, nullable=False)
    time = db.Column(db.String(60), nullable=False)
    amount = db.Column(db.Integer(), nullable=False)
    status = db.Column(db.String(60), nullable=False)

    #buses = db.relationship('Buses', backref='availability')

    def __repr__(self):
        return f"Availability('{self.bus_id}','{self.route_id}','{self.date}','{self.time}','{self.amount}','{self.status}')"
Пример #11
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), unique=True, nullable=False)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    phone = db.Column(db.Integer(), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    active = db.Column(db.Boolean)
    bookings = db.relationship('Booking', backref='customer')
    roles = db.relationship('Role',
                            secondary='roles_users',
                            backref=db.backref('users', lazy='dynamic'))

    def __repr__(self):
        return f"User('{self.name}','{self.username}','{self.email}','{self.phone}','{self.image_file}')"
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    nickname = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    password = db.Column(db.String(120))
    timestamp = db.Column(db.Integer)
    role = db.Column(db.Text)
    posts = db.relationship('Post', backref='author', lazy='dynamic')

    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return str(self.id)  # python 3

    def is_allowed(self):
        if ("Professor" in str(self.role)) or ("Senior" in str(self.role)):
            return True
        else:
            return False

    @lm.user_loader
    def load_user(id):
        return User.query.get(int(id))

    def __repr__(self):
        return json.dumps({
            'id': self.id,
            'nickname': self.nickname,
            'email': self.email,
            'role': self.role
        })
Пример #13
0
class Role(db.Model, RoleMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), unique=True, nullable=False)
    description = db.Column(db.String(255))
Пример #14
0
class Booking(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    ticket_number = db.Column(db.String(60), nullable=False)
    customer_id = db.Column(db.Integer,
                            db.ForeignKey('user.id'),
                            nullable=False)
    seat_id = db.Column(db.Integer, db.ForeignKey('seats.id'), nullable=False)
    bus_id = db.Column(db.Integer, db.ForeignKey('buses.id'), nullable=False)
    route_id = db.Column(db.Integer, db.ForeignKey('route.id'), nullable=False)
    phone = db.Column(db.Integer(), nullable=False)
    date_booked = db.Column(db.String(120),
                            nullable=False,
                            default=now.strftime('%Y-%m-%d'))
    email = db.Column(db.String(120), nullable=False)
    date = db.Column(db.DateTime, nullable=False)
    time = db.Column(db.String(60), nullable=False)

    def __repr__(self):
        return f"('{self.customer_id}','{self.phone}','{self.email}','{self.seat_id}',\
Пример #15
0
#     return User.query.get(int(user_id))


class Controller(ModelView):
    def is_accessible(self):
        if current_user.has_role('admin'):
            return current_user.is_authenticated
        else:
            return abort(403)

    def not_authenticated(self):
        abort(403)


roles_users = db.Table(
    'roles_users', db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
    db.Column('role_id', db.Integer, db.ForeignKey('role.id')))


class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), unique=True, nullable=False)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    phone = db.Column(db.Integer(), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    active = db.Column(db.Boolean)
    bookings = db.relationship('Booking', backref='customer')