def mission_statement(): search_debates_form = HomepageSearch(prefix="search_debate_form") if search_debates_form.validate_on_submit(): if search_debates_form.search_bar.data == "": return redirect( url_for("homepage_with_params_wrapper", searchtype=search_debates_form.debate_type.data, terms="___blank___", page=1)) else: return redirect( url_for("homepage_with_params_wrapper", searchtype=search_debates_form.debate_type.data, terms=search_debates_form.search_bar.data, page=1)) template_payload = {} template_payload["search_debates_form_multipage"] = search_debates_form if current_user.is_authenticated and current_user is not None: template_payload["user"] = g.user else: template_payload["auth_url"] = g.auth_url return render_template("mission_statement.html", server_data=template_payload)
def search(searchtype, terms, page=1): search_debates_form = HomepageSearch(prefix="search_debate_form") if search_debates_form.validate_on_submit(): if search_debates_form.search_bar.data == "": return redirect( url_for("homepage_with_params_wrapper", searchtype=search_debates_form.debate_type.data, terms="___blank___", page=1)) else: return redirect( url_for("homepage_with_params_wrapper", searchtype=search_debates_form.debate_type.data, terms=search_debates_form.search_bar.data, page=1)) debates, maxlen = search_debates(searchtype=searchtype, terms=terms, page=page) template_payload = { "debates": debates, "user": g.user, "pagenum": page, "max_pagenum": maxlen, "searchtype": searchtype, "terms": terms } template_payload["search_debates_form_multipage"] = search_debates_form return render_template("search.html", server_data=template_payload)
def settings(): search_debates_form = HomepageSearch(prefix="search_debate_form") if search_debates_form.validate_on_submit(): if search_debates_form.search_bar.data == "": return redirect( url_for("homepage_with_params_wrapper", searchtype=search_debates_form.debate_type.data, terms="___blank___", page=1)) else: return redirect( url_for("homepage_with_params_wrapper", searchtype=search_debates_form.debate_type.data, terms=search_debates_form.search_bar.data, page=1)) template_payload = {} template_payload["search_debates_form_multipage"] = search_debates_form if current_user.is_authenticated and current_user is not None: template_payload["user"] = g.user else: template_payload["auth_url"] = g.auth_url user_settings = User.query.filter_by(id=current_user.id).first() settings_form = EmailSettings(obj=user_settings) change_username = ChangeUsername(obj=user_settings) sync_with_google = SyncWithGoogle(obj=user_settings) template_payload["settings_form"] = settings_form template_payload["username_form"] = change_username template_payload["sync_with_google"] = sync_with_google if settings_form.validate_on_submit() and change_username.validate_on_submit() and \ sync_with_google.validate_on_submit(): if (not change_username.name.data.isspace()) and ( change_username.name.data != ""): user_settings.name = change_username.name.data user_settings.sync_with_google = bool( sync_with_google.sync_with_google.data) user_settings.send_user_joined_emails = bool( settings_form.send_user_joined_emails.data) user_settings.send_round_continue_emails = bool( settings_form.send_round_continue_emails.data) user_settings.send_voting_notification_emails = bool( settings_form.send_voting_notification_emails.data) user_settings.send_debate_finished_emails = bool( settings_form.send_debate_finished_emails.data) db.session.commit() return render_template("settings.html", server_data=template_payload)
def create_or_join_debate(): search_debates_form = HomepageSearch(prefix="search_debate_form") if search_debates_form.validate_on_submit(): if search_debates_form.search_bar.data == "": return redirect(url_for("homepage_with_params_wrapper", searchtype=search_debates_form.debate_type.data, terms="___blank___", page=1 )) else: return redirect(url_for("homepage_with_params_wrapper", searchtype=search_debates_form.debate_type.data, terms=search_debates_form.search_bar.data, page=1)) create_debate_form = DebateCreate(prefix="create_debate_form") search_debates_form_bottom = DebateSearchBar(prefix="search_debate_form") template_payload = { "user": g.user, "create_debate_form": create_debate_form, "search_debates_form": search_debates_form } template_payload["search_debates_form_multipage"] = search_debates_form if create_debate_form.validate_on_submit(): debate = Debate() debate.dtype = create_debate_form.debate_type.data debate.topic = create_debate_form.topic.data debate.max_round_number = create_debate_form.max_round_number.data debate.max_claim_number = 1 #create_debate_form.max_claim_number.data debate.isTimed = create_debate_form.is_timed.data debate.has_sent_finished_emails = False debate.current_round_number = 1 debate.views = 0 debate.stage = "pro" user = User.query.filter_by(id=current_user.id).first() user_type = create_debate_form.pro_or_con.data add_user_to_debate(debate, user, user_type=user_type) return redirect(url_for("debate_synopsis", debate_id=debate.id)) if search_debates_form_bottom.validate_on_submit(): return redirect(url_for("search", searchtype="joinable", terms=search_debates_form.search_bar.data, page=1 )) return render_template("create_or_join_debate.html", server_data=template_payload)
def homepage_with_params(searchtype="in-progress", terms="", page=1): global with_params search_debates_form = HomepageSearch(prefix="search_debate_form") if search_debates_form.validate_on_submit(): if search_debates_form.search_bar.data == "": return redirect( url_for("homepage_with_params_wrapper", searchtype=search_debates_form.debate_type.data, terms="___blank___", page=1)) else: return redirect( url_for("homepage_with_params_wrapper", searchtype=search_debates_form.debate_type.data, terms=search_debates_form.search_bar.data, page=1)) if terms != "": debates, maxlen = search_debates(searchtype=searchtype, terms=terms, page=page, isGlobalSearch=True) else: debates, maxlen = search_debates(searchtype=searchtype, terms=terms, page=page) template_payload = {"debates": debates} template_payload["search_debates_form_multipage"] = search_debates_form if current_user.is_authenticated and current_user is not None: template_payload["user"] = g.user template_payload["is_vip"] = current_user.isVIP else: template_payload["auth_url"] = g.auth_url template_payload["pagenum"] = page template_payload["max_pagenum"] = maxlen template_payload["with_params"] = with_params template_payload["searchtype"] = searchtype if terms == "": template_payload["terms"] = "___blank___" else: template_payload["terms"] = terms return render_template("home.html", server_data=template_payload)
def profile(user_id, page=1): search_debates_form = HomepageSearch(prefix="search_debate_form") if search_debates_form.validate_on_submit(): if search_debates_form.search_bar.data == "": return redirect( url_for("homepage_with_params_wrapper", searchtype=search_debates_form.debate_type.data, terms="___blank___", page=1)) else: return redirect( url_for("homepage_with_params_wrapper", searchtype=search_debates_form.debate_type.data, terms=search_debates_form.search_bar.data, page=1)) template_payload = {} template_payload["search_debates_form_multipage"] = search_debates_form profile_user = User.query.filter_by(id=user_id).first() debates = [] for debate in Debate.query.all(): for relation in debate.users: if relation.user == profile_user: user_pro, user_con = find_user_debate_stance(debate) i = { "id": debate.id, "user_pro": user_pro, "topic": debate.topic, "max_round_number": debate.max_round_number, "current_round_number": debate.current_round_number, "user_con": user_con, "is_timed": debate.isTimed, "stage": debate.stage, "views": debate.views } debates.append(i) break if profile_user is not None: prof_user = { "name": profile_user.name, "avatar": profile_user.avatar, "wins": profile_user.wins, "losses": profile_user.losses } else: return ("No user id, " + user_id) if current_user.is_authenticated and current_user is not None: template_payload["user"] = g.user else: template_payload["auth_url"] = g.auth_url debates = list(paginate_list(debates, main.config["POSTS_PER_PAGE"])) template_payload["max_pagenum"] = ceil(len(debates)) try: debates = debates[page - 1] except IndexError: debates = [] template_payload["prof_user"] = prof_user template_payload["debates"] = debates template_payload["pagenum"] = page template_payload["user_id"] = user_id return render_template("profile.html", server_data=template_payload)
def debate_synopsis(debate_id): search_debates_form = HomepageSearch(prefix="search_debate_form") if search_debates_form.validate_on_submit(): if search_debates_form.search_bar.data == "": return redirect( url_for("homepage_with_params_wrapper", searchtype=search_debates_form.debate_type.data, terms="___blank___", page=1)) else: return redirect( url_for("homepage_with_params_wrapper", searchtype=search_debates_form.debate_type.data, terms=search_debates_form.search_bar.data, page=1)) template_payload = {} template_payload["search_debates_form_multipage"] = search_debates_form debate = Debate.query.filter_by(id=debate_id).first() debate_key = "has_viewed" + str(debate.id) if debate_key in session: pass else: session[debate_key] = False if session[debate_key] == False: debate.views += 1 db.session.commit() session[debate_key] = True mrn = debate.max_round_number rounds = return_rounds_of_debate(debate) user_pro, user_con = find_user_debate_stance(debate) if current_user.is_authenticated and current_user is not None: template_payload["is_vip"] = current_user.isVIP challenger = User.query.filter_by(id=current_user.id).first() template_payload["user"] = g.user # if debate is joinable and the current_user isn't in it, render the # join form and add the current_user upon validation if len(debate.users) < 2 and debate.users[0].user is not challenger: join_debate_form = JoinDebate() template_payload["join_debate_form"] = join_debate_form if join_debate_form.validate_on_submit(): # check again in case of someone else joining in the meantime if len(debate.users ) < 2 and debate.users[0].user is not challenger: incumbent_user_type = debate.users[0].user_type if incumbent_user_type == "pro": add_user_to_debate(debate, challenger, user_type="con") elif incumbent_user_type == "con": add_user_to_debate(debate, challenger, user_type="pro") if (debate.isTimed == "timed") or (debate.isTimed == None): debate.time_for_next_phase = datetime.datetime.utcnow() + \ datetime.timedelta(minutes=main.config["TIME_DELTA"]) db.session.commit() if debate.users[0].user.send_user_joined_emails == True: send_email( generate_user_joined_debate_email( debate, challenger.name, challenger.avatar), debate.users[0].user.email) return redirect( url_for("debate_synopsis", debate_id=debate_id)) else: template_payload["rounds"] = rounds template_payload["max_round_number"] = mrn template_payload["debate_topic"] = debate.topic template_payload["user_pro"] = user_pro template_payload["user_con"] = user_con template_payload["round_num"] = debate.current_round_number template_payload["debate_id"] = debate_id template_payload["debate_stage"] = debate.stage # this, unfortunately, has to stay here because it stops execution from going to # the below claim_support_form stuff. It's ugly, but, hey. This file used to have # 4 render_templates! return render_template("debate_synopsis.html", server_data=template_payload) for u in debate.users: if current_user.id == u.user_id: if debate.stage == u.user_type: claim_support_form = ClaimSupport() template_payload["claim_support_form"] = claim_support_form if claim_support_form.validate_on_submit(): if debate.stage != u.user_type: return redirect( url_for("debate_synopsis", debate_id=debate_id)) append_all_claims(debate, claim_support_form) switch_from_pro_to_con(debate) move_to_voting_mode_if_finished(debate) db.session.commit() if debate.isTimed == "untimed": manage_email_transitions(debate, user_pro, user_con) return redirect( url_for("debate_synopsis", debate_id=debate_id)) canVote = False if (debate.stage == "voting") and (current_user not in debate.users_voted): canVote = True session["voting_status"] = { "canVote": canVote, "debate_id": debate_id } else: canVote = False template_payload["auth_url"] = g.auth_url try: if (debate.time_for_next_phase is not None) and ( debate.time_for_next_phase < datetime.datetime.utcnow()): if (debate.stage == "voting"): debate.stage = "finished" debate.current_round_number += 1 if debate.pro_votes > debate.con_votes: user_pro.wins += 1 user_con.losses += 1 elif debate.con_votes > debate.pro_votes: user_con.wins += 1 user_pro.losses += 1 elif (user_pro is not None) and (user_con is not None): if (debate.stage == "pro") or (debate.stage == "con"): claim = Claim() claim.enthymeme_claim = " " claim.enthymeme_justification = " " claim.round_number = debate.current_round_number claim.user_type = debate.stage debate.claims.append(claim) switch_from_pro_to_con(debate) move_to_voting_mode_if_finished(debate) db.session.commit() manage_debate_end_emails(debate, user_pro, user_con) except: pass if (debate.stage == "voting" or debate.stage == "finished"): template_payload["pro_votes"] = debate.pro_votes template_payload["canVote"] = canVote template_payload["con_votes"] = debate.con_votes try: template_payload["user"] = challenger except: template_payload["user"] = None template_payload["rounds"] = rounds template_payload["max_round_number"] = mrn template_payload["round_num"] = debate.current_round_number template_payload["debate_topic"] = debate.topic template_payload["user_pro"] = user_pro template_payload["user_con"] = user_con template_payload["debate_id"] = debate_id template_payload["debate_stage"] = debate.stage template_payload["is_timed"] = debate.isTimed template_payload["debate_time"] = debate.time_for_next_phase return render_template("debate_synopsis.html", server_data=template_payload)