-
Notifications
You must be signed in to change notification settings - Fork 170
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
class AlertTypeEnum(enum.Enum): | ||
success = "success" | ||
info = "info" | ||
warning = "warning" | ||
danger = "danger" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like django uses an enum https://docs.djangoproject.com/en/5.0/ref/contrib/messages/#adding-a-message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see...
Yeah we can do this in cookies, it you guys think its better.
Yes. |
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.