root: base Websocket message storage on Base not fallback
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
f67b57e369
commit
4a444e667a
|
@ -1,13 +1,12 @@
|
||||||
"""Channels Messages storage"""
|
"""Channels Messages storage"""
|
||||||
from asgiref.sync import async_to_sync
|
from asgiref.sync import async_to_sync
|
||||||
from channels.layers import get_channel_layer
|
from channels.layers import get_channel_layer
|
||||||
from django.contrib.messages.storage.base import Message
|
from django.contrib.messages.storage.base import BaseStorage, Message
|
||||||
from django.contrib.messages.storage.fallback import FallbackStorage
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.http.request import HttpRequest
|
from django.http.request import HttpRequest
|
||||||
|
|
||||||
|
|
||||||
class ChannelsStorage(FallbackStorage):
|
class ChannelsStorage(BaseStorage):
|
||||||
"""Send contrib.messages over websocket"""
|
"""Send contrib.messages over websocket"""
|
||||||
|
|
||||||
def __init__(self, request: HttpRequest) -> None:
|
def __init__(self, request: HttpRequest) -> None:
|
||||||
|
@ -15,6 +14,9 @@ class ChannelsStorage(FallbackStorage):
|
||||||
super().__init__(request)
|
super().__init__(request)
|
||||||
self.channel = get_channel_layer()
|
self.channel = get_channel_layer()
|
||||||
|
|
||||||
|
def _get(self):
|
||||||
|
return [], True
|
||||||
|
|
||||||
def _store(self, messages: list[Message], response, *args, **kwargs):
|
def _store(self, messages: list[Message], response, *args, **kwargs):
|
||||||
prefix = f"user_{self.request.session.session_key}_messages_"
|
prefix = f"user_{self.request.session.session_key}_messages_"
|
||||||
keys = cache.keys(f"{prefix}*")
|
keys = cache.keys(f"{prefix}*")
|
||||||
|
|
Reference in New Issue