djangofloor.wsgi.window_info
¶
WindowInfo object and associated functions¶
A WindowInfo
object carries important data the browser window that is connected to the websocket:
- the window key that is unique to each open browser window,
- user information about the connected user,
- i18n information.
The WindowInfo
object is populated by middlewares, thath should be any subclass of
djangofloor.middleware.WindowInfoMiddleware
.
The list of used middlewares is defined by the WINDOW_INFO_MIDDLEWARES setting.
Warning
Never modify a WindowInfo
: the same object can be reused for all websocket signals from a given connection.
Designed to be instanciated from a django.http.request.HttpRequest
and reused across signals
(when a signal calls another one). However, a blank WindowInfo
can also be directly instanciated.
-
class
djangofloor.wsgi.window_info.
WindowInfo
(init=True)[source]¶ Built to store the username and the window key and must be supplied to any Python signal call. All attributes are set by “WindowInfoMiddleware“‘s.
Can be constructed from a standard
django.http.HttpRequest
or from a dict. Like the request, you should check the installed middlewares to obtain the full list of attributes. The default ones are provided bydjangofloor.middleware
.-
classmethod
from_dict
(values)[source]¶ Generate a new
WindowInfo
from a dict.
-
classmethod
from_request
(request)[source]¶ return a
djangofloor.wsgi.window_info.WindowInfo
from adjango.http.HttpRequest
.If the request already is a
djangofloor.wsgi.window_info.WindowInfo
, then it is returned as-is (not copied!).Parameters: request ( django.http.HttpRequest
ordjangofloor.wsgi.window_info.WindowInfo
) – standard Django requestReturns: a valid request Return type: djangofloor.wsgi.window_info.WindowInfo
-
has_perm
(req, perm)¶ return true is the user has the required perm.
>>> from djangofloor.wsgi.window_info import WindowInfo >>> r = WindowInfo.from_dict({'username': 'username', 'perms':['app_label.codename']}) >>> r.has_perm('app_label.codename') True
Parameters: - req – WindowInfo
- perm – name of the permission (“app_label.codename”)
Returns: True if the user has the required perm
Return type:
-
to_dict
()[source]¶ Convert this
djangofloor.wsgi.window_info.WindowInfo
to adict
which can be provided to JSON.Returns: a dict ready to be serialized in JSON Return type: dict
-
user
¶ return the user object if authenticated, else return None
-
classmethod