def create_timeline(): data = request.get_json() username = data['username'] timeline_name = data['timeline_name'] events = data['events'] cover = data['cover'] user = User.query.filter_by(username=username).first() t = TimelinePost(author=user, timeline_name=timeline_name, events=events, background=cover) db.session.add(t) db.session.commit() #Grouping All Content to collect hashtags content = "" for e in events: content += e['description'].strip() + " " parse_hashtags(t, content) addPoint('TIMELINE', user) return jsonify({ 'message': 'created timeline', })
def edit_timeline(): data = request.get_json() username = data['username'] post_id = data['post_id'] user = User.query.filter_by(username=username).first() post = getPost('timeline', post_id) #content = data['content'] title = data['title'] events = data['events'] cover = data['cover'] if (post.author.id == user.id): post.timeline_name = title post.events = [] db.session.commit() post.events = [*events] #Grouping All Content to collect hashtags content = "" for e in events: content += e['description'] + " " parse_hashtags(post, content) #post.content = content post.background = cover db.session.commit() addPoint('EDITPOST', user) return jsonify({ 'code': 'S', 'message': 'Edited Timeline Successfully!' }) else: return jsonify({'code': 'ERR', 'message': 'Permission Denied'})
def resharepost(): data = request.get_json() username = data['username'] host_type = data['host_type'] host_id = data['host_id'] content = data['content'] category = data['category'] reshare_type = data['reshare_type'] post = getPost(host_type, host_id) user = User.query.filter_by(username=username).first() if (reshare_type == 'ResharedWithComment'): rwc = ReshareWithComment(author=user, host=post, content=content, category=category) db.session.add(rwc) post.reshare(user=user, post=rwc) print(f"{user} reshared post: {post} => {rwc}") parse_hashtags(rwc, content) else: sr = SimpleReshare(author=user, host=post) db.session.add(sr) post.reshare(user=user, post=sr) print(f"{user} reshared post: {post} => {sr}") addPoint('RESHARE', user) return jsonify({'message': 'Reshared Post'})
def addcomment(): data = request.get_json() username = data['username'] post_type = data['post_type'] post_id = data['post_id'] content = data['content'] category = data['category'] user = User.query.filter_by(username=username).first() post = None c = None if (post_type == 'microblog'): post = MicroBlogPost.query.filter_by(post_id=post_id).first() c = Comment(author=user, content=content, category=category, microblog_parent=post) elif (post_type == 'blog'): post = BlogPost.query.filter_by(post_id=post_id).first() c = Comment(author=user, content=content, category=category, blog_parent=post) elif (post_type == 'timeline'): post = TimelinePost.query.filter_by(post_id=post_id).first() c = Comment(author=user, content=content, category=category, timeline_parent=post) elif (post_type == 'ResharedWithComment'): post = ReshareWithComment.query.filter_by(post_id=post_id).first() c = Comment(author=user, content=content, category=category, rwc_parent=post) elif (post_type == 'carousel'): post = CarouselPost.query.filter_by(post_id=post_id).first() c = Comment(author=user, content=content, category=category, carousel_parent=post) db.session.add(c) db.session.commit() parse_hashtags(c, content) print(f"{user} commented on post: {post} => {c}") addPoint('COMMENT', user) return jsonify({ 'message': 'comment added', })
def create_poll(): data = request.get_json() username = data['username'] content = data['content'] options = data['options'] user = User.query.filter_by(username=username).first() p = PollPost(author=user, content=content, options=options) db.session.add(p) db.session.commit() parse_hashtags(p, content) addPoint('POLL', user) return jsonify({ 'message': 'created poll', })
def create_microblog(): data = request.get_json() username = data['username'] content = data['content'] category = data['category'] user = User.query.filter_by(username=username).first() mxb = MicroBlogPost(author=user, category=category, content=content) db.session.add(mxb, content) db.session.commit() parse_hashtags(mxb, content) addPoint('MICROBLOG', user) return jsonify({ 'message': 'created microblog', })
def create_shareable(): data = request.get_json() username = data['username'] content = data['content'] name = data['name'] link = data['link'] user = User.query.filter_by(username=username).first() sb = ShareablePost(author=user, name=name, content=content, link=link) db.session.add(sb) db.session.commit() parse_hashtags(sb, content) addPoint('SHAREABLE', user) return jsonify({ 'message': 'created shareable', })
def editmicroblog(): data = request.get_json() username = data['username'] post_id = data['post_id'] content = data['content'] category = data['category'] user = User.query.filter_by(username=username).first() post = getPost('microblog', post_id) if (post.author.id == user.id): post.content = content parse_hashtags(post, content) #Delta post.category = category db.session.commit() return jsonify({ 'code': 'S', 'message': 'Edited MicroBlog Successfully!' }) else: return jsonify({'code': 'ERR', 'message': 'Permission Denied'})
def editcomment(): data = request.get_json() username = data['username'] comment_id = data['comment_id'] user = User.query.filter_by(username=username).first() post = getPost('comment', comment_id) comment = data['comment'] category = data['category'] if (post.author.id == user.id): post.content = comment parse_hashtags(post, comment) #Delta post.category = category db.session.commit() addPoint('EDITPOST', user) return jsonify({ 'code': 'S', 'message': 'Edited Comment Successfully!' }) else: return jsonify({'code': 'ERR', 'message': 'Permission Denied'})
def create_blog(): data = request.get_json() username = data['username'] content = data['content'] blog_name = data['blog_name'] cover = data['cover'] user = User.query.filter_by(username=username).first() xb = BlogPost(author=user, blog_name=blog_name, content=content, background=cover) db.session.add(xb) db.session.commit() parse_hashtags(xb, content) addPoint('BLOG', user) return jsonify({ 'message': 'created blog', })
def editshareable(): data = request.get_json() username = data['username'] post_id = data['post_id'] user = User.query.filter_by(username=username).first() post = getPost('shareable', post_id) content = data['content'] link = data['link'] name = data['name'] if (post.author.id == user.id): post.link = link post.name = name post.content = content parse_hashtags(post, content) #Delta db.session.commit() addPoint('EDITPOST', user) return jsonify({ 'code': 'S', 'message': 'Edited Shareable Successfully!' }) else: return jsonify({'code': 'ERR', 'message': 'Permission Denied'})
def editblog(): data = request.get_json() username = data['username'] post_id = data['post_id'] content = data['content'] blog_name = data['blog_name'] cover = data['cover'] if data['cover'] else None user = User.query.filter_by(username=username).first() post = getPost('blog', post_id) if (post.author.id == user.id): post.content = content parse_hashtags(post, content) #Delta post.blog_name = blog_name if (cover != None): post.background = cover db.session.commit() addPoint('EDITPOST', user) return jsonify({'code': 'S', 'message': 'Edited Blog Successfully!'}) else: return jsonify({'code': 'ERR', 'message': 'Permission Denied'})
def create_carousel(): data = request.get_json() username = data['username'] content = data['content'] images = data['images'] user = User.query.filter_by(username=username).first() cx = CarouselPost(author=user, content=content) db.session.add(cx) db.session.commit() #Adding Images cx.images = [] db.session.commit() cx.images = [*[i for i in images]] db.session.commit() parse_hashtags(cx, content) addPoint('CAROUSEL', user) return jsonify({ 'message': 'created carousel', })
def editcarousel(): data = request.get_json() username = data['username'] post_id = data['post_id'] user = User.query.filter_by(username=username).first() post = getPost('carousel', post_id) content = data['content'] images = data['images'] if (post.author.id == user.id): post.content = content parse_hashtags(post, content) #Delta post.images = [] db.session.commit() post.images = [*images] db.session.commit() addPoint('EDITPOST', user) return jsonify({ 'code': 'S', 'message': 'Edited Carousel Successfully!' }) else: return jsonify({'code': 'ERR', 'message': 'Permission Denied'})