class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) posts = db.relationship('Post', backref='author', lazy=True) def get_reset_token(self, expires_sec=1800): s = Serializer(current_app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = Serializer(current_app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')"
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) password_hash = db.Column(db.String(128)) posts = db.relationship('Post', backref='author', lazy='dynamic') about_me = db.Column(db.String(140)) last_seen = db.Column(db.DateTime, default=datetime.utcnow) followed = db.relationship( 'User', secondary=followers, primaryjoin=(followers.c.follower_id == id), secondaryjoin=(followers.c.followed_id == id), backref=db.backref('followers', lazy='dynamic'), lazy='dynamic' ) def __repr__(self): return '<User {}>'.format(self.username) def set_password(self, password): self.password_hash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password_hash, password) def avatar(self, size): digest = md5(self.email.lower().encode('utf-8')).hexdigest() return 'https://www.gravatar.com/avatar/{}?d=identicon&s={}'.format( digest, size) def follow(self, user): if not self.is_following(user): self.followed.append(user) def unfollow(self, user): if self.is_following(user): self.followed.remove(user) def is_following(self, user): return self.followed.filter( followers.c.followed_id == user.id).count() > 0 def followed_posts(self): followed = Post.query.join( followers, (followers.c.followed_id == Post.user_id)).filter( followers.c.follower_id == self.id) own = Post.query.filter_by(user_id=self.id) return followed.union(own).order_by(Post.timestamp.desc()) def get_reset_password_token(self, expires_in=600): return jwt.encode( {'reset_password': self.id, 'exp': time() + expires_in}, app.config['SECRET_KEY'], algorithm='HS256').decode('utf-8') @staticmethod def verify_reset_password_token(token): try: id = jwt.decode(token, app.config['SECRET_KEY'], algorithms=['HS256'])['reset_password'] except: return return User.query.get(id)
class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64)) password_hash = db.Column(db.String(128)) last_seen = db.Column(db.DateTime, default=datetime.utcnow) def __repr__(self): return '<User {}>'.format(self.username) def check_password(self, password): return check_password_hash(self.password_hash, password) def set_password(self, password): self.password_hash = generate_password_hash(password) def avatar(self, size): digest = md5(self.email.lower().encode('utf-8')).hexdigest() return 'https://www.gravatar.com/avatar/{}?d=identicon&s={}'.format( digest, size) def to_dict(self): username = self.username lastseen = self.last_seen dict = {'username': username, 'lastseen': lastseen} return dict
class Question(db.Model): __tablename__ = 'question' id = db.Column(db.Integer, primary_key=True, autoincrement=True) question_title = db.Column(db.String(100), nullable=False) content = db.Column(db.Text, nullable=False) create_time = db.Column(db.DateTime, default=datetime.now) author_name = db.Column(db.String(64), db.ForeignKey('customer.username')) author = db.relationship('Customer', backref=db.backref('realquestions'))
class Employee(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) key = db.Column(db.String(120), index=True) password_hash = db.Column(db.String(128)) def __repr__(self): return '<Employee {}>'.format(self.username)
class Resource(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(64), index=True, unique=True) tag = db.Column(db.String(10)) description = db.Column(db.String(140)) download = db.Column(db.Integer, default=0) def __repr__(self): return '<name {}>'.format(self.name)
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(150), nullable=False) posts = db.relationship('Post', backref='author', lazy=True) def __repr__(self): return 'User name is %r' % self.username
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) body = db.Column(db.String(140)) timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) name = db.Column(db.String(140)) user_id = db.Column(db.Integer, db.ForeignKey('customer.id')) def __repr__(self): return '<{}>'.format(str(self.timestamp)[0:16])
class Friend_link(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) link = db.Column(db.String(120)) def __repr__(self): return '<Friend link %r>' % self.name def __unicode__(self): return self.name
class Blog(db.Model): __tablename__ = 'blog' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(50)) tag = db.Column(db.String(10)) time = db.Column(db.String) click = db.Column(db.Integer, default=0) def __repr__(self): return '<Blog {}>'.format(self.title)
class Posts(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(64)) post_body = db.Column(db.String(1024)) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User') create_date = db.Column(db.DateTime, default=datetime.utcnow) yn = db.Column(db.SmallInteger, default=1) def __repr__(self): "<post: {}>".format(self.title)
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(18), unique=True, nullable=False) email = db.Column(db.String(50), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default="default.jpg") password = db.Column(db.String(60), nullable=False) posts = db.relationship("Post", backref="author", lazy=True) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')"
class Pet(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(64), index=True) type = db.Column(db.String(64), index=True) old = db.Column(db.Integer, index=True) gender = db.Column(db.String(64), index=True) customer_id = db.Column(db.Integer, db.ForeignKey('customer.id')) appointments = db.relationship('Appointment', backref='pet', lazy='dynamic') def __repr__(self): return '<Pet {}>'.format(self.name)
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) posts = db.relationship('Post', backref='author', lazy=True) def __repr__(self): return "User('{0}', '{1}', '{2}')".format(self.username, self.email, self.image_file, self.password)
class NewAppointment(db.Model): id = db.Column(db.Integer, primary_key=True) applicant = db.Column(db.String(20), index=True, nullable=False) date = db.Column(db.DateTime, index=True, nullable=False) petType = db.Column(db.Integer, index=True, nullable=False) doctor = db.Column(db.Integer, index=True, nullable=False) phoneNo = db.Column(db.String(20), index=True, nullable=False) comment = db.Column(db.String, default="") user_id = db.Column(db.Integer, db.ForeignKey('customer.id')) cus_appoint = db.relationship('Customer', backref=db.backref('Customer')) def __repr__(self): return '<User {}>'.format(self.username)
class Customer(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) password_hash = db.Column(db.String(128)) phone = db.Column(db.Integer, index=True) firstname = db.Column(db.String(64), index=True) lastname = db.Column(db.String(64), index=True) pets = db.relationship('Pet', backref='owner', lazy='dynamic') appointments = db.relationship('Appointment', backref='customer', lazy='dynamic') posts = db.relationship('Post', backref='author', lazy='dynamic') def __repr__(self): return '<User {}>'.format(self.username)
class Entry(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100)) content = db.Column(db.Text) content_html = db.Column(db.Text) fragment = db.Column(db.Text) #内容片段, 用于主页显示 status = db.Column(db.Integer, default=1) #完成:1, 失败0, 草稿:-1 (暂时无用) create_time = db.Column(db.DateTime, index=True, default=datetime.now()) modified_time = db.Column(db.DateTime, default=datetime.now()) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) category = db.relationship('Category', backref=db.backref('entries', lazy='dynamic'), lazy='select') category_id = db.Column(db.Integer, db.ForeignKey('category.id')) tag = db.relationship('Tag', secondary=tag_entry, backref=db.backref('entries', lazy='dynamic')) view_count = db.Column(db.Integer, default=0) @staticmethod def on_changed_content(target, value, oldvalue, initator): if CONTENT_FORMAT == 'html': target.content_html = value else: target.content_html = md2html(text=value) def __repr__(self): return '<Entry %r>' % self.title def __unicode__(self): return self.title
class Post(SearchableMixin,db.Model): __searchable__ = ['body','title'] id = db.Column(db.Integer,primary_key=True) title = db.Column(db.String(80),nullable=False) body = db.Column(db.Text,nullable=False) body_html = db.Column(db.Text) summary = db.Column(db.Text) body_summary = db.Column(db.Text) timestamp = db.Column(db.DateTime,index=True,default=datetime.utcnow) html_body = db.Column(db.Text) user_id = db.Column(db.Integer,db.ForeignKey('user.id')) @staticmethod def delete(post=None,id=None): if post is None: post = Post.query.filter_by(id=id).first() db.session.delete(post) db.session.commit() @staticmethod def on_body_change(target,value,oldvalue,initiator): allowed_tags = ['a', 'abbr', 'acronym', 'b', 'blockquote', 'code','em', 'i', 'li', 'ol', 'pre', 'strong', 'ul','h1', 'h2', 'h3', 'p'] attrs = { '*':['class'],} target.body_html = bleach.linkify(bleach.clean(markdown(value), tags=allowed_tags, strip=True, attributes=attrs)) pattern = re.compile(r'<[^>]+>', re.S) summary = pattern.sub('', target.body_html) summary = (summary[0:40] + '...') if len(summary) >= 40 else summary target.body_summary = summary def __repr__(self): return '<Post {}>'.format(self.title)
class Suggesstion(db.Model): id = db.Column(db.Integer, primary_key=True) suggestion = db.Column(db.String(140)) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __repr__(self): return '<suggestion {}>'.format(self.suggestion)
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) login = db.Column(db.String(80), unique=True) nickname = db.Column(db.String(80), unique=True) password = db.Column(db.String(64), unique=True) email = db.Column(db.String(120), unique=True) role = db.Column(db.SmallInteger, default=ROLE_ADMIN) entry = db.relationship('Entry', backref='author', lazy='dynamic') about_me = db.Column(db.String(250)) last_seen = db.Column(db.DateTime) # Flask-Login integration def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def get_id(self): return self.id def get_id(self): return unicode(self.id) # #防止昵称相同 # @staticmethod # def make_unique_nickname(nickname): # if User.query.filter_by(nickname=nickname).first() == None: # return nickname # virsion = 2 # while True: # new_nickname = nickname + str(virsion) # if User.query.filter_by(nickname=new_nickname).first() == None: # break # virsion += 1 # return new_nickname def __repr__(self): return '<User %r>' % self.nickname def __unicode__(self): return self.nickname
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) content = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return 'Post %r' % self.title
class User(UserMixin,db.Model): id = db.Column(db.Integer,primary_key=True) username = db.Column(db.String(64),index=True,unique=True) email = db.Column(db.String(120),index=True,unique=True) password_hash = db.Column(db.String(128)) posts = db.relationship('Post',backref='author',lazy='dynamic') about_me = db.Column(db.String(140)) last_seen = db.Column(db.DateTime,default=datetime.utcnow) followed = db.relationship( 'User',secondary=followers, primaryjoin=(followers.c.follower_id == id), secondaryjoin=(followers.c.followed_id == id), backref=db.backref('followers',lazy='dynamic'),lazy='dynamic') def set_password(self,password): self.password_hash = generate_password_hash(password) def check_password(self,password): return check_password_hash(self.password_hash,password) def avatar(self,size): digest = md5(self.email.lower().encode('utf-8')).hexdigest() return 'https://www.gravatar.com/avatar/{}?d=identicon&s={}'.format(digest,size) def follow(self,user): if not self.is_following(user): self.followed.append(user) def unfollow(self,user): if self.is_following(user): self.followed.remove(user) def is_following(self,user): return self.followed.filter(followers.c.followed_id == user.id).count() > 0 def followed_posts(self): followed = Post.query.join( followers,(followers.c.followed_id == Post.user_id)).filter( followers.c.follower_id == self.id) own = Post.query.filter_by(user_id = self.id) return followed.union(own).order_by(Post.timestamp.desc()) def __repr__(self): return '<User {}>'.format(self.username)
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100)) body = db.Column(db.Text) timestamp = db.Column(db.DateTime, index=True, default=datetime.now) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __repr__(self): return '<Post {}>'.format(self.body)
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer,db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Post('{self.title}','{self.date_posted}')"
class Post(db.Model): __tablename__ = 'posts' id = db.Column(db.Integer, primary_key=True) body = db.Column(db.String(140)) timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) def __repr__(self): return '<Post {}>'.format(self.body)
class Category(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80), unique=True) def __repr__(self): return '<Category %r>' % self.name def __unicode__(self): return self.name
class Comment(db.Model): __tablename__ = 'comment' id = db.Column(db.Integer, primary_key=True) information = db.Column(db.String(100)) blog_id = db.Column(db.Integer, db.ForeignKey('blog.id')) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __repr__(self): return '<Comment {}>'.format(self.information)
class Choice(db.Model,UserMixin): id = db.Column(db.Integer, primary_key = True) choice = db.Column(db.String(64), unique=True, index=True) def __init__(self, name): self.choice = choice def as_dict(self): return {'choice': self.choice}
class Employee(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) password_hash = db.Column(db.String(128)) email = db.Column(db.String(120), index=True, unique=True) emid = db.Column(db.String(120), unique=True) phone = db.Column(db.String(120), index=True, unique=True) animal = db.Column(db.String(120), index=True) workplace = db.Column(db.String(120), index=True)
class BlogModel(db.Model): __tablename__ = 'blog' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30), unique=True, nullable=False) creator_id = db.Column(db.Integer, db.ForeignKey('user.id')) date_of_creation = db.Column(db.DateTime, default=datetime.now) is_active = db.Column(db.Boolean, default=False) posts = db.relationship('PostModel', backref='blog', lazy=True) def __repr__(self): return f"Blog : {self.name}"