Exemplo n.º 1
0
from webapp.extensions import db

from sqlalchemy.dialects.postgresql import TEXT

# Associatoin table
session_articles = db.Table(
    'session_articles',
    db.Column('session_id',
              db.Integer,
              db.ForeignKey('session.id'),
              primary_key=True),
    db.Column('article_id',
              db.Integer,
              db.ForeignKey('article.id'),
              primary_key=True))


class Article(db.Model):
    __tablename__ = 'article'

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(80), nullable=False)
    author = db.Column(db.String(80))
    full_text = db.Column(TEXT, nullable=False)
    link = db.Column(db.String(250), nullable=False)

    sessions = db.relationship('Session',
                               secondary=session_articles,
                               lazy='subquery',
                               backref=db.backref('articles', lazy=True))
Exemplo n.º 2
0
from webapp.extensions import bcrypt, db, loginmanager
from flask_login import UserMixin
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from flask import current_app
from datetime import datetime

from markdown import markdown

import bleach

tags = db.Table('post_tags',
                db.Column('post_id', db.Integer, db.ForeignKey('post.id')),
                db.Column('tag_id', db.Integer, db.ForeignKey('tag.id')))


@loginmanager.user_loader
def load_user(user_id):
    return User.query.get(int(user_id))


class User(UserMixin, db.Model):

    id = db.Column(db.Integer(), primary_key=True)
    email = db.Column(db.String(64), unique=True, index=True)
    location = db.Column(db.String(64))
    about_me = db.Column(db.Text())
    member_since = db.Column(db.DateTime(), default=datetime.utcnow)
    last_seen = db.Column(db.DateTime(), default=datetime.utcnow)
    name = db.Column(db.String(64), unique=True)
    username = db.Column(db.String(255))
    password = db.Column(db.String(255))
Exemplo n.º 3
0
from webapp.extensions import db
from werkzeug.security import check_password_hash, generate_password_hash
from flask_login import UserMixin, current_user
from sqlalchemy.sql import func
from sqlalchemy.sql.expression import or_, and_
from datetime import datetime
from flask import session

follows = db.Table('follows', db.Column('user_id', db.ForeignKey('user.id')),
                   db.Column('follow_id', db.ForeignKey('user.id')))


class User(db.Model, UserMixin):
    id = db.Column(db.Integer(), primary_key=True)
    username = db.Column(db.String(20), unique=True)
    bio = db.Column(db.String(100))
    gender = db.Column(db.SmallInteger(), default=0)  # 1 男 2 女 0 未填写
    email = db.Column(db.String(50), unique=True, index=True)
    password = db.Column(db.String(255))
    reg_date = db.Column(db.TIMESTAMP(), server_default=func.now())
    last_login_date = db.Column(db.DateTime())
    wb_uid = db.Column(db.String(20))
    avatar = db.Column(db.String(500))
    tasks = db.relationship('Task', backref='user', lazy='dynamic')

    comments = db.relationship('Comment', backref='user', lazy='dynamic')

    following = db.relationship('User',
                                secondary=follows,
                                primaryjoin=(follows.c.user_id == id),
                                secondaryjoin=(follows.c.follow_id == id),
Exemplo n.º 4
0
from webapp.extensions import db
# from webapp.models.study_block import Study_Block

# Associatoin table
course_list = db.Table(
    'course_list',
    db.Column('course_id',
              db.String(7),
              db.ForeignKey('course.code'),
              primary_key=True),
    db.Column('user_id',
              db.Integer,
              db.ForeignKey('user.id'),
              primary_key=True))


class Course(db.Model):
    __tablename__ = 'course'

    code = db.Column(db.String(7), primary_key=True)
    title = db.Column(db.String(80), nullable=False)
    credits = db.Column(db.Integer, nullable=False)

    # many -to many with Users
    users = db.relationship('User',
                            secondary=course_list,
                            lazy='subquery',
                            backref=db.backref('courses', lazy=True))
    sessions = db.relationship('Session', back_populates='course')

    def __repr__(self):
Exemplo n.º 5
0
# -*- coding: utf-8 -*-

from webapp.extensions import db

from sqlalchemy.orm import class_mapper

from sqlalchemy.dialects.mysql import LONGTEXT

from jieba.analyse.analyzer import ChineseAnalyzer


tags = db.Table(
    'blog_tags',
    db.Column('blog_id', db.Integer, db.ForeignKey('blogs.id')),
    db.Column('tag_id', db.Integer, db.ForeignKey('tags.id'))
)


class Blog(db.Model):
    __tablename__ = 'blogs'
    __searchable__ = ['title', 'content']
    __analyzer__ = ChineseAnalyzer()

    id = db.Column(db.Integer, primary_key=True)
    time = db.Column(db.BigInteger)
    author = db.Column(db.String(255))
    title = db.Column(db.String(255), unique=True)
    content = db.Column(LONGTEXT)

    comments = db.relationship('Comment', backref='blogs', lazy='dynamic')
    tags = db.relationship('Tag', secondary=tags, backref=db.backref('blogs', lazy='dynamic'))
Exemplo n.º 6
0
# -*- coding: utf-8 -*-

from webapp.extensions import db

from functools import reduce
from operator import or_

from jieba.analyse.analyzer import ChineseAnalyzer

from flask_security import UserMixin

import time

roles_users = db.Table(
    'roles_users', db.Column('user_id', db.Integer, db.ForeignKey('users.id')),
    db.Column('role_id', db.Integer, db.ForeignKey('roles.id')))


class User(db.Model, UserMixin):
    __tablename__ = 'users'
    __searchable__ = ['username']
    __analyzer__ = ChineseAnalyzer()

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(255), unique=True)
    password = db.Column(db.String(255))
    email = db.Column(db.String(255))
    create_time = db.Column(db.String(255))
    online = db.Column(db.Boolean, default=False)
    last_seen_at = db.Column(db.Integer, default=time.time())
    updated_at = db.Column(db.Integer,