From 283a4c7b8dcc60242737a5b9760813bd7222cb5e Mon Sep 17 00:00:00 2001
From: grant-sea <129594788+grant-sea@users.noreply.github.com>
Date: Sat, 1 Apr 2023 23:12:03 +0800
Subject: [PATCH 1/2] Add an optional parameter for render_table()
Add an optional parameter for render_table() to allow setting the location of the actions column. The two options are "front" (the 1st column of the table) and "end" (default value, the last column of the table).
---
flask_bootstrap/templates/base/table.html | 39 +++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/flask_bootstrap/templates/base/table.html b/flask_bootstrap/templates/base/table.html
index bf561a76..13dd5e8a 100644
--- a/flask_bootstrap/templates/base/table.html
+++ b/flask_bootstrap/templates/base/table.html
@@ -39,6 +39,7 @@
model=None,
show_actions=False,
actions_title='Actions',
+ actions_location='end',
custom_actions=None,
view_url=None,
edit_url=None,
@@ -57,9 +58,11 @@
{% endif %}
{% for row in data %}
+ {% if actions_location != 'front' %}
{% for title in titles %}
{% set key = title[0] %}
{% set value = row[key] %}
@@ -107,6 +116,7 @@
{%- endif -%}
{% endfor %}
+ {% endif %}
{% if show_actions %}
{% if custom_actions %}
@@ -161,6 +171,35 @@
{% endif %}
|
{% endif %}
+ {% if actions_location == 'front' %}
+ {% for title in titles %}
+ {% set key = title[0] %}
+ {% set value = row[key] %}
+ {%- if key == primary_key -%}
+
+ {%- else -%}
+ |
+ {%- endif -%}
+ {%- if value is string -%}
+ {%- if safe_columns and key in safe_columns -%}
+ {{ value|safe }}
+ {%- else -%}
+ {%- if urlize_columns and key in urlize_columns -%}
+ {{ value|urlize }}
+ {%- else -%}
+ {{ value }}
+ {%- endif -%}
+ {%- endif -%}
+ {%- else -%}
+ {{ value }}
+ {%- endif -%}
+ {%- if key == primary_key -%}
+
+ {%- else -%}
+ |
+ {%- endif -%}
+ {% endfor %}
+ {% endif %}
{% endfor %}
From 45346a188d0abf8d167c386ec4e4d2b737bef4a0 Mon Sep 17 00:00:00 2001
From: grant-sea <129594788+grant-sea@users.noreply.github.com>
Date: Sun, 9 Apr 2023 21:18:27 +0800
Subject: [PATCH 2/2] Add an optional parameter for render_table()
Use boolean type for the optional parameter (actions_first). Setting parameter for the repeating block in the template to make the codes more compact.
---
flask_bootstrap/templates/base/table.html | 101 +++++++++-------------
1 file changed, 39 insertions(+), 62 deletions(-)
diff --git a/flask_bootstrap/templates/base/table.html b/flask_bootstrap/templates/base/table.html
index 13dd5e8a..b5818f85 100644
--- a/flask_bootstrap/templates/base/table.html
+++ b/flask_bootstrap/templates/base/table.html
@@ -39,7 +39,7 @@
model=None,
show_actions=False,
actions_title='Actions',
- actions_location='end',
+ actions_first=False,
custom_actions=None,
view_url=None,
edit_url=None,
@@ -58,10 +58,10 @@
{% endif %}
{% for row in data %}
- {% if actions_location != 'front' %}
- {% for title in titles %}
- {% set key = title[0] %}
- {% set value = row[key] %}
- {%- if key == primary_key -%}
-
- {%- else -%}
- |
- {%- endif -%}
- {%- if value is string -%}
- {%- if safe_columns and key in safe_columns -%}
- {{ value|safe }}
+ {% set show_main_cols %}
+ {% for title in titles %}
+ {% set key = title[0] %}
+ {% set value = row[key] %}
+ {%- if key == primary_key -%}
+ |
{%- else -%}
- {%- if urlize_columns and key in urlize_columns -%}
- {{ value|urlize }}
+ |
+ {%- endif -%}
+ {%- if value is string -%}
+ {%- if safe_columns and key in safe_columns -%}
+ {{ value|safe }}
{%- else -%}
- {{ value }}
+ {%- if urlize_columns and key in urlize_columns -%}
+ {{ value|urlize }}
+ {%- else -%}
+ {{ value }}
+ {%- endif -%}
{%- endif -%}
+ {%- else -%}
+ {{ value }}
{%- endif -%}
- {%- else -%}
- {{ value }}
- {%- endif -%}
- {%- if key == primary_key -%}
-
- {%- else -%}
- |
- {%- endif -%}
- {% endfor %}
- {% endif %}
+ {%- if key == primary_key -%}
+
+ {%- else -%}
+
+ {%- endif -%}
+ {% endfor %}
+ {% endset %}
+ {% if not actions_first %}
+ {{show_main_cols}}
+ {% endif %}
{% if show_actions %}
{% if custom_actions %}
@@ -171,34 +174,8 @@
{% endif %}
|
{% endif %}
- {% if actions_location == 'front' %}
- {% for title in titles %}
- {% set key = title[0] %}
- {% set value = row[key] %}
- {%- if key == primary_key -%}
-
- {%- else -%}
- |
- {%- endif -%}
- {%- if value is string -%}
- {%- if safe_columns and key in safe_columns -%}
- {{ value|safe }}
- {%- else -%}
- {%- if urlize_columns and key in urlize_columns -%}
- {{ value|urlize }}
- {%- else -%}
- {{ value }}
- {%- endif -%}
- {%- endif -%}
- {%- else -%}
- {{ value }}
- {%- endif -%}
- {%- if key == primary_key -%}
-
- {%- else -%}
- |
- {%- endif -%}
- {% endfor %}
+ {% if actions_first %}
+ {{show_main_cols}}
{% endif %}
{% endfor %}