-
-
Notifications
You must be signed in to change notification settings - Fork 695
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
"flash messages" mechanism #790
Comments
I can use the new signed values support from #785 to help build this. |
Actually I'm inclined to use cookies now, ala Django: https://docs.djangoproject.com/en/3.0/ref/contrib/messages/
|
Setting messages just needs access to the response. Reading messages needs access to both request AND response, since it needs to clear the messages that are being displayed. That's if the messages are persisted exclusively in cookies - which makes sense for Django since it's designed to run as many different load-balanced processes. Since Datasette is a single process which can access an on-file database, maybe consider storing the flash messages within Datasette memory itself - a sort of session mechanism? |
I'm going to build the first version of this with signed cookies. I'm inclined to do this all on the request object, since it's the object representing the current request as it flows through the application. I need the ability to remember which messages were set and which need to be cleared, so I need to do that on something that is available for the lifetime of the request. |
Maybe two utility functions:
Problem: the |
Alternative: Maybe use a request correlation ID that gets added to the scope? This is all getting a bit messy. |
Here's how the Django stuff works: https://github.com/django/django/blob/master/django/contrib/messages/storage/base.py Notably the messages are mostly dealt with on the request object, with a piece of middleware that reads from the request and modifies the response (to set or clear cookies) right at the end: https://github.com/django/django/blob/master/django/contrib/messages/middleware.py |
What if I use a mutable key on ASGI spec says this: https://asgi.readthedocs.io/en/latest/specs/main.html#middleware
|
If The problem then is how do I know to clean up the memory used by that dictionary when the request flows out of the system? I guess the code that updates the cookies in the response could do that. |
Flask and Django both support "types" of message - info, warning etc. I think I should do the same. |
It would be neat if this was driven by a method on |
Then later:
|
Problem with Solution: call it |
I'm going to stash these on the |
I'm going to use a output renderer plugin to test this, since then my unit tests can run against custom code that both sets and displays messages. |
I need to make sure that any time cookies are set there's no cache-control header (or it is set to private). |
The |
From #698 (comment)
|
Debug tool is live here: https://latest.datasette.io/-/messages Documentation is here: https://github.com/simonw/datasette/blob/master/docs/internals.rst#add_messagerequest-message-message_typedatasetteinfo |
Message CSS is now demonstrated on https://latest.datasette.io/-/patterns |
Originally posted by @simonw in #703
The text was updated successfully, but these errors were encountered: