[Python] Why isn't the flash() in flask-admin showing for this specific case, while showing...

Discussão em 'Python' iniciado por Stack, Março 25, 2025.

  1. Stack

    Stack Membro Participativo

    I can't figure out why, when I use this method to generate the flash_message on flash_message2 and flash_message3 it works fine and it shows, when I attempt to return my actual one that I intend to return the flash_message the flash message doesn't even show up, this is my code:

    def generate_briefing_report(all_data_list, invalids_list, identifier_field: str, title: str = "Report",
    operation_title="Operation Summary:", button_enabled=True):
    formatted_operation_summary_top_message = ""

    # All Valid OR partial valid
    calculated_disparity = len(all_data_list) - len(invalids_list)
    if calculated_disparity == len(all_data_list) or (
    calculated_disparity > 0 and calculated_disparity < len(all_data_list)):
    formatted_operation_summary_top_message += f"[✔] Number of successful operations: {calculated_disparity}"

    # All are invalid OR partial Invalid
    copyable_erroneous_values = None
    if calculated_disparity == 0 or (calculated_disparity > 0 and calculated_disparity < len(all_data_list)):
    if formatted_operation_summary_top_message:
    formatted_operation_summary_top_message += "<br/>"

    formatted_operation_summary_top_message += f"[❌] Number of unsuccessful operations: {len(invalids_list)} "
    copyable_erroneous_values = ", ".join(record["order_number"] for record in invalids_list)

    operation_summary_message = Markup(formatted_operation_summary_top_message)
    valid_total = calculated_disparity
    invalid_total = len(invalids_list)

    copy_failed_button_html = ""
    if button_enabled and copyable_erroneous_values:
    copy_failed_button_html = f"""
    <button style="cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; border-radius: 5px; background-color: #f0f0f0;" onclick="var textArea = document.createElement('textarea'); textArea.value = '{copyable_erroneous_values}'; document.body.appendChild(textArea); textArea.select(); document.execCommand('Copy'); textArea.remove(); showToast();">Copy Failed to clipboard </button>
    """ if invalid_total > 0 else ""

    data_list = []
    for index, record in enumerate(invalids_list, start=1):
    data_list.append([index, record[identifier_field], record["error"]])

    settings = {
    "title": title,
    "identifier_title": identifier_field
    }

    error_id = str(uuid.uuid4())
    session[error_id] = {
    'settings': settings,
    'data': data_list
    }

    report_url = url_for('error_report', error_id=error_id)
    open_errors_view_button_html = Markup(f"""
    <button style="cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; border-radius: 5px; background-color: #f0f0f0;" onclick="window.open('{report_url}', '_blank')">View Error Details</button>
    """)

    flash_message = Markup(f"""
    <div>
    <strong>{operation_title}</strong><br/> {operation_summary_message} {open_errors_view_button_html}<br/><br/>
    </div>
    """)

    flash_message2 = Markup(f"""
    <div>
    <strong>{operation_title}</strong><br/> {operation_summary_message}<br/><br/>
    </div>
    """)

    flash_message3 = Markup(f"""
    <div>
    {open_errors_view_button_html}<br/><br/>
    </div>
    """)
    return flash_message


    when I attempt to flash this:

    flash_message = Markup(f"""
    <div>
    <strong>{operation_title}</strong><br/> {operation_summary_message} {open_errors_view_button_html}<br/><br/>
    </div>
    """)


    It just doesn't show.

    Continue reading...

Compartilhe esta Página