flask-construct-ui 0.12.4__tar.gz → 0.13.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/PKG-INFO +1 -1
  2. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/base.py +92 -18
  3. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/rcrud.py +4 -0
  4. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/css/whitelabel.css +25 -0
  5. flask_construct_ui-0.13.0/flask_construct_ui/templates/crud/_actions.html +46 -0
  6. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/crud/edit.html +3 -13
  7. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/crud/listindex.html +2 -5
  8. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/crud/related_crud_tab_form.html +2 -8
  9. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/crud/related_crud_tab_list.html +2 -8
  10. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/crud/view.html +2 -7
  11. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui.egg-info/PKG-INFO +1 -1
  12. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui.egg-info/SOURCES.txt +1 -0
  13. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/pyproject.toml +1 -1
  14. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/LICENSE +0 -0
  15. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/README.md +0 -0
  16. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/__init__.py +0 -0
  17. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/app_hooks.py +0 -0
  18. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/auth.py +0 -0
  19. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/capabilities.py +0 -0
  20. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/cli.py +0 -0
  21. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/components/__init__.py +0 -0
  22. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/components/calendar.py +0 -0
  23. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/components/chart.py +0 -0
  24. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/components/chart_native.py +0 -0
  25. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/components/content.py +0 -0
  26. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/components/core.py +0 -0
  27. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/components/grid.py +0 -0
  28. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/components/kanban.py +0 -0
  29. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/components/layout.py +0 -0
  30. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/components/live.py +0 -0
  31. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/components/period.py +0 -0
  32. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/components/pivot.py +0 -0
  33. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/contrast.py +0 -0
  34. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/crud.py +0 -0
  35. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/crud_forms.py +0 -0
  36. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/csrf.py +0 -0
  37. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/data.py +0 -0
  38. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/data_sqlalchemy.py +0 -0
  39. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/dragdrop.py +0 -0
  40. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/errors.py +0 -0
  41. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/flashes.py +0 -0
  42. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/forms.py +0 -0
  43. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/grid.py +0 -0
  44. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/headless.py +0 -0
  45. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/icons.py +0 -0
  46. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/l10n/en/main.flt +0 -0
  47. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/l10n/sv/main.flt +0 -0
  48. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/language.py +0 -0
  49. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/layout.py +0 -0
  50. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/live.py +0 -0
  51. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/menu.py +0 -0
  52. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/navbar.py +0 -0
  53. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/navigation.py +0 -0
  54. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/orgmode.py +0 -0
  55. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/pagination.py +0 -0
  56. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/py.typed +0 -0
  57. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/resume.py +0 -0
  58. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/sanitize.py +0 -0
  59. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/schema.py +0 -0
  60. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/css/grid.css +0 -0
  61. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/css/prosemirror-bundle.min.css +0 -0
  62. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/css/unpoly.min.css +0 -0
  63. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/designs/adminlte.css +0 -0
  64. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/designs/sandstone.css +0 -0
  65. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/fonts/bootstrap-icons/LICENSE.txt +0 -0
  66. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/fonts/bootstrap-icons/bootstrap-icons.min.css +0 -0
  67. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/fonts/bootstrap-icons/fonts/bootstrap-icons.woff +0 -0
  68. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/fonts/bootstrap-icons/fonts/bootstrap-icons.woff2 +0 -0
  69. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/fonts/material-symbols/LICENSE.txt +0 -0
  70. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/fonts/material-symbols/material-symbols-outlined.woff2 +0 -0
  71. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/fonts/material-symbols/material-symbols.css +0 -0
  72. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/fonts/material-symbols/names.txt +0 -0
  73. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/js/construct-core.min.js +0 -0
  74. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/js/construct-grid.min.js +0 -0
  75. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/js/kanban-dnd.js +0 -0
  76. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/js/prosemirror-bundle.min.js +0 -0
  77. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/static/js/unpoly.min.js +0 -0
  78. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/_form_field.html +0 -0
  79. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/button.html +0 -0
  80. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/calendar.html +0 -0
  81. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/calendarmini.html +0 -0
  82. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/card.html +0 -0
  83. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/chart.html +0 -0
  84. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/chart_native.html +0 -0
  85. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/form.html +0 -0
  86. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/grid.html +0 -0
  87. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/grid_layout.html +0 -0
  88. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/grid_notice.html +0 -0
  89. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/horizontal_layout.html +0 -0
  90. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/kanban.html +0 -0
  91. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/live.html +0 -0
  92. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/live_refresh.html +0 -0
  93. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/main.html +0 -0
  94. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/markup.html +0 -0
  95. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/period_nav.html +0 -0
  96. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/pivot_form.html +0 -0
  97. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/rich_text.html +0 -0
  98. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/table.html +0 -0
  99. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/tabs.html +0 -0
  100. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/text.html +0 -0
  101. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/components/vertical_layout.html +0 -0
  102. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/crud/_macros.html +0 -0
  103. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/crud/_many_related_options.html +0 -0
  104. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/crud/_related_options.html +0 -0
  105. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/crud/create.html +0 -0
  106. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/crud/tab_view.html +0 -0
  107. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/errors/error.html +0 -0
  108. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/errors/forbidden.html +0 -0
  109. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/navbar/notifications.html +0 -0
  110. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/navbar/search_results.html +0 -0
  111. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/structure/base.html +0 -0
  112. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/structure/public.html +0 -0
  113. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/style/_flashes.html +0 -0
  114. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/style/_footer.html +0 -0
  115. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/style/_menu.html +0 -0
  116. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/style/base_full.html +0 -0
  117. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/templates/style/base_partial.html +0 -0
  118. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/testing.py +0 -0
  119. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/urls.py +0 -0
  120. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui/validation.py +0 -0
  121. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui.egg-info/dependency_links.txt +0 -0
  122. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui.egg-info/requires.txt +0 -0
  123. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/flask_construct_ui.egg-info/top_level.txt +0 -0
  124. {flask_construct_ui-0.12.4 → flask_construct_ui-0.13.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flask-construct-ui
3
- Version: 0.12.4
3
+ Version: 0.13.0
4
4
  Summary: A UI toolkit for Flask with CRUD and component features.
5
5
  Author-email: Olof Tjerngren <olof@tjerngren.net>
6
6
  License-Expression: LGPL-3.0-or-later
@@ -45,9 +45,76 @@ from .urls import apply_trailing_slash as apply_trailing_slash
45
45
  logger = logging.getLogger("flask_construct_ui")
46
46
 
47
47
 
48
- def list_action(name, icon):
48
+ _ACTION_METHODS = ("get", "post")
49
+
50
+
51
+ def _action_info(kind, name, icon, method, confirm):
52
+ """Validate an action decorator's arguments and return its info dict.
53
+
54
+ The route-dependent checks (does the route accept *method*?) need the
55
+ method's ``@expose`` routes, which may be applied before or after the
56
+ action decorator, so they run in ``PageMeta`` (see ``_resolve_action``).
57
+ """
58
+ if method is not None:
59
+ if not isinstance(method, str) or method.lower() not in _ACTION_METHODS:
60
+ raise ValueError(
61
+ f"@{kind}({name!r}): method must be 'get' or 'post', got {method!r}"
62
+ )
63
+ method = method.lower()
64
+ return {"name": name, "icon": icon, "method": method, "confirm": confirm}
65
+
66
+
67
+ def _resolve_action(kind, cls, attr_name, info, url, methods):
68
+ """Build the action entry for one ``@expose`` route of a page method.
69
+
70
+ Without an explicit ``method`` the action follows the route: a route
71
+ that accepts GET is a link (as before), a POST-only route a form.
72
+ """
73
+ accepted = {m.upper() for m in methods}
74
+ where = f"@{kind}({info['name']!r}) on {cls.__name__}.{attr_name} (route {url!r})"
75
+ method = info["method"]
76
+ if method is None:
77
+ if "GET" in accepted:
78
+ method = "get"
79
+ elif "POST" in accepted:
80
+ method = "post"
81
+ else:
82
+ raise ValueError(
83
+ f"{where}: the route accepts neither GET nor POST "
84
+ f"({', '.join(sorted(accepted))}), so it cannot be an action"
85
+ )
86
+ elif method.upper() not in accepted:
87
+ raise ValueError(
88
+ f"{where}: method={method!r} but the route only accepts "
89
+ f"{', '.join(sorted(accepted))}; add {method.upper()!r} to its "
90
+ f"@expose methods"
91
+ )
92
+ if info["confirm"] and method != "post":
93
+ raise ValueError(
94
+ f"{where}: confirm= needs a POST action; an action that is worth "
95
+ f"confirming changes state and should not be a GET link"
96
+ )
97
+ return {
98
+ "endpoint": attr_name,
99
+ "name": info["name"],
100
+ "icon": info["icon"],
101
+ "url": url,
102
+ "method": method,
103
+ "confirm": info["confirm"],
104
+ }
105
+
106
+
107
+ def list_action(name, icon, method=None, confirm=None):
108
+ """Add a per-row action to the CRUD list.
109
+
110
+ ``method`` is ``"get"`` (a link) or ``"post"`` (a small form carrying the
111
+ CSRF token). Left out, it follows the route: GET when the route accepts
112
+ GET, otherwise POST. ``confirm`` is an l10n key for a confirmation text
113
+ shown before a POST action is sent.
114
+ """
115
+
49
116
  def decorator(f):
50
- f._list_action_info = {"name": name, "icon": icon}
117
+ f._list_action_info = _action_info("list_action", name, icon, method, confirm)
51
118
  return f
52
119
 
53
120
  return decorator
@@ -61,9 +128,14 @@ def tab_action(name, icon):
61
128
  return decorator
62
129
 
63
130
 
64
- def edit_action(name, icon):
131
+ def edit_action(name, icon, method=None, confirm=None):
132
+ """Add an action to the record's edit/view header.
133
+
134
+ ``method`` and ``confirm`` work as for :func:`list_action`.
135
+ """
136
+
65
137
  def decorator(f):
66
- f._edit_action_info = {"name": name, "icon": icon}
138
+ f._edit_action_info = _action_info("edit_action", name, icon, method, confirm)
67
139
  return f
68
140
 
69
141
  return decorator
@@ -203,14 +275,15 @@ class PageMeta(type):
203
275
  cls._default_view = p
204
276
 
205
277
  if hasattr(attr, "_list_action_info"):
206
- info = attr._list_action_info
207
278
  cls.list_actions.append(
208
- {
209
- "endpoint": p,
210
- "name": info["name"],
211
- "icon": info["icon"],
212
- "url": url,
213
- }
279
+ _resolve_action(
280
+ "list_action",
281
+ cls,
282
+ p,
283
+ attr._list_action_info,
284
+ url,
285
+ methods,
286
+ )
214
287
  )
215
288
 
216
289
  if hasattr(attr, "_tab_action_info"):
@@ -225,14 +298,15 @@ class PageMeta(type):
225
298
  )
226
299
 
227
300
  if hasattr(attr, "_edit_action_info"):
228
- info = attr._edit_action_info
229
301
  cls.edit_actions.append(
230
- {
231
- "endpoint": p,
232
- "name": info["name"],
233
- "icon": info["icon"],
234
- "url": url,
235
- }
302
+ _resolve_action(
303
+ "edit_action",
304
+ cls,
305
+ p,
306
+ attr._edit_action_info,
307
+ url,
308
+ methods,
309
+ )
236
310
  )
237
311
 
238
312
  # Wrap views
@@ -462,6 +462,8 @@ class RelatedCrudTab:
462
462
  "endpoint": f"rcrud_{tab_key}_{a['endpoint']}",
463
463
  "name": a["name"],
464
464
  "icon": a["icon"],
465
+ "method": a["method"],
466
+ "confirm": a["confirm"],
465
467
  }
466
468
  for a in (
467
469
  rct.child_crud_class.list_actions if rct.child_crud_class else []
@@ -646,6 +648,8 @@ class RelatedCrudTab:
646
648
  ),
647
649
  "name": _ea["name"],
648
650
  "icon": _ea["icon"],
651
+ "method": _ea["method"],
652
+ "confirm": _ea["confirm"],
649
653
  }
650
654
  )
651
655
  return render_template(
@@ -886,6 +886,31 @@ a:hover {
886
886
  color: var(--fcu-danger-fg);
887
887
  }
888
888
 
889
+ /* @edit_action / @list_action controls (crud/_actions.html). A POST action
890
+ is a <form> around a <button>; the form must not break the row/header
891
+ flex layout, and the button must look like the GET action's link. */
892
+ .fcu-action-form {
893
+ display: inline-flex;
894
+ align-items: center;
895
+ margin: 0;
896
+ }
897
+ /* Bare header icon (edit/view page header). */
898
+ .fcu-icon-action {
899
+ display: inline-flex;
900
+ align-items: center;
901
+ padding: 4px;
902
+ border: none;
903
+ background: transparent;
904
+ color: var(--fcu-text-muted);
905
+ font: inherit;
906
+ text-decoration: none;
907
+ cursor: pointer;
908
+ }
909
+ .fcu-icon-action:hover,
910
+ .fcu-icon-action:focus-visible {
911
+ color: var(--fcu-primary);
912
+ }
913
+
889
914
  /* Picker result rows. The hover tint was an inline handler; as CSS it also
890
915
  applies on keyboard focus. The `.active` roving highlight (above) wins. */
891
916
  .fcu-dropdown-item:hover,
@@ -0,0 +1,46 @@
1
+ {# One @edit_action / @list_action control.
2
+
3
+ A GET action is a link; a POST action is a small form carrying the CSRF
4
+ token, so it can change state safely and ask for confirmation first
5
+ (up-confirm, only allowed on POST actions). Both look the same.
6
+
7
+ variant: "button" (labelled .fcu-btn), "icon" (bare header icon) or
8
+ "row" (list row icon).
9
+ target: Unpoly target. A GET link is only followed by Unpoly when one is
10
+ given; a POST form falls back to #main-content.
11
+ history: carry up-history="true" (RCRUD tab content).
12
+ next: optional return URL, posted as "next" for the handler. #}
13
+ {% macro action_control(construct, action, href, variant="button", target=none, history=false, next=none) %}
14
+ {%- set label = construct.t(action.name) -%}
15
+ {%- set cls = {"button": "fcu-btn", "icon": "fcu-icon-action", "row": "fcu-row-action"}[variant] -%}
16
+ {%- if action.method == "post" -%}
17
+ {# nosemgrep: django-no-csrf-token — Flask app; CSRF is handled by {{ csrf_field() }} below, not Django's {% csrf_token %}. #}
18
+ <form method="post" action="{{ href }}" class="fcu-action-form"
19
+ up-target="{{ target or '#main-content' }}"
20
+ {%- if history %} up-history="true"{% endif %}
21
+ {%- if action.confirm %} up-confirm="{{ construct.t(action.confirm) }}"{% endif %}>
22
+ {{ csrf_field() }}
23
+ {%- if next %}
24
+ <input type="hidden" name="next" value="{{ next }}">
25
+ {%- endif %}
26
+ <button type="submit" class="{{ cls }}"{% if variant != "button" %} title="{{ label }}"{% endif %}>
27
+ {{- _action_content(action, label, variant) -}}
28
+ </button>
29
+ </form>
30
+ {%- else -%}
31
+ <a href="{{ href }}" class="{{ cls }}"
32
+ {%- if variant != "button" %} title="{{ label }}"{% endif %}
33
+ {%- if target %} up-follow up-target="{{ target }}"{% endif %}
34
+ {%- if history %} up-history="true"{% endif %}>
35
+ {{- _action_content(action, label, variant) -}}
36
+ </a>
37
+ {%- endif -%}
38
+ {% endmacro %}
39
+
40
+ {% macro _action_content(action, label, variant) -%}
41
+ {%- if variant == "button" -%}
42
+ {{ icon(action.icon, size="sm") }} {{ label }}
43
+ {%- else -%}
44
+ {{ icon(action.icon, label=label) }}
45
+ {%- endif -%}
46
+ {%- endmacro %}
@@ -1,5 +1,6 @@
1
1
  {% extends "structure/base.html" %}
2
2
  {% from 'crud/_macros.html' import render_field, render_form_errors, render_layout %}
3
+ {% from 'crud/_actions.html' import action_control %}
3
4
  {% block title %}{{ construct.compose_title(construct.t("crud-edit-rec", {'recname': construct.t(view.name, {'count': 1})})) }}{% endblock %}
4
5
  {# This view renders its own visible <h1>, so suppress the layout default. #}
5
6
  {% block page_heading %}{% endblock %}
@@ -38,12 +39,7 @@
38
39
  {% if edit_actions %}
39
40
  <div style="display: flex; gap: 8px; margin-bottom: 16px;">
40
41
  {% for action in edit_actions %}
41
- <a href="{{ url_for(view.endpoint + '.' + action.endpoint, id=data[primary_key]) }}"
42
- class="fcu-btn"
43
- up-follow
44
- up-target="#main-content">
45
- {{ icon(action.icon, size="sm") }} {{ construct.t(action.name) }}
46
- </a>
42
+ {{ action_control(construct, action, url_for(view.endpoint + '.' + action.endpoint, id=data[primary_key]), "button", target="#main-content") }}
47
43
  {% endfor %}
48
44
  </div>
49
45
  {% endif %}
@@ -81,13 +77,7 @@
81
77
  {% if edit_actions %}
82
78
  <div style="display: flex; gap: 8px;">
83
79
  {% for action in edit_actions %}
84
- <a href="{{ url_for(view.endpoint + '.' + action.endpoint, id=data[primary_key]) }}"
85
- style="color: var(--fcu-text-muted); text-decoration: none; display: inline-flex; align-items: center; padding: 4px;"
86
- title="{{ construct.t(action.name) }}"
87
- up-follow
88
- up-target="#main-content">
89
- {{ icon(action.icon, label=construct.t(action.name)) }}
90
- </a>
80
+ {{ action_control(construct, action, url_for(view.endpoint + '.' + action.endpoint, id=data[primary_key]), "icon", target="#main-content") }}
91
81
  {% endfor %}
92
82
  </div>
93
83
  {% endif %}
@@ -1,5 +1,6 @@
1
1
  {% extends "structure/base.html" %}
2
2
  {% from 'crud/_macros.html' import shown %}
3
+ {% from 'crud/_actions.html' import action_control %}
3
4
  {% block title %}{{ construct.compose_title(construct.t(view.name)) }}{% endblock %}
4
5
  {# This view renders its own visible <h1>, so suppress the layout default. #}
5
6
  {% block page_heading %}{% endblock %}
@@ -179,11 +180,7 @@
179
180
  {% endif %}
180
181
  {% if list_actions %}
181
182
  {% for action in list_actions %}
182
- <a href="{{ url_for(view.endpoint + '.' + action.endpoint, id=row[primary_key]) }}"
183
- class="fcu-row-action"
184
- title="{{ construct.t(action.name) }}">
185
- {{ icon(action.icon, label=construct.t(action.name)) }}
186
- </a>
183
+ {{ action_control(construct, action, url_for(view.endpoint + '.' + action.endpoint, id=row[primary_key]), "row", next=return_here) }}
187
184
  {% endfor %}
188
185
  {% endif %}
189
186
  {# nosemgrep: django-no-csrf-token — Flask app; CSRF is handled by {{ csrf_field() }} below, not Django's {% csrf_token %}. #}
@@ -1,5 +1,6 @@
1
1
  {% extends "crud/tab_view.html" %}
2
2
  {% from 'crud/_macros.html' import render_field, render_form_errors, render_layout, render_newrel_panel, field_help, error_attrs %}
3
+ {% from 'crud/_actions.html' import action_control %}
3
4
 
4
5
  {#
5
6
  render_child_field: renders a child form field without needing the parent
@@ -91,14 +92,7 @@
91
92
  {% if edit_actions %}
92
93
  <div style="display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px;">
93
94
  {% for action in edit_actions %}
94
- <a href="{{ action.href }}"
95
- class="fcu-btn"
96
- up-follow
97
- up-target="{{ content_target }}"
98
- up-history="true">
99
- {{ icon(action.icon, size="sm") }}
100
- {{ construct.t(action.name) }}
101
- </a>
95
+ {{ action_control(construct, action, action.href, "button", target=content_target, history=true) }}
102
96
  {% endfor %}
103
97
  </div>
104
98
  {% endif %}
@@ -1,5 +1,6 @@
1
1
  {% extends "crud/tab_view.html" %}
2
2
  {% from 'crud/_macros.html' import shown %}
3
+ {% from 'crud/_actions.html' import action_control %}
3
4
  {% block tab_content %}
4
5
  {%- set is_advanced_filter = request.args.get('advanced_filter') if filter_enabled else none -%}
5
6
  {%- set tab_list_url = url_for(view.endpoint + '.' + list_ep, id=parent_id) -%}
@@ -191,14 +192,7 @@
191
192
  </a>
192
193
  {% endif %}
193
194
  {% for action in list_actions %}
194
- <a href="{{ url_for(view.endpoint + '.' + action.endpoint, id=parent_id, child_id=row[primary_key]) }}"
195
- class="fcu-row-action"
196
- title="{{ construct.t(action.name) }}"
197
- up-follow
198
- up-target="{{ content_target }}"
199
- up-history="true">
200
- {{ icon(action.icon, label=construct.t(action.name)) }}
201
- </a>
195
+ {{ action_control(construct, action, url_for(view.endpoint + '.' + action.endpoint, id=parent_id, child_id=row[primary_key]), "row", target=content_target, history=true) }}
202
196
  {% endfor %}
203
197
  {% if rct.permits('delete', construct, row) %}
204
198
  {# nosemgrep: django-no-csrf-token — Flask app; CSRF is handled by {{ csrf_field() }} below, not Django's {% csrf_token %}. #}
@@ -1,5 +1,6 @@
1
1
  {% extends "structure/base.html" %}
2
2
  {% from 'crud/_macros.html' import render_field, render_layout %}
3
+ {% from 'crud/_actions.html' import action_control %}
3
4
  {% block title %}{{ construct.compose_title(construct.t("crud-view-rec", {'recname': construct.t(view.name, {'count': 1})})) }}{% endblock %}
4
5
  {# This view renders its own visible <h1>, so suppress the layout default. #}
5
6
  {% block page_heading %}{% endblock %}
@@ -22,13 +23,7 @@
22
23
  {% if edit_actions %}
23
24
  <div style="display: flex; gap: 8px;">
24
25
  {% for action in edit_actions %}
25
- <a href="{{ url_for(view.endpoint + '.' + action.endpoint, id=data[primary_key]) }}"
26
- style="color: var(--fcu-text-muted); text-decoration: none; display: inline-flex; align-items: center; padding: 4px;"
27
- title="{{ construct.t(action.name) }}"
28
- up-follow
29
- up-target="#main-content">
30
- {{ icon(action.icon, label=construct.t(action.name)) }}
31
- </a>
26
+ {{ action_control(construct, action, url_for(view.endpoint + '.' + action.endpoint, id=data[primary_key]), "icon", target="#main-content") }}
32
27
  {% endfor %}
33
28
  </div>
34
29
  {% endif %}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flask-construct-ui
3
- Version: 0.12.4
3
+ Version: 0.13.0
4
4
  Summary: A UI toolkit for Flask with CRUD and component features.
5
5
  Author-email: Olof Tjerngren <olof@tjerngren.net>
6
6
  License-Expression: LGPL-3.0-or-later
@@ -98,6 +98,7 @@ flask_construct_ui/templates/components/table.html
98
98
  flask_construct_ui/templates/components/tabs.html
99
99
  flask_construct_ui/templates/components/text.html
100
100
  flask_construct_ui/templates/components/vertical_layout.html
101
+ flask_construct_ui/templates/crud/_actions.html
101
102
  flask_construct_ui/templates/crud/_macros.html
102
103
  flask_construct_ui/templates/crud/_many_related_options.html
103
104
  flask_construct_ui/templates/crud/_related_options.html
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "flask-construct-ui"
7
- version = "0.12.4"
7
+ version = "0.13.0"
8
8
  description = "A UI toolkit for Flask with CRUD and component features."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"