--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/858abfe1-42b9-185b-e69c-c23d6058e762%40andreymal.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM3vn6SP2q951_1keJnaQhAbTEY3rfK_X-FvSSLOtQoTCw%40mail.gmail.com.
The page you referred to says:
>First request the feature on the django-developers list, not in the ticket tracker.
That's why I'm here ¯\_(ツ)_/¯
About my case — in general, I want to make a
websocket server. Django Channels is too complicated and I
don't want to use it for my case; instead, I want to make a
very stupid and primitive server (without consumers, routers,
channel layers and other scary words; less than 0.5k
lines of code). But I still need to authenticate the user, and
I want to do exactly what Channels does — get the user
model instance for current websocket scope.
Now, to prevent code duplication, I have to do something like this:
def get_session(self):
SessionStore =
importlib.import_module(settings.SESSION_ENGINE).SessionStore
# self.session_key is loaded from websocket
cookies
return SessionStore(self.session_key)
def get_user_model(self):
from django.contrib.auth import get_user
from django.http.request import HttpRequest
request = HttpRequest()
request.session = self.get_session()
return get_user(request)
But this is obviously ugly. But creating a copy of the "get_user" function and modifying it to fit my needs is even worse.
The "get_user_by_session_key" function I propose can dramatically simplify this code and increase reliability. The same applies to Channels that can get rid of its own copy of the "get_user" function.
I expect you'll say "just
use Channels and don't be an idiot", but I think this
small refactoring will be good anyway, even for Channels.
I don't
quite understand what you mean by saying "isn't the only thing that would need
changing"; as of
today, I have not noticed any problems when working
with the session without a real request. (I know that
it’s not very safe to work with the ORM in async code,
but don't worry, I took care of this.)
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM3vn6SP2q951_1keJnaQhAbTEY3rfK_X-FvSSLOtQoTCw%40mail.gmail.com.
>First request the feature on the django-developers list, not in the ticket tracker
I expect you'll say "just use Channels and don't be an idiot",
But this is obviously ugly
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/d72e1e22-4e65-2c25-391e-a942b73cb498%40andreymal.org.