示例#1
0
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
示例#2
0
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'))
示例#3
0
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'))
示例#4
0
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)        
示例#5
0
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.String(20), index=True, nullable=False)
    appoint_time = db.Column(db.Integer, index=True, nullable=False)
    petType = db.Column(db.Integer, index=True, nullable=False)
    petName = db.Column(db.String(20), 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(20), default="")
    condition = db.Column(db.Integer, index=True, default=1, nullable=False)
    op_date = db.Column(db.String(20), index=True)
    op_time = db.Column(db.Integer, index=True)
    app_type = db.Column(db.Integer, index=True, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('customer.id'))
    cus_appoint = db.relationship('Customer', backref=db.backref('Customer'))

    def to_dict(self):
        result = {}
        for key in self.__mapper__.c.keys():
            if getattr(self, key) is not None:
                result[key] = str(getattr(self, key))
            else:
                result[key] = getattr(self, key)
        return result

    def to_json(all_vendors):
        v = [ven.to_dict() for ven in all_vendors]
        return v
示例#6
0
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'))
示例#7
0
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
示例#8
0
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)
示例#9
0
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)