This is an automated email from the ASF dual-hosted git repository. gstein pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/steve.git
commit aa3c091836963892f6837062a97c8d75941e064b Author: Greg Stein <[email protected]> AuthorDate: Sat Oct 11 23:05:11 2025 -0500 Add tools/display for using Quart "flash" notices. * pages.py: - signin_info(): fetch flashes from the Quart session, and inject EasyDict instances into the template data. - define flash_FOO() for each Bootstrap alert type * flashes.ezt: new template fragment to display an alert box for each flash that is within the session, using the right category. * templates/VARIOUS.ezt: include the new flashes.ezt --- v3/server/pages.py | 35 +++++++++++++++++++++++++++++++---- v3/server/templates/about.ezt | 2 ++ v3/server/templates/admin.ezt | 2 +- v3/server/templates/flashes.ezt | 6 ++++++ v3/server/templates/home.ezt | 4 ++++ v3/server/templates/manage.ezt | 2 ++ v3/server/templates/privacy.ezt | 2 ++ v3/server/templates/profile.ezt | 2 ++ v3/server/templates/settings.ezt | 2 ++ v3/server/templates/vote-on.ezt | 2 ++ v3/server/templates/voter.ezt | 1 + 11 files changed, 55 insertions(+), 5 deletions(-) diff --git a/v3/server/pages.py b/v3/server/pages.py index 80b54dd..465895d 100644 --- a/v3/server/pages.py +++ b/v3/server/pages.py @@ -58,12 +58,39 @@ T_BAD_EID = APP.load_template(TEMPLATES / 'e_bad_eid.ezt') async def signin_info(): "Return EZT template data for the Sign-In, in the upper right." + + ### debug/test + await flash_primary('hello there') + await flash_danger('and another') + + basic = edict() + + # Flashes are stored in the Session. Fetch and turn each flash into + # EasyDict objects for use by templates. + # NOTE: .flash() is called with (message, category), but the + # .get_flashed_messages() returns tuples of (category, message) + basic.flashes = [ edict(message=f[1], category=f[0]) + for f in quart.get_flashed_messages(with_categories=True) ] + s = await asfquart.session.read() if s: - return edict(uid=s['uid'], name=s['fullname'], email=s['email'],) - - # No session. - return edict(uid=None, name=None, email=None,) + basic.update(uid=s['uid'], name=s['fullname'], email=s['email'],) + else: + # No session. + basic.update(uid=None, name=None, email=None,) + + return basic + + +# Define a bunch of helpers for recording "flash" messages in the session. +# Each helper function is: +# async def flash_FOO(message) +# where FOO is one of the eight Bootstrap alert classes. See: +# https://getbootstrap.com/docs/5.0/components/alerts/#examples +for _cat in ('primary', 'secondary', 'success', 'danger', + 'warning', 'info', 'light', 'dark', ): + globals()[f'flash_{_cat}'] = functools.partial(quart.flash, category=_cat) +del _cat @APP.get('/') diff --git a/v3/server/templates/about.ezt b/v3/server/templates/about.ezt index 4d95432..453a191 100644 --- a/v3/server/templates/about.ezt +++ b/v3/server/templates/about.ezt @@ -1,6 +1,8 @@ [include "header.ezt"] <div class="container"> <h1>[title]</h1> + [include "flashes.ezt"] + <p> TBD </p> diff --git a/v3/server/templates/admin.ezt b/v3/server/templates/admin.ezt index cfd4dca..a9753c8 100644 --- a/v3/server/templates/admin.ezt +++ b/v3/server/templates/admin.ezt @@ -1,7 +1,7 @@ [include "header.ezt"] <div class="container"> <h1>[title]</h1> - + [include "flashes.ezt"] [for owned] <div class="w-auto mb-4"> diff --git a/v3/server/templates/flashes.ezt b/v3/server/templates/flashes.ezt new file mode 100644 index 0000000..821a23d --- /dev/null +++ b/v3/server/templates/flashes.ezt @@ -0,0 +1,6 @@ +[for flashes] + <div class="alert alert-[flashes.category] alert-dismissible fade show" role="alert"> + [flashes.message] + <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> + </div> +[end] diff --git a/v3/server/templates/home.ezt b/v3/server/templates/home.ezt index d86d195..b2c4e2e 100644 --- a/v3/server/templates/home.ezt +++ b/v3/server/templates/home.ezt @@ -1,5 +1,9 @@ [include "header.ezt"] <div class="container"> + <div class="mt-2"> + [include "flashes.ezt"] + </div> + <p class="my-3"> Welcome! What are you here for? Select an option below. </p> diff --git a/v3/server/templates/manage.ezt b/v3/server/templates/manage.ezt index 2bcba42..956c437 100644 --- a/v3/server/templates/manage.ezt +++ b/v3/server/templates/manage.ezt @@ -1,6 +1,8 @@ [include "header.ezt"] <div class="container"> <h1>[title]</h1> + [include "flashes.ezt"] + <div class="sticky-top"> <h2>[e_title]</h2> </div> diff --git a/v3/server/templates/privacy.ezt b/v3/server/templates/privacy.ezt index 4d95432..453a191 100644 --- a/v3/server/templates/privacy.ezt +++ b/v3/server/templates/privacy.ezt @@ -1,6 +1,8 @@ [include "header.ezt"] <div class="container"> <h1>[title]</h1> + [include "flashes.ezt"] + <p> TBD </p> diff --git a/v3/server/templates/profile.ezt b/v3/server/templates/profile.ezt index 4d95432..453a191 100644 --- a/v3/server/templates/profile.ezt +++ b/v3/server/templates/profile.ezt @@ -1,6 +1,8 @@ [include "header.ezt"] <div class="container"> <h1>[title]</h1> + [include "flashes.ezt"] + <p> TBD </p> diff --git a/v3/server/templates/settings.ezt b/v3/server/templates/settings.ezt index 4d95432..453a191 100644 --- a/v3/server/templates/settings.ezt +++ b/v3/server/templates/settings.ezt @@ -1,6 +1,8 @@ [include "header.ezt"] <div class="container"> <h1>[title]</h1> + [include "flashes.ezt"] + <p> TBD </p> diff --git a/v3/server/templates/vote-on.ezt b/v3/server/templates/vote-on.ezt index 4a6dcc3..73cff96 100644 --- a/v3/server/templates/vote-on.ezt +++ b/v3/server/templates/vote-on.ezt @@ -1,6 +1,8 @@ [include "header.ezt"] <div class="container"> <h1>[title]</h1> + [include "flashes.ezt"] + <p> You have [issue_count] issues to vote upon, in this election. </p> diff --git a/v3/server/templates/voter.ezt b/v3/server/templates/voter.ezt index b6e57a5..8def7c2 100644 --- a/v3/server/templates/voter.ezt +++ b/v3/server/templates/voter.ezt @@ -1,6 +1,7 @@ [include "header.ezt"] <div class="container"> <h1>[title]</h1> + [include "flashes.ezt"] [for election] <div class="w-auto mb-4">
