Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement flash messages #770

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jonocodes
Copy link
Contributor

@jonocodes jonocodes commented May 15, 2024

This creates the 'flash' function which can be called from any view. Then the next page load will display the message.

It also added messages to the 'create', 'edit', 'delete' functions.

Screenshot from 2024-05-15 13-02-22

@jonocodes jonocodes mentioned this pull request May 15, 2024
1 task
Copy link
Contributor

@hasansezertasan hasansezertasan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a quite good implementation. Great job 👍.

It's similar to litestar's flash plugin and starlette-flash package implementation.

Using sessions to keep the flash messages in the flash bag on redirects is a great idea but the user could use a custom SessionMiddleware that depends on a key-value database like Redis might cause conflicts. I believe instead of using sessions to store flash messages we can directly use cookies with a customizable cookie name default to admin_flash_messages to store everything.

Or we can come up with a middleware that is specifically for flashes, something like FlashMiddleware 🤓

Also I do think we should update edit.html and create.html to use flash bag instead of using plain error variable.

Comment on lines +30 to +34
class AlertTypeEnum(enum.Enum):
success = "success"
info = "info"
warning = "warning"
danger = "danger"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why limit the message type? I think this could be just a string.

Copy link
Contributor Author

@jonocodes jonocodes May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These map to tabler alert types https://tabler.io/docs/components/alerts
which is how they get styled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point but I believe that this shouldn't be limited by an enumeration.

Even though flash messages have some basic categories, they could have custom categories.

WDYT @aminalaee?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see...

@jonocodes
Copy link
Contributor Author

Using sessions to keep the flash messages in the flash bag on redirects is a great idea but the user could use a custom SessionMiddleware that depends on a key-value database like Redis might cause conflicts. I believe instead of using sessions to store flash messages we can directly use cookies with a customizable cookie name default to admin_flash_messages to store everything.

Yeah we can do this in cookies, it you guys think its better.

Also I do think we should update edit.html and create.html to use flash bag instead of using plain error variable.

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants