def add_position_with_premise(request): db_user: User = request.validated['user'] db_issue: Issue = request.validated['issue'] reference_text: str = request.validated['reference'] origin: DataOrigin = request.validated['origin'] history = history_handler.save_and_set_cookie(request, db_user, db_issue) host, path = split_url(request.environ.get("HTTP_REFERER")) new_position = set_position(db_user, db_issue, request.validated['position-text']) conclusion_id: int = new_position['statement_uids'][0] db_conclusion: Statement = DBDiscussionSession.query(Statement).get( conclusion_id) pd = set_positions_premise(db_issue, db_user, db_conclusion, [[request.validated['reason-text']]], True, history, request.mailer) statement_uids: List[int] = flatten(pd['statement_uids']) LOG.info("Created %d statements: %s", len(statement_uids), statement_uids) __store_origin_and_reference(db_issue, db_user, origin, host, path, reference_text, statement_uids) if origin: add_origin_for_list_of_statements(origin, new_position['statement_uids']) add_origin_for_list_of_statements(origin, flatten(pd['statement_uids'])) return __http_see_other_with_cors_header('/api' + pd['url'])
def add_premise_to_statement(request: IRequest): db_user: User = request.validated['user'] db_issue: Issue = request.validated['issue'] db_statement: Statement = request.validated['statement'] reference_text: str = request.validated['reference'] is_supportive = request.validated['attitude'] == Attitudes.AGREE origin: DataOrigin = request.validated['origin'] history = history_handler.save_and_set_cookie(request, db_user, db_issue) host, path = split_url(request.environ.get("HTTP_REFERER")) pd = set_positions_premise(db_issue, db_user, db_statement, [[request.validated['reason-text']]], is_supportive, history, request.mailer) __store_origin_and_reference(db_issue, db_user, origin, host, path, reference_text, flatten(pd['statement_uids'])) return __http_see_other_with_cors_header('/api' + pd['url'])
def test_flatten(): l1 = [[1]] l2 = [[1, 2]] l3 = [[1, 2], [3]] l4 = [[1, 2], [3, 4]] l5 = [[1, 2], [3], [4]] l6 = [] assert flatten(l1) == [1] assert flatten(l2) == [1, 2] assert flatten(l3) == [1, 2, 3] assert flatten(l4) == [1, 2, 3, 4] assert flatten(l5) == [1, 2, 3, 4] assert flatten(l6) is None