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.Session(key=None)[source]
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 by djangofloor.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 a django.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 or djangofloor.wsgi.window_info.WindowInfo) – standard Django request
Returns: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:

bool

perms

set of all perms of the user (set of “app_label.codename”)

to_dict()[source]

Convert this djangofloor.wsgi.window_info.WindowInfo to a dict 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

djangofloor.wsgi.window_info.get_window_context(window_info)[source]

Generate a template context from the window_info, equivalent of a template context from a django.http.request.HttpRequest.

djangofloor.wsgi.window_info.render_to_string(template_name, context=None, window_info=None, using=None)[source]

Render a template to a string using a context from the window_info, equivalent of the django.template.loader.render_to_string().