示例#1
0
class User(db.Model, UserMixin):
    __tablename__ = 'users'
    id = db.Column(db.Integer, unique=True, primary_key=True)
    profile_image = db.Column(db.String(64),
                              nullable=False,
                              default='default.png')
    email = db.Column(db.String(64), unique=True, index=True)
    username = db.Column(db.String(64), unique=True, index=True)
    password_hash = db.Column(db.String(128))
    role = db.Column(db.String(80))
    #teachers = db.relationship("Member", backref="user", lazy="dynamic")
    #students = db.relationship("Base", backref="user", lazy="dynamic")
    posts = db.relationship('BlogPost', backref='author', lazy=True)

    def __init__(self, email, username, password, role):
        self.email = email
        self.username = username
        self.password_hash = generate_password_hash(password)
        self.role = role

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

    def __repr__(self):
        return f"Username {self.username}"
示例#2
0
class User(db.Model, UserMixin):

    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    profile_image = db.Column(db.String(20),
                              nullable=False,
                              default='default_profile.png')
    email = db.Column(db.String(64), unique=True, index=True)
    username = db.Column(db.String(64), unique=True, index=True)
    password_hash = db.Column(db.String(128))

    posts = db.relationship('BlogPost', backref='author', lazy=True)

    def __init__(self, email, username, password):
        self.email = email
        self.username = username
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):

        return check_password_hash(self.password_hash, password)

    def __repr__(self):
        return f"UserName: {self.username}"
示例#3
0
class Post(db.Model):
    users = db.relationship(User)
    slug = db.Column(db.Integer, nullable=False)
    id = db.Column(db.Integer, primary_key=True)
    meta_title = db.Column(db.String(60), nullable=False)
    meta_desc = db.Column(db.String(160), nullable=False)
    category = db.Column(db.String(160), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)

    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    heading = db.Column(db.String(140), nullable=False)
    post = db.Column(db.Text, nullable=False)
示例#4
0
class Images(db.Model):
    __tablename__ = 'images'
    id = db.Column(db.Integer, primary_key=True)
    filename = db.Column(db.String(50), nullable=False)
    thumbnail = db.Column(db.String(50), nullable=False)
    file_size = db.Column(db.Integer, nullable=False)
    file_width = db.Column(db.Integer, nullable=False)
    file_height = db.Column(db.Integer, nullable=False)
    create_date = db.Column(db.DateTime,
                            default=datetime.utcnow,
                            nullable=False)

    def getImage(image_id):
        return Images.query.filter_by(id=image_id).first()
示例#5
0
class Contact(db.Model):

    __tablename__ = 'contact-form'

    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(64), nullable=False)
    subject = db.Column(db.String(140), nullable=False)
    message = db.Column(db.Text, nullable=False)

    def __init__(self, email, subject, message):
        self.email = email
        self.subject = subject
        self.message = message

    def __repr__(self):
        return f"Contact form -- Email: {self.email} -- Subject: {self.subject} -- Message: {self.message}"
示例#6
0
class Tag(db.Model):
    id = db.Column(db.Integer,primary_key=True)
    tag = db.Column(db.String(64), nullable=False, unique=True)


    def __init__(self,tag):
        self.tag = tag

    def __repr__(self):
        return "Tag: {}".format(self.tag)
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)
示例#8
0
class BlogPost(db.Model):
    users = db.relationship(User)

    id = db.Column(db.Integer, primary_key=True)
    event_image = db.Column(
        db.Text,
        nullable=False,
        default='https://' + str(app.config['AWS_BUCKET']) +
        '.s3-ap-northeast-1.amazonaws.com/default_profile.png')
    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)
    event_date = db.Column(db.DateTime, default=datetime.utcnow)
    event_time = db.Column(db.Time, default=datetime.utcnow)
    organizer = db.Column(db.String(140), nullable=False)
    place = db.Column(db.String(140), nullable=False)
    entry = db.Column(db.Text, nullable=False)
    way = db.Column(db.Text, nullable=False)
    cost = db.Column(db.String(140), nullable=False)
    contact = db.Column(db.String(140), nullable=False)
    text = db.Column(db.Text, nullable=False)

    comments = db.relationship('Comment', backref='title', lazy=True)
    likes = db.relationship('PostLike', backref='post', lazy='dynamic')

    def __init__(self, organizer, place, title, event_date, event_time, entry,
                 text, way, user_id, cost, event_image, contact):
        self.title = title
        self.text = text
        self.event_date = event_date
        self.event_time = event_time
        self.user_id = user_id
        self.event_image = event_image
        self.organizer = organizer
        self.place = place
        self.entry = entry
        self.way = way
        self.cost = cost
        self.contact = contact

        def __repr__(self):
            return f"Post ID: {self.id} --Date:{self.date} --- {self.title}"
示例#9
0
class Comment(db.Model):

    __tablename__ = 'comments'

    users = db.relationship(User)

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    post_id = db.Column(db.Integer, db.ForeignKey('blogpost.id'), nullable=False)
    text = db.Column(db.String(140))
    timestamp = db.Column(db.DateTime(), default=datetime.utcnow, index=True)
示例#10
0
class TextOutput(db.Model):
    users = db.relationship(User)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String(1000))
    sa_score = db.Column(db.Integer)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

    def __init__(self, text, user_id, sa_score):
        self.user_id = user_id
        self.text = text
        self.sa_score = sa_score
示例#11
0
class BlogPost(db.Model):

    __tablename__ = 'blogpost'

    users = db.relationship(User)

    id = db.Column(db.Integer,primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    comments = db.relationship('Comment', backref='post', lazy=True)

    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    title = db.Column(db.String(140),nullable=False, unique=True)
    text = db.Column(db.Text,nullable=False)
    slug = db.Column(db.String(140), nullable=False)

    tags = db.relationship(
        'Tag', secondary=post_tag,
        backref=db.backref('posts', lazy='dynamic'), lazy='dynamic'
    )

    def __init__(self,title,text,user_id, slug):
        self.title = title
        self.text = text
        self.user_id = user_id
        self.slug = slug

    def __repr__(self):
        return "Post ID: {}".format(self.id)

    def tag(self, tag):
        if not self.tagged(tag):
            self.tags.append(tag)

    def untag(self, tag):
        if self.tagged(tag):
            self.tags.remove(tag)

    def tagged(self, tag):
        return self.tags.filter(
            post_tag.c.tag_id == tag.id).count() > 0
示例#12
0
class BlogPost():
    users = db.relationship(User)
    id = db.Column(db.Integer, primary_key=True)
    userId = 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(160), nullable=False)
    text = db.Column(db.Text, nullable=False)

    def __init__(self, title, text, userId):
        self.title = title
        self.text = text
        self.userId = userId

    def __repr__(self):
        f"Post Id { self.id } -- Date: { self.date } -----{ self.title }"
示例#13
0
class BlogPost(db.Model):
    users = db.relationship(User)
    id = db.Column(db.Integer, primary_key=True)
    meta_title = db.Column(db.String(60), nullable=False)
    meta_desc = db.Column(db.String(160), nullable=False)
    category = db.Column(db.String(160), nullable=False)
    keywords = db.Column(db.String(160), nullable=False)
    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, meta_title, meta_desc, category,
                 keywords):
        self.title = title
        self.text = text
        self.user_id = user_id
        self.meta_title = meta_title
        self.meta_desc = meta_desc
        self.category = category
        self.keywords = keywords

    def __repr__(self):
        return f"Post ID: {self.id}"
class Question(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    subject = db.Column(db.String(200), nullable=False)
    content = db.Column(db.Text(), nullable=False)

    create_date = db.Column(db.DateTime(), nullable=False)

    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.id', ondelete='CASCADE'),
                        nullable=False)
    user = db.relationship('User', backref=db.backref('question_set'))

    modify_date = db.Column(db.DateTime(), nullable=True)

    voter = db.relationship('User',
                            secondary=question_voter,
                            backref=db.backref('question_voter_set'))
示例#15
0
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 posted: {self.date} --- Title of the text: {self.title}"
示例#16
0
class BlogPost(db.Model, UserMixin):

    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}'
示例#17
0
class BlogPost(db.Model):
    # Setup the relationship to the User table
    users = db.relationship(User)

    # Model for the Blog Posts on Website
    id = db.Column(db.Integer, primary_key=True)
    # Notice how we connect the BlogPost to a particular author
    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}"
示例#18
0
class Comment(db.Model):
    blog_post = db.relationship(BlogPost)
    users = db.relationship(User)

    id = db.Column(db.Integer, primary_key=True)
    body = db.Column(db.String(140), nullable=False)
    timestamp = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    post_id = db.Column(db.Integer,
                        db.ForeignKey('blog_post.id'),
                        nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)

    def __init__(self, body, post_id, user_id):
        self.body = body
        self.post_id = post_id
        self.user_id = user_id

        def __repr__(self):
            return f"Post ID: {self.id}---userid:{self.user_id} --Date:{self.timestamp}---{self.body}"
示例#19
0
class User(db.Model, UserMixin):

    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    profile_image = db.Column(
        db.Text,
        nullable=False,
        default='https://' + str(app.config['AWS_BUCKET']) +
        '.s3-ap-northeast-1.amazonaws.com/default_profile.png')
    email = db.Column(db.String(140), unique=True, index=True)
    username = db.Column(db.String(140), unique=True, index=True)
    name = db.Column(db.String(140), nullable=True)
    club_name = db.Column(db.String(140), nullable=True)
    event = db.Column(db.Text, nullable=True)
    facebook = db.Column(db.String(140), nullable=True)
    twitter = db.Column(db.String(140), nullable=True)
    instagram = db.Column(db.String(140), nullable=True)
    info = db.Column(db.Text, nullable=True)
    club_number = db.Column(db.String(140), nullable=True)
    club_place = db.Column(db.String(140), nullable=True)
    club_active = db.Column(db.String(140), nullable=True)
    money = db.Column(db.String(140), nullable=True)
    url = db.Column(db.String(140), nullable=True)
    university = db.Column(db.Integer, nullable=False)
    type = db.Column(db.Integer, nullable=False)
    last_seen = db.Column(db.DateTime, default=datetime.utcnow)
    password_hash = db.Column(db.String(128))
    authenticated = db.Column(db.Boolean, default=False)
    email_confirmation_sent_on = db.Column(db.DateTime, nullable=True)
    email_confirmed = db.Column(db.Boolean, nullable=True, default=False)
    email_confirmed_on = db.Column(db.DateTime, nullable=True)
    posts = db.relationship('BlogPost', backref='author', lazy=True)
    comments = db.relationship('Comment', backref='poster', lazy=True)
    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')

    liked = db.relationship('PostLike',
                            foreign_keys='PostLike.user_id',
                            backref='user',
                            lazy='dynamic')

    def __init__(self,
                 email,
                 username,
                 name,
                 club_name,
                 type,
                 university,
                 password,
                 email_confirmation_sent_on=None):
        self.email = email
        self.username = username
        self.name = name
        self.club_name = club_name
        self.type = type
        self.university = university
        self.password_hash = generate_password_hash(password)
        self.email_confirmation_sent_on = email_confirmation_sent_on
        self.email_confirmed = False
        self.email_confirmed_on = None
        self.authenticated = False

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

    def is_authenticated(self):
        return self.authenticated

    def __repr__(self):
        return f"Username {self.username}"

    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 = BlogPost.query.join(
            followers, (followers.c.followed_id == BlogPost.user_id)).filter(
                followers.c.follower_id == self.id)
        return followed.union(self.posts).order_by(BlogPost.date.desc())

    def like_post(self, blog_post):
        if not self.has_liked_post(blog_post):
            like = PostLike(user_id=self.id, post_id=blog_post.id)
            db.session.add(like)

    def unlike_post(self, blog_post):
        if self.has_liked_post(blog_post):
            PostLike.query.filter_by(user_id=self.id,
                                     post_id=blog_post.id).delete()

    def has_liked_post(self, blog_post):
        return PostLike.query.filter(PostLike.user_id == self.id,
                                     PostLike.post_id
                                     == blog_post.id).count() > 0