def discussion_page_settings(discussion_id): query = DBQuery() discussion = query.get_discussions_by_id(discussion_id) comments = query.get_all_comments_list(discussion_id) user = '' joined = '' user_score_discussion = '' big_dict = {} for c in comments: parent_id = c[2] parent_content = c[3] value_list = [] while parent_id is not None: value_list.insert(0, parent_content) big_dict[c[0]] = value_list parent_id, parent_content = query.get_parent_id(parent_id) user_score_discussion = '' if session['logged_in']: user = query.get_user_details(session['email']) joined = query.check_if_joined(discussion_id, session['email']) user_score_discussion = query.get_user_vote_details_discussion( discussion_id, session['email']) return render_template('discussion_page.html', discussion=discussion, comments=comments, main=False, user=user, joined=joined, user_score_discussion=user_score_discussion, big_dict=big_dict, settings=True)
def redirect_profile(): if session['logged_in']: query = DBQuery() user = query.get_user_details(session['email']) print(user) return render_template('profile.html', register=False, logged_in=True, user=user) else: return render_template('profile.html', register=False, logged_in=False)
def remove_branches(discussion_id): query = DBQuery() discussion = query.get_discussions_by_id(discussion_id) comments = query.get_all_comments_list(discussion_id) graph = {} counter = 1 level = [1] if request.method == 'POST': percentile = int(request.form['percentile']) num75 = get_num_75(discussion_id, percentile) get_nodes_75(discussion_id, num75) for s in comments: mylist = [] node_id = s[0] counter = counter + 1 for j in comments: parent_id = (j[2]) if parent_id == node_id: level.append(counter) mylist.append(str(j[0])) graph[str(node_id)] = mylist if str(node_id) not in graph: graph[str(node_id)] = [] global html_string html_string = [] status = discussion[0][6] print(status) visited = dfs(graph, str(comments[0][0]), [], html_string, comments, status) str1 = ''.join(html_string) user = query.get_user_details(session['email']) reset_ranking = query.reset_ranking(discussion_id) return redirect( url_for('discussions.discussion_page_tree', discussion_id=discussion_id, discussion=discussion, comments=comments, html_string=Markup(str1), main=True, tree=True, status=True, user=user))
def discussion_page_main(discussion_id): query = DBQuery() discussion = query.get_discussions_by_id(discussion_id) comments = query.get_all_comments_list(discussion_id) graph = {} counter = 1 level = [1] for s in comments: mylist = [] node_id = s[0] counter = counter + 1 for j in comments: parent_id = (j[2]) if parent_id == node_id: level.append(counter) mylist.append(str(j[0])) graph[str(node_id)] = mylist if str(node_id) not in graph: graph[str(node_id)] = [] global html_string status = discussion[0][6] html_string = [] visited = dfs(graph, str(comments[0][0]), [], html_string, comments, status) str1 = ''.join(html_string) user = '' merge_comments = '' joined = '' big_dict = {} for c in comments: parent_id = c[2] parent_content = c[3] value_list = [] if parent_id is None: value_list.insert(0, parent_content) big_dict[c[0]] = value_list else: while parent_id is not None: value_list.insert(0, parent_content) big_dict[c[0]] = value_list parent_id, parent_content = query.get_parent_id(parent_id) print(big_dict) user_score_discussion = '' if session['logged_in']: user = query.get_user_details(session['email']) user_score_discussion = query.get_user_vote_details_discussion( discussion_id, session['email']) merge_comments = query.get_merge_list(discussion_id) joined = query.check_if_joined(discussion_id, session['email']) return render_template('discussion_page.html', discussion=discussion, comments=comments, main=True, tree=False, html_string=Markup(str1), user=user, merge_list=merge_comments, joined=joined, user_score_discussion=user_score_discussion, big_dict=big_dict)