Closed nerdoc closed 3 years ago
Yup, I'm aware of this. Since the reflex is as a matter of fact happening outside of the response / request cycle I'm not sure there is a good solution for this if you specifically want to use django's messages
. The message is fetched when the next response is loaded.
At the same time you should be able to modify the html any way you want to, so that it works as a notification. So perhaps all that is needed is an example of how that would look like?
Definitely. A working example is ok, the messaging framework is not even mandatory in Django. but could be removed with three lines. AFAIK, Sockpuppet is able to do Push notofications. The best example would be something like a long running task which is finished, and then the user gets a message. For the example this could be shown by hooking onto a Django event? iIs this possible?
@nerdoc simple solution communicates with redis/memcached ... create a messages cache like
on the reflex:
cache.set(f"msg_{user}", [message1])
on the view:
messages = cache.get(f"msg_{user}")
for message in messages:
message.info(self.request, message)
take a look the chat example:
Cool, thanks! That's fine for me I think.
Bug Report
Describe the bug
When adding a message using Djangos (per default enabled) message framework, e.g.
The Django message framework must be installed properly of course. The Reflex class produces an Error (visible on the server output):
To Reproduce
in a reflex, add that to a stimulus-called Reflex method and trigger the reflex from the frontend.:
Expected behavior
the message should be processed and displayed normally. However, the user must take care that the message part is within the rendered HTML part, to be shown instantly. I know this adds some overhead (which is unwanted). Maybe it could be made optional.
A completely (and maybe better) other approach would be a working example of a push notification using a Reflex using Sockpuppet.
Versions
Django-sockpuppet
External tools