def test_text_to_html_can_preserve_line_breaks(): assert text_to_html("First line.\r\nSecond line.", preserve_line_breaks=True) == \ Markup("First line.<br>Second line.") assert text_to_html("First line.\r\nSecond line.", preserve_line_breaks=False) == \ Markup("First line.\r\nSecond line.") assert text_to_html("First line.\r\nSecond line.") == \ Markup("First line.\r\nSecond line.")
def supplier_questions(framework_slug, lot_slug, brief_id): get_framework_and_lot(framework_slug, lot_slug, data_api_client, allowed_statuses=['live', 'expired'], must_allow_brief=True) brief = data_api_client.get_brief(brief_id)["briefs"] if not is_brief_correct(brief, framework_slug, lot_slug, current_user.id, allowed_statuses=['live']): abort(404) # Get Q&A in format suitable for govukSummaryList for index, question in enumerate(brief['clarificationQuestions']): question["key"] = { "html": f"{str(index + 1)}. " f"{text_to_html(question['question'], format_links=True, preserve_line_breaks=True)}" } question["value"] = { "html": text_to_html(question["answer"], format_links=True, preserve_line_breaks=True) } return render_template("buyers/supplier_questions.html", brief=brief)
def get_brief_by_id(framework_family, brief_id): frameworks = data_api_client.find_frameworks()['frameworks'] frameworks = [ framework for framework in frameworks if framework['framework'] == framework_family ] framework = get_latest_live_framework_or_404(frameworks, framework_family) abort_if_not_further_competition_framework(framework) briefs = data_api_client.get_brief(brief_id) brief = briefs.get('briefs') if brief['status'] not in PUBLISHED_BRIEF_STATUSES or brief['framework'][ 'family'] != framework_family: abort(404, "Opportunity '{}' can not be found".format(brief_id)) brief_responses = data_api_client.find_brief_responses( brief_id=brief_id, status=",".join(ALL_BRIEF_RESPONSE_STATUSES), with_data=False, ).get('briefResponses') winning_response, winning_supplier_size = None, None if brief['status'] == 'awarded': winning_response = next( response for response in brief_responses if response["id"] == brief['awardedBriefResponseId']) winning_supplier_size = format_winning_supplier_size( winning_response["supplierOrganisationSize"]) brief_responses_stats = count_brief_responses_by_size_and_status( brief_responses) if brief['status'] not in PUBLISHED_BRIEF_STATUSES or brief['framework'][ 'family'] != framework_family: abort(404, "Opportunity '{}' can not be found".format(brief_id)) try: has_supplier_responded_to_brief = (current_user.supplier_id in [ res['supplierId'] for res in brief_responses if res["status"] in COMPLETED_BRIEF_RESPONSE_STATUSES ]) except AttributeError: has_supplier_responded_to_brief = False # Get Q&A in format suitable for govukSummaryList for index, question in enumerate(brief['clarificationQuestions']): question["key"] = { "html": f"{str(index + 1)}. " f"{text_to_html(question['question'], format_links=True, preserve_line_breaks=True)}" } question["value"] = { "html": text_to_html(question["answer"], format_links=True, preserve_line_breaks=True) } brief_content = content_loader.get_manifest(brief['frameworkSlug'], 'display_brief').filter(brief) # Get attributes in format suitable for govukSummaryList brief_summary = brief_content.summary(brief) for section in brief_summary: section.summary_list = to_summary_list_rows(section.questions, format_links=True, filter_empty=False) return render_template( 'brief.html', brief=brief, brief_responses_stats=brief_responses_stats, content=brief_content, brief_content_summary=brief_summary, has_supplier_responded_to_brief=has_supplier_responded_to_brief, winning_response=winning_response, winning_supplier_size=winning_supplier_size, )
def test_text_to_html_can_format_links(): assert text_to_html("https://gov.uk", format_links=True) == \ Markup('<a href="https://gov.uk" class="govuk-link" rel="external">https://gov.uk</a>') assert text_to_html("https://gov.uk", format_links=False) == "https://gov.uk" assert text_to_html("https://gov.uk") == "https://gov.uk"
def test_text_to_html_can_capitalize_first_letter(): assert text_to_html("hello world", capitalize_first=True) == "Hello world" assert text_to_html("hello world", capitalize_first=False) == "hello world" assert text_to_html("hello world") == "hello world"
def test_text_to_html_takes_one_string_value_and_returns_markup(): assert text_to_html("") == Markup("") assert text_to_html("Hello World") == Markup("Hello World")