Example #1
0
class Phrases(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    created = db.Column(db.DateTime, default=datetime.datetime.now)
    phrase = db.Column(db.String(140), index=True)

    def __repr__(self):
        return str(self.phrase)
Example #2
0
class UserGroup(db.Model):
    __tablename__ = "user_groups"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, unique=True)

    def __repr__(self):
        return "<{}>".format(self.name)
Example #3
0
class Permission(db.Model):
    """ 用户权限
    """
    __tablename__ = "article"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(100), unique=True, nullable=False)
    content = db.Column(db.Text, nullable=False)
    column = db.Column(db.String(20), nullable=False, default='news')
    author = db.Column(db.String(50), default='admin')
    article_status = db.Column(db.Integer, nullable=False, default=0)
    article_type = db.Column(db.Integer, nullable=False, default=0)
    create_time = db.Column(db.DateTime, nullable=False)
    pub_time = db.Column(db.DateTime)

    def to_json(self):
        pub_time = self.pub_time.strftime(
            "%Y-%m-%d %H:%S:%M") if self.pub_time else ''
        return {
            'id': self.id,
            'title': self.title,
            'content': self.content,
            'column': self.column,
            'author': self.author,
            'create_time': self.create_time.strftime("%Y-%m-%d %H:%S:%M"),
            'pub_time': pub_time
        }

    def __repr__(self):
        return f"<User '{self.title}'>"
Example #4
0
class Comment(db.Model):
    __tablename__ = "comments"

    id = db.Column(db.Integer, primary_key=True)
    author_name = db.Column(db.String(64), nullable=False)
    author_email = db.Column(db.String(64), nullable=False)
    text = db.Column(db.Text, nullable=False)
    posted_time = db.Column(db.DateTime, default=datetime.utcnow())

    def __repr__(self):
        return "{} | {} | {}".format(self.author_name, self.author_email,
                                     self.posted_time)
Example #5
0
class PlaceImage(db.Model):
    __tablename__ = "place_images"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64))
    path = db.Column(db.String(256), unique=True)
    thumbnail = db.Column(db.String(256), unique=True)

    place_id = db.Column(db.Integer, db.ForeignKey("places.id"))

    def __repr__(self):
        return "{} | {}".format(self.name, self.path)

    def add_thumbnail(self):
        print(self.path)
        self.thumbnail = re.sub(r'\.', '_thumb.', self.path)
        print(self.thumbnail)
Example #6
0
class Document(db.Model):
    """ 企业动态
    """
    __tablename__ = "document"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(100), unique=True, nullable=False)
    content_text = db.Column(db.Text, nullable=False)
    content_html = db.Column(db.Text, nullable=False)
    column_id = db.Column(db.Integer, db.ForeignKey('column.id'))
    author_id = db.Column(db.String(100), db.ForeignKey('user.uid'))
    status = db.Column(db.Integer, nullable=False, default=0)
    type = db.Column(db.Integer, nullable=False, default=0)
    create_time = db.Column(db.DateTime, nullable=False)
    pub_time = db.Column(db.DateTime)
    column = db.relationship('Column', backref=db.backref('document'))
    author = db.relationship('User', backref=db.backref('document'))


    @property
    def content(self):
        return self.content_text

    @content.setter
    def content(self, content_html):
        soup = BeautifulSoup(content_html, 'html.parser')
        self.content_text = soup.text

    def to_json(self):
        pub_time = self.pub_time.strftime("%Y-%m-%d %H:%S:%M") if self.pub_time else ''
        return {
            'id': self.id,
            'title': self.title,
            'content': self.content_text,
            'content_html': self.content_html,
            'column': self.column.title,
            'column_id': self.column_id,
            'author': self.author,
            'create_time': self.create_time.strftime("%Y-%m-%d %H:%S:%M"),
            'pub_time': pub_time,
            'status': self.status
        }

    def __repr__(self):
        return f"<Document '{self.title}'>"
Example #7
0
class User(UserMixin, db.Model):
    __tablename__ = "users"
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String, unique=True)
    email = db.Column(db.String, unique=True)
    password_hash = db.Column(db.String(128), unique=True)
    confirmed = db.Column(db.Boolean, default=False)

    groups = relationship("UserGroup", secondary=user2group,
                          backref=backref('users', order_by=id))

    def __repr__(self):
        return "<{}>".format(self.username)

    @property
    def password(self):
        raise AttributeError("Password is not readable")

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

    def verify_password(self, password):
        return check_password_hash(self.password_hash, password)

    def generate_confirmation_token(self, expiration=3600):
        s = Serializer(current_app.config['SECRET_KEY'], expiration)
        return s.dumps({'confirm': self.id})

    def confirm(self, token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            data = s.loads(token)
        except:
            return False

        if data.get("confirm") != self.id:
            return False

        self.confirmed = True
        current_app.logger.info("User {} confirmed".format(self.username))
        db.session.add(self)
        db.session.commit()
        return True
Example #8
0
class Column(db.Model):
    """ 企业动态
    """
    __tablename__ = "column"

    id = db.Column(db.String(100), primary_key=True, nullable=False)
    title = db.Column(db.String(100), nullable=False)
    parent_id = db.Column(db.String(100), nullable=False, default='root')
    type = db.Column(db.String(20))

    __table_args__ = (
        UniqueConstraint('title', 'parent_id'),  # 同一栏目下目录标题唯一
    )

    def to_json(self):
        return {
            'id': self.id,
            'title': self.title,
            'parent_id': self.parent_id,
            'type': self.type,
        }

    def __repr__(self):
        return f"<Column '{self.id}'>"
Example #9
0
class User(db.Model):
    """ 用户表
    """
    __tablename__ = "user"

    uid = db.Column(db.String(100), primary_key=True, default=uuid1().hex)
    username = db.Column(db.String(100), unique=True)
    email = db.Column(db.String(100), unique=True)
    password_hash = db.Column(db.String(100))
    role = db.Column(db.String(100), default='user')
    registration_time = db.Column(db.DateTime, default=datetime.now())
    status = db.Column(db.Integer, default=0, nullable=False)

    @property
    def password(self):
        raise AttributeError('password: write-only field')

    @password.setter
    def password(self, password):
        self.password_hash = flask_bcrypt.generate_password_hash(
            password).decode('utf-8')

    def check_password(self, password):
        return flask_bcrypt.check_password_hash(self.password_hash, password)

    def to_json(self):
        registration_time = self.registration_time.strftime(
            "%Y-%m-%d %H:%S:%M") if self.registration_time else ''
        return {
            'uid': self.uid,
            'username': self.username,
            'email': self.email,
            'role': self.role,
            'registration_time': registration_time,
            'status': self.status,
            'avatar': '',
        }

    def __repr__(self):
        return f"<User '{self.username}'>"
Example #10
0
class Tour(db.Model):
    __tablename__ = "tours"
    id = db.Column(db.Integer, primary_key=True)

    title = db.Column(db.String(64), unique=True)
    price = db.Column(db.String(64))
    slug = db.Column(db.String(256), unique=True)

    duration = db.Column(db.String(64))
    min_people_number = db.Column(db.Integer)
    distance = db.Column(db.Integer)

    places = db.relationship("Place", secondary=places2tours,
                             backref="places")

    comments = db.relationship(Comment, secondary=comments2tours)

    def __repr__(self):
        return self.title

    def generate_slug(self, title):
        """ Generate slug by title """
        self.slug = slugify_ru(title, to_lower=True)
Example #11
0
from apps.main import db
from apps.comments.models import Comment
from slugify import slugify_ru
from sqlalchemy import event


places2tours = db.Table("places2tours", db.Model.metadata,
                        db.Column("place_id", db.Integer,
                                  db.ForeignKey("places.id")),
                        db.Column("tour_id", db.Integer,
                                  db.ForeignKey("tours.id")))

comments2tours = db.Table("comments2tours", db.Model.metadata,
                          db.Column("comment_id", db.Integer,
                                    db.ForeignKey("comments.id")),
                          db.Column("tour_id", db.Integer,
                                    db.ForeignKey("tours.id")))


class Tour(db.Model):
    __tablename__ = "tours"
    id = db.Column(db.Integer, primary_key=True)

    title = db.Column(db.String(64), unique=True)
    price = db.Column(db.String(64))
    slug = db.Column(db.String(256), unique=True)

    duration = db.Column(db.String(64))
    min_people_number = db.Column(db.Integer)
    distance = db.Column(db.Integer)
Example #12
0
class Place(db.Model):
    __tablename__ = "places"
    __table_args__ = (CheckConstraint('rating >= 0 and rating <= 5',
                                      name="rating_0_5"), )

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(64), unique=True)
    snippet = db.Column(db.Text, index=True)
    description = db.Column(db.Text, index=True)

    rating = db.Column(db.Integer)
    price = db.Column(db.String(64))
    schedule = db.Column(db.Text)
    info = db.Column(db.Text)
    address = db.Column(db.String(128))
    location = db.Column(db.String(64))

    slug = db.Column(db.String(128), unique=True)

    comments = db.relationship(Comment, secondary=comments2places)
    images = db.relationship("PlaceImage", backref="place")

    timestamp = db.Column(db.DateTime, default=datetime.utcnow)

    def __repr__(self):
        return self.title

    def generate_slug(self, title):
        """ Generate slug by title """
        self.slug = slugify_ru(title, to_lower=True)
Example #13
0
from flask import current_app
from apps.main import db, login_manager
from werkzeug.security import generate_password_hash, check_password_hash
from flask_login import UserMixin
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from sqlalchemy.orm import relationship, backref


# Required by flask-login.
@login_manager.user_loader
def load_user(user_id):
    return User.query.get(int(user_id))


user2group = db.Table('user2group', db.Model.metadata,
                      db.Column("user_id", db.Integer,
                                db.ForeignKey("users.id")),
                      db.Column("group_id", db.Integer,
                                db.ForeignKey("user_groups.id")))


class User(UserMixin, db.Model):
    __tablename__ = "users"
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String, unique=True)
    email = db.Column(db.String, unique=True)
    password_hash = db.Column(db.String(128), unique=True)
    confirmed = db.Column(db.Boolean, default=False)

    groups = relationship("UserGroup", secondary=user2group,
                          backref=backref('users', order_by=id))
Example #14
0
class Srt(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    set_of_words = db.Column(db.Text())
    list_of_words = db.Column(db.Text())
Example #15
0
class UpperWords(db.Model):
    word = db.Column(db.String(40), index=True, primary_key=True, unique=True)

    def __repr__(self):
        return self.word