{% from 'bootstrap/utils.html' import render_icon, arg_url_for %} {% macro deprecate_placeholder_url() %} {{ warn('Passing an URL with primary key palceholder for view_url/edit_url/delete_url/custom_actions is deprecated. You will need to pass an fixed URL or an URL tuple to URL arguments, see the docs for more details (https://bootstrap-flask.readthedocs.io/en/stable/macros.html#render-table). The support to URL string will be removed in version 2.0.', stacklevel=2) }} {% endmacro %} {% macro build_url(endpoint, model, pk, url_tuples) %} {% if model == None %} {{ raise("The model argument can't be None when setting action URLs.") }} {% endif %} {% with url_params = {} -%} {%- do url_params.update(request.view_args if not endpoint else {}), url_params.update(request.args if not endpoint else {}) -%} {% with record = model.query.get(pk) %} {% for url_parameter, db_field in url_tuples %} {% if db_field.startswith(':') and '.' in db_field %} {%- set db_field = db_field[1:].split('.') -%} {%- do url_params.update({url_parameter: record[db_field[0]][db_field[1]]}) -%} {% elif db_field.startswith(':') %} {%- set db_field = db_field[1:] -%} {%- do url_params.update({url_parameter: record[db_field]}) -%} {% else %} {%- do url_params.update({url_parameter: db_field}) -%} {% endif %} {% endfor %} {% endwith -%} {{ arg_url_for(endpoint, url_params) }} {%- endwith %} {%- endmacro %} {% macro render_table(data, titles=None, primary_key='id', primary_key_title='#', caption=None, table_classes=None, header_classes=None, responsive=False, responsive_class='table-responsive', model=None, show_actions=False, actions_title='Actions', custom_actions=None, view_url=None, edit_url=None, delete_url=None, new_url=None, action_pk_placeholder=':id') %} {% if not titles %} {% set titles = get_table_titles(data, primary_key, primary_key_title) %} {% endif %} {% if responsive %}
{{ title[1] }} | {% endfor %} {% if show_actions %}{{ actions_title }} {% if new_url %} {{ render_icon('plus-circle-fill') }} {% endif %} | {% endif %}|
---|---|---|
{{ row[title[0]] }} | {% else %}{{ row[title[0]] }} | {% endif %} {% endfor %} {% if show_actions %}{% if custom_actions %} {% for (action_name, action_icon, action_url) in custom_actions %} {% if ':primary_key' in action_url | join('') %} {% set action_pk_placeholder = ':primary_key' %} {% endif %} {{ render_icon(action_icon) }} {% endfor %} {% endif %} {% if view_url %} {% if ':primary_key' in view_url | join('') %} {% set action_pk_placeholder = ':primary_key' %} {% endif %} {{ render_icon('eye-fill') }} {% endif %} {% if edit_url -%} {% if ':primary_key' in edit_url | join('') %} {% set action_pk_placeholder = ':primary_key' %} {% endif %} {{ render_icon('pencil-fill') }} {%- endif %} {% if delete_url %} {% if ':primary_key' in delete_url | join('') %} {% set action_pk_placeholder = ':primary_key' %} {% endif %} {% endif %} | {% endif %}