OpenSlides/openslides/core/session_backend.py
Oskar Hahn fe64941aab Big Mode for OpenSlides
Uses django channels instead of tornado for the autoupdate. Therefore
tornado is nolonger a dependency of OpenSlides (but channels).

This uses websockets instead of SockJS.

Use the flag insecure in the start command to provide static files serving.

Use a new session backend that has a ForeignKey to User.
2016-06-09 11:14:39 +02:00

24 lines
699 B
Python

from django.contrib.sessions.backends.db import \
SessionStore as DjangoSessionStore
class SessionStore(DjangoSessionStore):
"""
Like the Django db Session store, but saves the user into the db field.
"""
@classmethod
def get_model_class(cls):
# Avoids a circular import
from .models import Session
return Session
def create_model_instance(self, data):
"""
Set the user from data to the db field. Set to None, if its a session
from an anonymous user.
"""
model = super().create_model_instance(data)
model.user_id = data['_auth_user_id'] if '_auth_user_id' in data else None
return model