{#- ---------------------------------------------------------------------------- Macro for rendering a form widget in default style. ----------------------------------------------------------------------------- #} {%- macro render_form_item_default(form_item, with_errors = True, placeholder = None) %}
{{ render_form_label_help(form_item) }} {{ form_item(placeholder=placeholder or '', **kwargs) }} {%- if with_errors %} {{ render_form_feedback(form_item, bound_to_input = True) }} {%- endif %}
{%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering a form select widget with selectpicker class. ----------------------------------------------------------------------------- #} {%- macro render_form_item_select(form_item, with_errors = True, empty_message=_('Nothing selected'), class_ = "") %}
{{ render_form_label_help(form_item) }} {{ form_item(**{'data-none-selected-text': empty_message, 'class_': class_}) }} {%- if with_errors %} {{ render_form_feedback(form_item, bound_to_input = True) }} {%- endif %}
{%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering a form widget with datetime selection class. ----------------------------------------------------------------------------- #} {%- macro render_quick_options_dropdown(form_item, icon) %} {%- if form_item.quick_options %} {%- endif %} {%- endmacro %} {%- macro render_form_item_datetime(form_item, ident, with_errors = True, use_seconds = False, use_current = False, form = None, idea_help = False) %}
{%- call render_form_label_help_html(form_item) %} {%- if idea_help %} {{ render_help_idea_reference() }} {%- endif %} {{ render_help_datetime(form_item) }} {%- endcall %} {%- set low_high_group = form and form.get_low_high_group and form.get_low_high_group(form_item.name) %} {%- set low_high = form and form.get_low_high and form.get_low_high(form_item.name) %}
{{ form_item(data_td_target = "#" + ident, **kwargs) }} {{ render_quick_options_dropdown(form_item, get_icon("clock")) }} {%- if with_errors %} {{ render_form_feedback(form_item, bound_to_input = True) }} {%- endif %}
{{ _('Note: Your selected timezone is "%(tz)s"', tz = session.timezone) | safe }}
{%- endmacro %} {%- macro render_form_item_with_quick_options(form_item, ident, icon, with_errors = True) %}
{{ render_form_label_help(form_item) }}
{{ form_item() }} {{ render_quick_options_dropdown(form_item, icon) }}
{%- if with_errors %} {{ render_form_feedback(form_item, bound_to_input = True) }} {%- endif %}
{%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering a static form widget. ----------------------------------------------------------------------------- #} {%- macro render_form_item_static(form_item_label, form_item_value) %}

{{ form_item_value }}

{%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering a radio button form widget. ----------------------------------------------------------------------------- #} {%- macro render_form_item_radiobutton(form_item, with_errors = True, equally_big = False) %}
{{ render_form_label_help(form_item) }}
{%- for subfield in form_item %} {{ subfield(class_='btn-check') }} {{ subfield.label(class_='btn btn-outline-secondary' + (' w-100' if equally_big else '')) }} {%- endfor %}
{%- if with_errors %} {{ render_form_feedback(form_item, bound_to_input = True) }} {%- endif %}
{%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering a form field with a ransack query. ----------------------------------------------------------------------------- #} {%- macro render_form_item_ransack(form_item, with_errors = True, placeholder = None, full_completion = True) %}
{%- call render_form_label_help_html(form_item) %}

{{ _('For more in-depth information about the syntax, please study the official documentation webpage.', url = 'https://ransack-125e0a.gitlab-pages.cesnet.cz/language.html') }}

{%- endcall %}
{{ form_item(class_='monaco-hidden-input', placeholder=placeholder, hidden=true, **kwargs) }} {{ render_form_feedback(form_item, true) }}
{%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering a list of errors associated with given form widget. ----------------------------------------------------------------------------- #} {%- macro render_form_feedback(field, bound_to_input=false) %} {%- if field.errors %} {%- for err in field.errors %} {{ get_icon("form-error") }} {{ err }} {%- if not bound_to_input and not loop.last %}
{%- endif %} {%- endfor %} {%- elif field.warnings %} {%- for warn in field.warnings %} {{ get_icon("form-warning") }} {{ warn }} {%- if not bound_to_input and not loop.last %}
{%- endif %} {%- endfor %} {%- endif %} {%- endmacro %} {%- macro render_form_feedback_labeled(item, bound_to_input=false) %} {%- if item.errors %} {%- for err in item.errors %}
{{ get_icon("form-error") }} {{ item.label.text }} {{ err }}
{%- endfor %} {%- elif item.warnings %} {%- for warn in item.warnings %}
{{ get_icon("form-warning") }} {{ item.label.text }} {{ warn }}
{%- endfor %} {%- endif %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering a label with given form widget. ----------------------------------------------------------------------------- #} {%- macro render_form_label_help(item, icon='', placement = 'top') %}
{{ icon }} {%- if item.description %}
{{ get_icon("help") }}

{{ get_icon("help") }} {{ item.label.text }}

{{ item.description | safe }}

{%- endif %} {{ item.label(class='form-label') }} {%- if item.flags.required %} *{% endif %}
{%- endmacro %} {%- macro render_form_label_help_html(item, icon='', placement = 'top') %}
{{ icon }}
{{ get_icon("help") }}

{{ get_icon("help") }} {{ item.label.text }}

{%- if item.description %}

{{ item.description | safe }}

{%- endif %} {{ caller() }} {%- if hawat_current_view.has_help %}

{{ macros_page.render_help_link(icon = 'reference', text = _('more help'), tooltip_text = '') }}

{%- endif %}
{{ item.label(class_='form-label') }} {%- if item.flags.required %} *{% endif %}
{%- endmacro %} {%- macro render_help_idea_reference() %}

{{ _('For more in-depth information about the IDEA event format please study official documentation webpage.', url = 'https://idea.cesnet.cz/en/definition') }}

{%- endmacro %} {%- macro render_help_datetime(form_item) %}

{%- if form_item.ALLOWS_RELATIVE_TIME and not form_item.description %} {# If the form field allows for relative time, add relative time description unless the field already has description defined #} {{ _('User may change his/her timezone preferences in his/her account settings. Alternatively you may use a time delta in the format nYnMnDnHnMn.nnS relative to the current time or unambiguous explicit UTC timestamps in the format YYYY-MM-DDThh:mm:ssZ. UTC timestamps are particularly useful for pre-generated URLs, that are independent of the user preferences.', url = url_for('users.me')) }} {%- else %} {{ _('User may change his/her timezone preferences in his/her account settings. Alternatively you may use unambiguous explicit UTC timestamps in the format YYYY-MM-DDThh:mm:ssZ. UTC timestamps are particularly useful for pre-generated URLs, that are independent of the user preferences.', url = url_for('users.me')) }} {%- endif %}

{%- endmacro %} {%- macro render_help_currenttz() %}
{{ _('Note: Your selected timezone is "%(tz)s"', tz = session.timezone) | safe }}
{%- endmacro %} {%- macro render_admin_update_warning() %} {%- if not hawat_current_app.config.DEBUG and permission_can('admin') %} {%- endif %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macros for rendering stored-query-related form widgets ----------------------------------------------------------------------------- #} {#- ---------------------------------------------------------------------------- Macros for rendering the save-query controls: the "Save" / "Save As" buttons and the "Save As" modal dialog. Renders two buttons: - **Save** (only when a stored query is being edited and the current user may edit it): submits the whole search form directly to the stored-query *update* endpoint (``formmethod="POST"`` + ``formaction``), updating only the stored filter parameters. It carries ``target`` itself and, together with the disabled ``csrf_token`` and ``submit`` inputs below (enabled by JS on click), sends nothing else but the search filter values. - **Save As**: opens the modal dialog below, which asks for the new query's name and description and POSTs to the stored-query *create* endpoint. Created queries are always private; sharing is performed separately from the stored query list view. Both macros must be called INSIDE the search ``
`` element: their fields are part of the search form and are wrapped in ``
`` blocks which are enabled only while the modal is open (``save-as-query-fields``) or while a save-query submission is in progress (``save-query-fields``). Because the fieldsets are disabled otherwise, the save-only fields (query_name, query_description, target, csrf_token) are excluded from normal GET search submissions. ``render_save_query_modal`` must be rendered before the search form's own submit button in tree order in order for implicit submit using enter to work correctly. :param form: The search form (must be a StoredQueryFormMixin subclass). ----------------------------------------------------------------------------- #} {%- macro render_save_query_buttons(form) %} {%- if hawat_current_view.supports_stored_queries and 'stored_queries' in hawat_current_app.blueprints %} {%- set editing = form.editing_query.data %} {%- set can_save = form.can_user_save_editing_query() %} {%- if editing %} {{ form.editing_query() }} {%- endif %}
{%- if editing and can_save %} {%- if editing.scope == '__GLOBAL__' %} {%- set btn_class = 'btn-danger' %} {%- set btn_title = _('You are editing a globally published query. Changes will affect all users.') %} {%- elif editing.scope == '__GROUP__' %} {%- set btn_class = 'btn-info text-light' %} {%- set btn_title = _('You are editing a group query. Any group member can see and modify it.') %} {%- else %} {%- set btn_class = 'btn-success' %} {%- set btn_title = _('You are editing your private query.') %} {%- endif %} {%- endif %}
{%- endif %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering the "Save As" modal dialog belonging to the buttons rendered by :func:`render_save_query_buttons`. See the documentation of that macro for details, especially the tree-order requirement for this macro. :param form: The search form (must be a StoredQueryFormMixin subclass). ----------------------------------------------------------------------------- #} {%- macro render_save_query_modal(form) %} {%- if hawat_current_view.supports_stored_queries and 'stored_queries' in hawat_current_app.blueprints %} {%- set editing = form.editing_query.data %} {%- set can_save = form.can_user_save_editing_query() %} {# Save As New Query Modal #} {%- endif %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering a link to the stored query list, filtered to queries supported by the current view. :param form: The search form (must be a StoredQueryFormMixin subclass). ----------------------------------------------------------------------------- #} {%- macro render_query_list_link(form) %} {%- if form.editing_query is defined and hawat_current_view.supports_stored_queries and 'stored_queries' in hawat_current_app.blueprints %} {{ get_icon('module-stored-queries') }} {{ _('My Queries') }} {%- endif %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering a badge with the name of the currently loaded stored query. Intended for display within the main page title. The badge color matches the query scope (private/group/global), as does the "Save" button rendered by :func:`render_save_query_buttons`. :param form: The search form (must be a StoredQueryFormMixin subclass). ----------------------------------------------------------------------------- #} {%- macro render_editing_query_badge(form) %} {%- if form.editing_query is defined and hawat_current_view.supports_stored_queries and 'stored_queries' in hawat_current_app.blueprints %} {%- set editing = form.editing_query.data %} {%- if editing %} {%- if editing.scope == '__GLOBAL__' %} {%- set badge_class = 'bg-danger' %} {%- elif editing.scope == '__GROUP__' %} {%- set badge_class = 'bg-info' %} {%- else %} {%- set badge_class = 'bg-success' %} {%- endif %} {{ editing.name }} {%- endif %} {%- endif %} {%- endmacro %}