コード例 #1
0
ファイル: book.py プロジェクト: simonli/Pybookstore
class BookUploadRecord(db.Model):
    __tablename__ = 'book_upload_records'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    book_edition_id = db.Column(db.Integer, db.ForeignKey('book_editions.id'))
    create_time = db.Column(db.DateTime, default=datetime.now)

    def __init__(self, *args, **kwargs):
        super(BookUploadRecord, self).__init__(*args, **kwargs)
コード例 #2
0
ファイル: book.py プロジェクト: simonli/Pybookstore
class BookEditionComment(db.Model):
    __tablename__ = 'book_edition_comments'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    book_edition_id = db.Column(db.Integer, db.ForeignKey('book_editions.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))  # 评价人
    at_user_id = db.Column(db.Integer, db.ForeignKey('users.id'))  # 评价哪个用户
    comment = db.Column(db.Text)
    create_time = db.Column(db.DateTime, default=datetime.now)

    def __init__(self, *args, **kwargs):
        super(BookEditionComment, self).__init__(*args, **kwargs)
コード例 #3
0
ファイル: book.py プロジェクト: simonli/Pybookstore
class BookPushRecord(db.Model):
    __tablename__ = 'book_push_records'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    book_edition_id = db.Column(db.Integer, db.ForeignKey('book_editions.id'))
    from_platform = db.Column(db.String(255))
    create_time = db.Column(db.DateTime, default=datetime.now)
    use_time = db.Column(db.Integer, default=0)
    delivery_status = db.Column(db.Integer, default=1)  # 0-失败 1-成功 3-未知
    destination_email = db.Column(db.String(255), nullable=False)

    def __init__(self, *args, **kwargs):
        super(BookPushRecord, self).__init__(*args, **kwargs)
コード例 #4
0
ファイル: book.py プロジェクト: simonli/Pybookstore
class BookEdition(db.Model):
    __tablename__ = 'book_editions'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    book_id = db.Column(db.Integer, db.ForeignKey('books.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))  # 上传者
    filename = db.Column(db.String(255), nullable=False)
    original_filename = db.Column(db.String(255))
    size = db.Column(db.Integer)  # byte字节
    push_count = db.Column(db.Integer, default=0)
    download_count = db.Column(db.Integer, default=0)
    checksum = db.Column(db.String(255))
    create_time = db.Column(db.DateTime, default=datetime.now)
    book_edition_comments = db.relationship('BookEditionComment',
                                            backref='book_edition',
                                            lazy='dynamic')

    def __init__(self, *args, **kwargs):
        super(BookEdition, self).__init__(*args, **kwargs)
コード例 #5
0
ファイル: user.py プロジェクト: simonli/Pybookstore
class PushSetting(db.Model):
    __tablename__ = 'push_settings'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    email = db.Column(db.String(255))
    create_time = db.Column(db.DateTime, default=datetime.now)
    is_default = db.Column(db.Integer, default=0)  # 1 is default

    def __init__(self, *args, **kwargs):
        super(PushSetting, self).__init__(*args, **kwargs)
コード例 #6
0
ファイル: user.py プロジェクト: simonli/Pybookstore
class UserCheckinRecord(db.Model):
    __tablename__ = 'user_checkin_records'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    score = db.Column(db.Integer, default=0)
    total_score = db.Column(db.Integer, default=0)
    create_time = db.Column(db.DateTime, default=datetime.now)  # 下载时间

    def __init__(self, *args, **kwargs):
        super(UserCheckinRecord, self).__init__(*args, **kwargs)
コード例 #7
0
ファイル: user.py プロジェクト: simonli/Pybookstore
class UserPoint(db.Model):
    __tablename__ = 'user_points'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    point = db.Column(db.Integer, default=0)
    point_source = db.Column(db.String(30))
    source_id = db.Column(db.Integer)
    create_time = db.Column(db.DateTime, default=datetime.now)

    def __init__(self, *args, **kwargs):
        super(UserPoint, self).__init__(*args, **kwargs)
コード例 #8
0
ファイル: user.py プロジェクト: simonli/Pybookstore
class User(UserMixin, db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    username = db.Column(db.String(50),
                         nullable=False,
                         unique=True,
                         index=True)
    _password_hash = db.Column('password',
                               db.String(255),
                               nullable=False,
                               server_default=u'')
    email = db.Column(db.String(255), nullable=False)
    avatar = db.Column(db.String(255))
    last_login_time = db.Column(db.DateTime, default=datetime.now)
    last_login_ip = db.Column(db.String(50), default='')
    login_count = db.Column(db.Integer, nullable=False, default=0)
    is_delete = db.Column(db.Integer, default=0)  # o-OK, 1-deleted
    role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
    create_time = db.Column(db.DateTime, default=datetime.now())
    push_settings = db.relationship(PushSetting,
                                    backref='user',
                                    lazy='dynamic')
    point_count = db.Column(db.Integer, default=0)  # 总积分

    def __init__(self, *args, **kwargs):
        super(User, self).__init__(*args, **kwargs)

    def __repr__(self):
        return '<User %r>' % self.username

    @property
    def password(self):
        raise AttributeError('password is not a readable attribute.')

    @password.setter
    def password(self, password):
        self._password_hash = bcrypt.generate_password_hash(password)

    @property
    def is_admin(self):
        return self.can(Permission.ADMIN)

    @property
    def is_pro(self):
        return self.can(Permission.PRO)

    def verify_password(self, password):
        return bcrypt.check_password_hash(self._password_hash, password)

    def can(self, permissions):
        return self.role is not None and (self.role.permissions
                                          | permissions) == permissions

    @staticmethod
    def initial_admin():
        u = User()
        u.username = '******'
        u.password = '******'
        u.email = 'admin@localhost'
        u.role = Role.query.filter_by(name='Admin').first()

        u1 = User()
        u1.username = '******'
        u1.password = '******'
        u1.email = '*****@*****.**'
        u1.role = Role.query.filter_by(name='Admin').first()

        db.session.add(u)
        db.session.add(u1)
        db.session.commit()
コード例 #9
0
ファイル: book.py プロジェクト: simonli/Pybookstore
# -*- coding:utf-8 -*-
from datetime import datetime

from bookstore.extensions import db

books_tags = db.Table(
    'book_tag', db.Column('tag_id', db.Integer, db.ForeignKey('tags.id')),
    db.Column('book_id', db.Integer, db.ForeignKey('books.id')))

books_categories = db.Table(
    'book_category',
    db.Column('category_id', db.Integer, db.ForeignKey('categories.id')),
    db.Column('book_id', db.Integer, db.ForeignKey('books.id')))


class Book(db.Model):
    __tablename__ = 'books'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    title = db.Column(db.String(255), nullable=False, index=True)  # 书名
    author = db.Column(db.String(255))  # 作者
    logo = db.Column(db.String(255))  # 书的封面
    translator = db.Column(db.String(255))  # 译者
    publisher = db.Column(db.String(255))  # 出版社
    isbn = db.Column(db.String(100))  # ISBN号
    douban_id = db.Column(db.Integer, unique=True, index=True)  # 豆瓣ID
    douban_url = db.Column(db.String(255))
    douban_rating_score = db.Column(db.Integer, default=0)  # 豆瓣得分
    douban_rating_people = db.Column(db.Integer, default=0)  # 豆瓣评论人数
    book_catalog = db.Column(db.Text)  # 图书目录
    book_intro = db.Column(db.Text)  # 内容简介
    author_intro = db.Column(db.Text)  # 作者简介