class FeedBackModel(db.Model): __tablename__ = "yitu-feedback" id_ = db.Column(db.BigInteger, primary_key=True) user_id = db.Column(db.Integer) contact = db.Column(db.Text) date = db.Column(db.DateTime) content = db.Column(db.Text)
class BookList(db.Model): __tablename__ = "book_lists" id_ = db.Column(db.Integer, primary_key=True) # 描述 description = db.Column(db.Text) # 标题 title = db.Column(db.Text) # 所属用户id user_id = db.Column(db.Integer, db.ForeignKey("users.id_"), index=True) books = db.relationship("Book", secondary=BookListR, backref="book_list")
class HotSearch(db.Model): __tablename__ = "hot_search" id_ = db.Column(db.Integer, primary_key=True) name = db.Column(db.Text) create_time = db.Column(db.DateTime, default=datetime.now)
class Book(db.Model): __tablename__ = "books" book_id = db.Column(db.Integer, primary_key=True) book_author = db.Column(db.Text) book_cover = db.Column(db.Text) book_rate = db.Column(db.Integer) book_content = db.Column(db.Text) book_publish = db.Column(db.Text) book_last_number = db.Column(db.Integer) book_key = db.Column(db.String(13), index=True) book_db_id = db.Column(db.Integer, unique=True) book_title = db.Column(db.Text) book_place = db.Column(db.Text) detail_data = db.Column(db.Text) hot_id = db.Column(db.Integer) is_hot = db.Column(db.Boolean, default=False) subscribers = db.relationship('Subscribe', foreign_keys=[Subscribe.book_id], backref=db.backref('book', lazy='joined'))
class HotBook(db.Model): __tablename__ = "hot_books" book_id = db.Column(db.Integer, primary_key=True) book_author = db.Column(db.Text) book_cover = db.Column(db.Text) book_rate = db.Column(db.Integer) book_content = db.Column(db.Text) book_publish = db.Column(db.Text) book_last_number = db.Column(db.Integer) book_key = db.Column(db.String(13), index=True) book_db_id = db.Column(db.Integer, unique=True) book_title = db.Column(db.Text) book_place = db.Column(db.Text) detail_data = db.Column(db.Text) hot_id = db.Column(db.Integer)
""" Author: Tyan boot <*****@*****.**> Date: 2017/6/23 书单 """ # -*- coding: utf-8 -*- from yitu import db BookListR = db.Table( "booklist_r", db.Column("list_id", db.Integer, db.ForeignKey("book_lists.id_")), db.Column("book_id", db.Integer, db.ForeignKey("books.book_id"))) class BookList(db.Model): __tablename__ = "book_lists" id_ = db.Column(db.Integer, primary_key=True) # 描述 description = db.Column(db.Text) # 标题 title = db.Column(db.Text) # 所属用户id user_id = db.Column(db.Integer, db.ForeignKey("users.id_"), index=True) books = db.relationship("Book", secondary=BookListR, backref="book_list")
class Subscribe(db.Model): __tablename__ = "subscribes" id_ = db.Column(db.BigInteger, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id_'), index=True) book_id = db.Column(db.Integer, db.ForeignKey('books.book_id'), index=True) timestamp = db.Column(db.DateTime, default=datetime.utcnow)
class User(db.Model): __tablename__ = "users" id_ = db.Column(db.Integer, primary_key=True) xh = db.Column(db.String(10), unique=True, index=True) name = db.Column(db.Text) password_hash = db.Column(db.Text) subscribing = db.relationship('Subscribe', foreign_keys=[Subscribe.user_id], backref=db.backref('user', lazy='joined')) book_lists = db.relationship("BookList", foreign_keys=BookList.user_id, backref=db.backref('user', lazy='joined')) @staticmethod def verify_token(token): from flask import current_app expire_time = current_app.config.get("EXPIRES_TIME") or 3600 token_key = current_app.config["APP_KEY"] s = TimedJSONWebSignatureSerializer(token_key, expires_in=expire_time) try: d = s.loads(token) user = User.query.get(d["uid"]) g.session_id = d["session"] return user except: return None @property def password(self): return None @password.setter def password(self, pwd): import hashlib s = hashlib.sha1() s.update(pwd.encode("ascii")) self.password_hash = s.hexdigest() def verify_password(self, pwd): import hashlib s = hashlib.sha1() s.update(pwd.encode("ascii")) if s.hexdigest() != self.password_hash: return False else: return True def generate_token(self, session): from flask import current_app expire_time = current_app.config.get("EXPIRES_TIME") or 3600 token_key = current_app.config["APP_KEY"] s = TimedJSONWebSignatureSerializer(token_key, expires_in=expire_time) d = s.dumps({"username": self.xh, "uid": self.id_, "session": session}) return d.decode("ascii")