def add_clar(): """ Adds or edits a clarification Note: must be called from within a request context Returns: a redirect to the clarification view page """ subject = request.form.get("subject") contents = request.form.get("contents") if subject is None: error = "Failed to add clarification due to undefined subject." current_app.logger.info(error) flash(error, "danger") return redirect(url_for("clarifications.clarifications_view")) if contents is None: error = "Failed to add clarification due to undefined contents." current_app.logger.info(error) flash(error, "danger") return redirect(url_for("clarifications.clarifications_view")) thread = str(uuid.uuid4()) is_public = True # This is a general clarification, which are always public clar = model.Clarification(current_user, subject, contents, thread, is_public) db_session.add(clar) db_session.commit() return redirect(url_for("clarifications.clarifications_view"))
def test_clarification(self): """test the clarification table""" contest_args, contest = get_contest() problem_args, problem = get_problem() user_args, user = get_user() CLARIFICATION_ARGS = { "initiating_user": user, "subject": "Test subject", "contents": "What is this thing?", "thread": "", "is_public": False, } clarification = model.Clarification(**CLARIFICATION_ARGS) db_session.add(clarification) db_session.commit()
def add_clar(): """ Adds a clarification Note: must be called from within a request context Returns: a redirect to the clarification view page """ problem_input = request.form.get("problem") subject = request.form.get("subject") contents = request.form.get("contents") if subject is None: error = "Failed to add clarification due to undefined subject." current_app.logger.info(error) flash(error, "danger") return redirect(url_for("clarifications.clarifications_view")) if contents is None: error = "Failed to add clarification due to undefined contents." current_app.logger.info(error) flash(error, "danger") return redirect(url_for("clarifications.clarifications_view")) if ( problem_input is None ): # We check the problem input here because we can have a general clarification that would be a null problem in the database error = "Failed to add clarification due to undefined problem." current_app.logger.info(error) flash(error, "danger") return redirect(url_for("clarifications.clarifications_view")) problem = model.Problem.query.filter_by(name=problem_input).first() clar = model.Clarification(problem, current_user, subject, contents, False) db_session.add(clar) db_session.commit() return redirect(url_for("clarifications.clarifications_view"))
def test_clarification(self): """test the clarification table""" contest_args, contest = get_contest() problem_args, problem = get_problem() user_args, user = get_user() CLARIFICATION_ARGS = { "problem": problem, "initiating_user": user, "subject": "Test subject", "contents": "What is this thing?", "is_public": False, } clarification = model.Clarification(**CLARIFICATION_ARGS) db_session.add(clarification) db_session.commit() results = model.Clarification.query.filter_by( subject=CLARIFICATION_ARGS["subject"]).all() self.assertEqual(len(results), 1)
def submit_clarification(): subject = request.json.get("subject", None) contents = request.json.get("contents", None) problem_slug = request.json.get("problem_slug", None) parent_id = request.json.get("parent_id", None) problem = model.Problem.query.filter_by(slug=problem_slug).scalar() thread = "" if parent_id is None: thread = str(uuid.uuid4()) else: thread = model.Clarification.query.filter_by(id=parent_id).scalar().thread is_public = False # user submitted clarifications are always false clar = model.Clarification(current_user, subject, contents, thread, is_public) clar.problem = problem db_session.add(clar) db_session.commit() return "{}"