Ejemplo n.º 1
0
class ReshareWithComment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    post_type = db.Column(db.String)
    post_id = db.Column(db.String)
    host_id = db.Column(db.String)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    comments = db.relationship('Comment', backref='rwc_parent')
    content = db.Column(db.String)
    created_on = db.Column(db.String)
    category = db.Column(db.String)
    host_type = db.Column(db.String)
    hashtags = db.relationship('Hashtags',
                               secondary=hashassociation['rwc'],
                               lazy='subquery',
                               backref=db.backref('rwc', lazy=True))

    # isEdited = db.Column(db.Boolean)

    def __init__(self, content, category, author, host):
        self.post_type = 'ResharedWithComment'
        self.post_id = str(uuid.uuid4())
        self.content = content
        self.category = category
        self.author = author
        self.host_id = host.post_id
        self.created_on = str(datetime.today().strftime("%b %d, %Y %H:%M:%S"))
        self.host_type = host.post_type
        # self.isEdited = False

    @hybrid_property
    def likes(self):
        lx = LikedPosts.query.filter_by(post_id=self.post_id).all()
        return [x for x in lx]

    def like(self, user):
        obj = LikedPosts(user=user, post=self)
        db.session.add(obj)
        db.session.commit()

    def unlike(self, user):
        obj = LikedPosts.query.filter_by(user=user,
                                         post_id=self.post_id).first()
        if (obj):
            db.session.delete(obj)
            db.session.commit()

    def addhashtag(self, HList):
        for h in HList:
            H = hashgen(h)
            H.rwc.append(self)
        db.session.commit()

    def removehashtag(self, HList):
        for h in HList:
            H = Hashtags.query.filter_by(hashtag=h).first()
            H.rwc.remove(self)
        db.session.commit()

    def __repr__(self):
        return f"ResharedWithComment({self.post_id} -> {self.host_id})"
Ejemplo n.º 2
0
class PollPost(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    post_type = db.Column(db.String)
    post_id = db.Column(db.String)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    content = db.Column(db.String)
    options = db.Column(db.PickleType(comparator=lambda *a: False))
    created_on = db.Column(db.String)
    hashtags = db.relationship('Hashtags',
                               secondary=hashassociation['poll'],
                               lazy='subquery',
                               backref=db.backref('polls', lazy=True))

    #Constructor
    def __init__(self, author, content, options):
        self.post_type = 'poll'
        self.post_id = str(uuid.uuid4())
        self.content = content
        self.author = author
        self.options = [{'name': e, 'count': 0} for e in options]
        self.created_on = str(datetime.today().strftime("%b %d, %Y %H:%M:%S"))

    @hybrid_property
    def likes(self):
        lx = LikedPosts.query.filter_by(post_id=self.post_id).all()
        return [x for x in lx]

    def like(self, user):
        obj = LikedPosts(user=user, post=self)
        db.session.add(obj)
        db.session.commit()

    def unlike(self, user):
        obj = LikedPosts.query.filter_by(user=user,
                                         post_id=self.post_id).first()
        if (obj):
            db.session.delete(obj)
            db.session.commit()

    def addhashtag(self, HList):
        for h in HList:
            H = hashgen(h)
            H.polls.append(self)
        db.session.commit()

    def removehashtag(self, HList):
        for h in HList:
            H = Hashtags.query.filter_by(hashtag=h).first()
            H.polls.remove(self)
        db.session.commit()

    def __repr__(self):
        return f"PollPost({self.post_id})"
Ejemplo n.º 3
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.String)
    username = db.Column(db.String)
    password = db.Column(db.String)
    name = db.Column(db.String)
    email = db.Column(db.String)
    website = db.Column(db.String)
    icon = db.Column(db.String)
    background = db.Column(db.String)
    reputation = db.Column(db.String)
    basepoints = db.Column(db.String)
    secondarypoints = db.Column(db.String)
    #This controlls the follow logic
    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')
    created_on = db.Column(db.String)
    bio = db.Column(db.String)
    location = db.Column(db.String)
    my_microblogs = db.relationship('MicroBlogPost', backref='author')
    my_blogs = db.relationship('BlogPost', backref='author')
    my_timelines = db.relationship('TimelinePost', backref='author')
    my_shareables = db.relationship('ShareablePost', backref='author')
    my_reshareWithComments = db.relationship('ReshareWithComment',
                                             backref='author')
    my_simpleReshares = db.relationship('SimpleReshare', backref='author')
    my_polls = db.relationship('PollPost', backref='author')
    my_comments = db.relationship('Comment', backref='author')
    my_carousels = db.relationship('CarouselPost', backref='author')
    liked_posts = db.relationship('LikedPosts', backref='user')
    reshared_posts = db.relationship('ResharedPosts', backref='user')
    bookmarked_posts = db.relationship('BookmarkedPosts', backref='user')
    voted_polls = db.Column(db.PickleType(comparator=lambda *a: False))

    #Constructor
    def __init__(self, username, email, password):
        self.username = username
        self.password = password
        self.user_id = str(uuid.uuid4())
        self.email = email
        self.icon = 'https://images.pexels.com/photos/771742/pexels-photo-771742.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500'
        self.background = 'https://cdn.vox-cdn.com/thumbor/eHhAQHDvAi3sjMeylWgzqnqJP2w=/0x0:1800x1200/1200x0/filters:focal(0x0:1800x1200):no_upscale()/cdn.vox-cdn.com/uploads/chorus_asset/file/13272825/The_Verge_Hysteresis_Wallpaper_Small.0.jpg'
        self.reputation = '0'
        self.followers = []
        self.following = []
        self.created_on = str(datetime.today().strftime("%b %d, %Y %H:%M:%S"))
        self.bio = ''
        self.location = 'Unspecified Location'
        self.voted_polls = []
        self.website = ''
        self.basepoints = '0'
        self.secondarypoints = '0'

    @hybrid_property
    def my_following(self):
        return [x.username for x in self.followed.all()]

    @hybrid_property
    def my_followers(self):
        return [x.username for x in self.followers.all()]

    #--------------------------------Follow other users logic-----------------------
    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

    #--------------------------------Follow other users logic-----------------------

    def add_bookmark(self, post, posttype):
        obj = BookmarkedPosts(user=self, post=post, post_type=posttype)
        db.session.add(obj)
        db.session.commit()

    def remove_bookmark(self, post):
        obj = BookmarkedPosts.query.filter_by(user=self,
                                              post_id=post.post_id).first()
        if (obj):
            db.session.delete(obj)
            db.session.commit()

    def __repr__(self):
        return f"MicroBloggerUser({self.username})"
Ejemplo n.º 4
0
class CarouselPost(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    post_type = db.Column(db.String)
    post_id = db.Column(db.String)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    comments = db.relationship('Comment', backref='carousel_parent')
    content = db.Column(db.String)
    created_on = db.Column(db.String)
    images = db.Column(db.PickleType(comparator=lambda *a: False))
    hashtags = db.relationship('Hashtags',
                               secondary=hashassociation['carousel'],
                               lazy='subquery',
                               backref=db.backref('carousels', lazy=True))
    # isEdited = db.Column(db.Boolean)

    @hybrid_property
    def likes(self):
        lx = LikedPosts.query.filter_by(post_id=self.post_id).all()
        return [x for x in lx]

    @hybrid_property
    def reshares(self):
        rx = ResharedPosts.query.filter_by(og_post_id=self.post_id).all()
        return [x for x in rx]

    def like(self, user):
        obj = LikedPosts(user=user, post=self)
        db.session.add(obj)
        db.session.commit()

    def unlike(self, user):
        obj = LikedPosts.query.filter_by(user=user,
                                         post_id=self.post_id).first()
        if (obj):
            db.session.delete(obj)
            db.session.commit()

    def reshare(self, user, post):
        obj = ResharedPosts(user=user, host=self, post=post)
        db.session.add(obj)
        db.session.commit()

    def unreshare(self, user, post):
        obj = ResharedPosts.query.filter_by(
            user=user, og_post_id=self.post_id,
            reshared_post_id=post.post_id).first()
        if (obj):
            db.session.delete(obj)
            db.session.commit()

    def addhashtag(self, HList):
        for h in HList:
            H = hashgen(h)
            H.carousels.append(self)
        db.session.commit()

    def removehashtag(self, HList):
        for h in HList:
            H = Hashtags.query.filter_by(hashtag=h).first()
            H.carousels.remove(self)
        db.session.commit()

    def __init__(self, author, content):
        self.post_id = str(uuid.uuid4())
        self.author = author
        self.post_type = 'carousel'
        self.images = []
        self.content = content
        self.created_on = str(datetime.today().strftime("%b %d, %Y %H:%M:%S"))
        # self.isEdited = False

    def __repr__(self):
        return f"CarouselPost({self.author_id}, {self.post_id})"
Ejemplo n.º 5
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    post_type = db.Column(db.String)
    comment_id = db.Column(db.String)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    content = db.Column(db.String)
    created_on = db.Column(db.String)
    category = db.Column(db.String)
    microblog_pid = db.Column(db.Integer, db.ForeignKey('micro_blog_post.id'))
    blog_pid = db.Column(db.Integer, db.ForeignKey('blog_post.id'))
    timeline_pid = db.Column(db.Integer, db.ForeignKey('timeline_post.id'))
    rwc_pid = db.Column(db.Integer, db.ForeignKey('reshare_with_comment.id'))
    carousel_pid = db.Column(db.Integer, db.ForeignKey('carousel_post.id'))
    hashtags = db.relationship('Hashtags',
                               secondary=hashassociation['comment'],
                               lazy='subquery',
                               backref=db.backref('comments', lazy=True))

    # isEdited = db.Column(db.Boolean)

    def __init__(self,
                 author,
                 content,
                 category,
                 microblog_parent=None,
                 blog_parent=None,
                 timeline_parent=None,
                 rwc_parent=None,
                 carousel_parent=None):
        self.post_type = 'comment'
        self.comment_id = str(uuid.uuid4())
        self.content = content
        self.category = category

        if (microblog_parent != None): self.microblog_parent = microblog_parent
        if (blog_parent != None): self.blog_parent = blog_parent
        if (timeline_parent != None): self.timeline_parent = timeline_parent
        if (rwc_parent != None): self.rwc_parent = rwc_parent
        if (carousel_parent != None): self.carousel_parent = carousel_parent

        self.author = author
        self.created_on = str(datetime.today().strftime("%b %d, %Y %H:%M:%S"))
        # self.isEdited = False

    @hybrid_property
    def likes(self):
        lx = LikedPosts.query.filter_by(post_id=self.comment_id).all()
        return [x for x in lx]

    def like(self, user):
        obj = LikedPosts(user=user, post=self)
        db.session.add(obj)
        db.session.commit()

    def unlike(self, user):
        obj = LikedPosts.query.filter_by(user=user,
                                         post_id=self.post_id).first()
        if (obj):
            db.session.delete(obj)
            db.session.commit()

    def addhashtag(self, HList):
        for h in HList:
            H = hashgen(h)
            H.comments.append(self)
        db.session.commit()

    def removehashtag(self, HList):
        for h in HList:
            H = Hashtags.query.filter_by(hashtag=h).first()
            H.comments.remove(self)
        db.session.commit()

    def __repr__(self):
        return f"Comment({self.comment_id})"
Ejemplo n.º 6
0
class TimelinePost(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    post_type = db.Column(db.String)
    post_id = db.Column(db.String)
    background = db.Column(db.String)
    timeline_name = db.Column(db.String)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    content = db.Column(db.String)
    events = db.Column(db.PickleType)
    created_on = db.Column(db.String)
    comments = db.relationship('Comment', backref='timeline_parent')
    hashtags = db.relationship('Hashtags',
                               secondary=hashassociation['timeline'],
                               lazy='subquery',
                               backref=db.backref('timelines', lazy=True))
    # isEdited = db.Column(db.Boolean)
    """
	SCHEMA(events): [
        {
          'event_name': 'The Situation Abroad',
          'description':
              'A Very Dire Situation',
          'timestamp': 'late 2019'
        },
	]
	"""
    def __init__(self, timeline_name, events, background, author):
        self.post_type = 'timeline'
        self.post_id = str(uuid.uuid4())
        self.timeline_name = timeline_name
        self.events = events
        self.background = background
        self.author = author
        self.created_on = str(datetime.today().strftime("%b %d, %Y %H:%M:%S"))
        # self.isEdited = false

    @hybrid_property
    def likes(self):
        lx = LikedPosts.query.filter_by(post_id=self.post_id).all()
        return [x for x in lx]

    @hybrid_property
    def reshares(self):
        rx = ResharedPosts.query.filter_by(og_post_id=self.post_id).all()
        return [x for x in rx]

    def like(self, user):
        obj = LikedPosts(user=user, post=self)
        db.session.add(obj)
        db.session.commit()

    def unlike(self, user):
        obj = LikedPosts.query.filter_by(user=user,
                                         post_id=self.post_id).first()
        if (obj):
            db.session.delete(obj)
            db.session.commit()

    def reshare(self, user, post):
        obj = ResharedPosts(user=user, host=self, post=post)
        db.session.add(obj)
        db.session.commit()

    def unreshare(self, user, post):
        obj = ResharedPosts.query.filter_by(
            user=user, og_post_id=self.post_id,
            reshared_post_id=post.post_id).first()
        if (obj):
            db.session.delete(obj)
            db.session.commit()

    def addhashtag(self, HList):
        for h in HList:
            H = hashgen(h)
            H.timelines.append(self)
        db.session.commit()

    def removehashtag(self, HList):
        for h in HList:
            H = Hashtags.query.filter_by(hashtag=h).first()
            H.timelines.remove(self)
        db.session.commit()

    def __repr__(self):
        return f"TimelinePost({self.timeline_name})"
Ejemplo n.º 7
0
class ShareablePost(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    post_type = db.Column(db.String)
    post_id = db.Column(db.String)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    content = db.Column(db.String)
    link = db.Column(db.String)
    name = db.Column(db.String)
    created_on = db.Column(db.String)
    hashtags = db.relationship('Hashtags',
                               secondary=hashassociation['shareable'],
                               lazy='subquery',
                               backref=db.backref('shareables', lazy=True))

    # isEdited = db.Column(db.Boolean)

    def __init__(self, name, content, link, author):
        self.post_type = 'shareable'
        self.post_id = str(uuid.uuid4())
        self.name = name
        self.content = content
        self.link = link
        self.author = author
        self.created_on = str(datetime.today().strftime("%b %d, %Y %H:%M:%S"))
        # self.isEdited = False

    @hybrid_property
    def likes(self):
        lx = LikedPosts.query.filter_by(post_id=self.post_id).all()
        return [x for x in lx]

    @hybrid_property
    def reshares(self):
        rx = ResharedPosts.query.filter_by(og_post_id=self.post_id).all()
        return [x for x in rx]

    def like(self, user):
        obj = LikedPosts(user=user, post=self)
        db.session.add(obj)
        db.session.commit()

    def unlike(self, user):
        obj = LikedPosts.query.filter_by(user=user,
                                         post_id=self.post_id).first()
        if (obj):
            db.session.delete(obj)
            db.session.commit()

    def reshare(self, user, post):
        obj = ResharedPosts(user=user, host=self, post=post)
        db.session.add(obj)
        db.session.commit()

    def unreshare(self, user, post):
        obj = ResharedPosts.query.filter_by(
            user=user, og_post_id=self.post_id,
            reshared_post_id=post.post_id).first()
        if (obj):
            db.session.delete(obj)
            db.session.commit()

    def addhashtag(self, HList):
        for h in HList:
            H = hashgen(h)
            H.shareables.append(self)
        db.session.commit()

    def removehashtag(self, HList):
        for h in HList:
            H = Hashtags.query.filter_by(hashtag=h).first()
            H.shareables.remove(self)
        db.session.commit()

    def __repr__(self):
        return f"ShareablePost({self.name})"