class Followrelationship(db.Model): __tablename__ = 'follow' id = db.Column(db.Integer, primary_key=True, autoincrement=True) follower_id = db.Column(db.Integer, db.ForeignKey('customer.id')) followed_id = db.Column(db.Integer, db.ForeignKey('employee.id')) follower = db.relationship('Customer', backref=db.backref('follower')) followed = db.relationship('Employee', backref=db.backref('followed'))
class UserModel(db.Model, UserMixin): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(20), unique=True, nullable=False) password = db.Column(db.String(256), nullable=False) first_name = db.Column(db.String(20), nullable=False) last_name = db.Column(db.String(20), nullable=False) dob = db.Column(db.DateTime, nullable=False) gender = db.Column(db.String, nullable=False) mobile_no = db.Column(db.String(10), unique=True, nullable=False) profile_pic = db.Column(db.String, default='default_profile.jpg') blogs = db.relationship('BlogModel', backref='creator', lazy=True) def __init__(self, email, password, first_name, last_name, mobile_no, gender, dob, profile_pic): self.username = str(email).split('@')[0] self.email = email self.password = bcrypt.generate_password_hash(password).decode('utf-8') self.first_name = first_name self.last_name = last_name self.mobile_no = mobile_no self.gender = gender self.dob = dob self.profile_pic = profile_pic def __repr__(self): return f"Hello I am {self.username}" def check_password(self, password): return bcrypt.check_password_hash(self.password, password)
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 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): 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 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) 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) 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 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 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 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 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 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 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 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(self.name, self.body, str(self.timestamp)[0:16])
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 AnswerQuestion(db.Model): __tablename__ = 'answer_question' id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.Text, nullable=False) create_time = db.Column(db.DateTime, default=datetime.now) author_id = db.Column(db.Integer, db.ForeignKey('employee.id')) answer_question_id = db.Column(db.Integer, db.ForeignKey('question.id')) author = db.relationship('Employee', backref=db.backref('realanswer')) question = db.relationship('Question', backref=db.backref('questionAnswer'))
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 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 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}"
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 PostModel(db.Model): __tablename__ = 'post' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(50), nullable=False) content = db.Column(db.Text, nullable=False) created_on = db.Column(db.DateTime, default=datetime.now) blog_id = db.Column(db.Integer, db.ForeignKey('blog.id')) def __repr__(self): return f"post : {self.title}"
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 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 Appointment(db.Model): id = db.Column(db.Integer, primary_key=True) type = db.Column(db.String(64),index=True) date = db.Column(db.String(64), index=True) time = db.Column(db.String(64), index=True) city = db.Column(db.String(64), index=True) details = db.Column(db.String(120), index=True) status = db.Column(db.String(64), index=True, default='Submitted') customer_id = db.Column(db.Integer, db.ForeignKey('customer.id')) pet_id = db.Column(db.Integer, db.ForeignKey('pet.id')) def __repr__(self): return '{}'.format(str(self.date)[0:10])
class BlogPost(db.Model): users = db.relationship(User) id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) title = db.Column(db.String(140), nullable=False) text = db.Column(db.Text, nullable=False) def __init__(self, title, text, user_id): self.title = title self.text = text self.user_id =user_id def __repr__(self): return f"Post Id: {self.id} --- Date: {self.date} --- Title: {self.title}"
class Entry(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100)) content = 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) def __repr__(self): return '<Entry %r>' % self.title def __unicode__(self): return self.title
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 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)