class ReviewModel(db.Model): """Class to create a Review class object""" __tablename__ = 'reviews' id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(50), nullable=False) body = db.Column(db.String(256), nullable=False) business = db.Column(db.Integer, db.ForeignKey('businesses.id')) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) creation_date = db.Column(db.DateTime, default=db.func.current_timestamp()) update_date = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp()) author = db.relationship('User') def __init__(self, title, body, business, db_user): self.title = title self.body = body self.business = business self.author_id = db_user @api.marshal_with(reviews_model, envelope='reviews') def as_dict(self): business_dict = { c.name: str(getattr(self, c.name)) for c in self.__table__.columns } business_dict['author'] = self.author.user_name return business_dict def __repr__(self): return '<Review: {}>'.format(self.title)
class User(db.Model): """ Class that creates a user """ __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True, autoincrement=True) email = db.Column(db.String(120), unique=True, nullable=False) user_name = db.Column(db.String(50), unique=True, nullable=False) password_hash = db.Column(db.String(256), nullable=False) creation_date = db.Column(db.DateTime, default=db.func.current_timestamp()) update_date = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp()) businesses = db.relationship('BusinessModel', order_by='BusinessModel.id', cascade='all, delete-orphan') def __init__(self, user_name, email, password): self.email = email self.user_name = user_name self.password_hash = generate_password_hash(password) def __repr__(self): return '<User: {}>'.format(self.user_name)
class Summary(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(1000), nullable=False) summary = db.Column(db.Text, nullable=False) user_email = db.Column(db.String(120)) def __repr__(self): return f"Summary('{self.title}', '{self.user_email}')"
class User(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(120), nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(120), nullable=False) def __repr__(self): return f"User('{self.email}')"
class IRQuery(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(1000), nullable=False) content = db.Column(db.Text, nullable=False) author = db.Column(db.String(1000), nullable=False) link = db.Column(db.String(2000), nullable=False) user_email = db.Column(db.String(120)) def __repr__(self): return f"IRQuery('{self.title}', '{self.user_email}')"
class BaseModel(db.Model): type_choice = ((1, '高匿'), (2, '匿名'), (3, '透明')) __abstract__ = True id = db.Column(db.Integer, primary_key=True) protocol = db.Column(db.String(10)) ip_port = db.Column(db.String(30), unique=True) server_area = db.Column(db.String(80)) res_time = db.Column(db.Integer) timeout_error = db.Column(db.Integer) alive_time = db.Column(db.DateTime) last_confirm = db.Column(db.DateTime) num_type = db.Column(db.SMALLINT) type = db.Column(db.String(10)) created_date = db.Column(db.DateTime, default=db.func.now()) def to_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns}
class Cat(db.Model): __tablename__ = 'cat' id = db.Column('id', db.Integer, primary_key=True) name = db.Column('name', db.String(100), nullable=False) def __init__(self, id, name): self.id = id self.name = name
class Qna(db.Model): id = db.Column(db.Integer, primary_key=True) question = db.Column(db.Text, nullable=False) title = db.Column(db.Text, nullable=False) answer = db.Column(db.Text, nullable=False) paragraph = db.Column(db.Text, nullable=False) user_email = db.Column(db.String(120)) def __repr__(self): return f"Qna('{self.question}, '{self.user_email}')"
class BusinessModel(db.Model): """Class to create a Business class object""" __tablename__ = 'businesses' id = db.Column(db.Integer, primary_key=True, autoincrement=True) business_name = db.Column(db.String(50), unique=True, nullable=False) category = db.Column(db.String(50), nullable=False) location = db.Column(db.String(50), nullable=False) profile = db.Column(db.String(256)) created_by = db.Column(db.Integer, db.ForeignKey('users.id')) creation_date = db.Column(db.DateTime, default=db.func.current_timestamp()) update_date = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp()) creator = db.relationship('User') reviews = db.relationship('ReviewModel', order_by='ReviewModel.id', cascade='all, delete-orphan') def __init__(self, business_name, category, location, profile, current_user): self.business_name = business_name self.category = category self.location = location self.profile = profile self.created_by = current_user @api.marshal_with(business_model) def as_dict(self): business_dict = { c.name: str(getattr(self, c.name)) for c in self.__table__.columns } business_dict['creator'] = self.creator.user_name return business_dict def __repr__(self): return '<Business: {}>'.format(self.business_name)
class Blacklist(db.Model): """Class for blacklisted tokens""" __tablename__ = 'blacklists' id = db.Column(db.Integer, primary_key=True, autoincrement=True) token = db.Column(db.String(500), unique=True, nullable=False) creation_date = db.Column(db.DateTime, default=db.func.current_timestamp()) def __init__(self, token): self.token = token def __repr__(self): return '<Token: {}'.format(self.token)