def post_comment(): if request.method == "POST": username = session['username'].lower() body = request.form['body'] print(body) time = datetime.now() # time = str(time) # print(body) # data_received = json.loads(request.data) # post = interactionHandler.retrieve_postid(data_received['postid']) # post_info = interactionHandler.get_post_info(data_received['postid']) # relation = interactionHandler.check_post(username, post_info[0]) print(username) print(1) interactionHandler.insert_comment(1, username, body, time) # print(relation) # if relation: # print(relation) # comments = interactionHandler.show_comment() # print(comments) # comments_first = [] # for comment in comments: # comments_first.append(comment[0]) # print(comments_first) return json.dumps({'status': 'success'}) # print(comments) # return render_template('news.html', comments=comments_first) # else: # return json.dumps({'status': 'no post found'}) else: return home2()
def news_dislike(): if request.method == "POST": username = session['username'] data_received = json.loads(request.data) post = interactionHandler.retrieve_newsid(data_received['postid']) like_count = interactionHandler.retrieve_newslikecount( data_received['postid']) like_count = like_count[0] relation = interactionHandler.retrieve_liked_user( username, data_received['postid']) if relation is not None: if post: like_count = like_count - 1 interactionHandler.news_update( (like_count, data_received['postid'])) interactionHandler.remove_liked_user(username, data_received['postid']) return json.dumps({'status': 'success'}) return json.dumps({'status': 'no post found'}) else: if post: pass return json.dumps({'status': 'success'}) return json.dumps({'status': 'no post found'}) return home2()
def unsave_post(): if request.method == "POST": username = session['username'] data_received = json.loads(request.data) post = interactionHandler.retrieve_postid(data_received['postid']) post_info = interactionHandler.get_post_info(data_received['postid']) relation = interactionHandler.check_post(username, post_info[0]) if relation is not None: if post: interactionHandler.unsave_post(username, post_info[0]) return json.dumps({'status': 'success'}) return json.dumps({'status': 'no post found'}) else: if post: pass return json.dumps({'status': 'success'}) return json.dumps({'status': 'no post found'}) return home2()