Compare commits

...

1 Commits

Author SHA1 Message Date
Daniel Perelman b30982bd7e Fixes to support Django Channels 4. 2023-07-29 15:31:26 -07:00
3 changed files with 12 additions and 8 deletions

View File

@ -1,7 +1,12 @@
from channels.http import AsgiHandler
from channels.routing import ProtocolTypeRouter, URLRouter
import django
from django.conf.urls import url
from django.core.asgi import get_asgi_application
# TODO Importing views breaks if django.setup() isn't called first...
# ... but this isn't the way this is supposed to work.
django.setup()
from . import views
@ -9,8 +14,8 @@ application = ProtocolTypeRouter({
"http": URLRouter([
url(r'^(?P<access_code>[a-zA-Z]{6})/', URLRouter([
url(r"status/(?P<hashcode>[a-z0-9]{64})/",
views.StatusLongPollConsumer, name='status'),
views.StatusLongPollConsumer.as_asgi(), name='status'),
])),
url(r"", AsgiHandler),
url(r"", get_asgi_application()),
]),
})

View File

@ -377,7 +377,7 @@ class StatusLongPollConsumer(AsyncHttpConsumer):
async def fear_tracker_hashcode_seen(self, event):
if self.hashcode != event["hashcode"]:
if event["status_string"]:
if "status_string" in event and event["status_string"]:
body = event["status_string"].encode('utf-8')
await self.send_response(200, body)
await self.disconnect()

View File

@ -3,10 +3,9 @@ ASGI entrypoint. Configures Django and then runs the application
defined in the ASGI_APPLICATION setting.
"""
import os
import django
from channels.routing import get_default_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fear_tracker_site.settings")
import fear_tracker.routing
django.setup()
application = get_default_application()
application = fear_tracker.routing.application