Cookieless Session Decorator

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# -*- coding: utf-8 -*-

from functools import wraps
from django.conf import settings
from django.utils.importlib import import_module

def session_from_http_params(view_func):
    @wraps(view_func)
    def decorated(request, *args, **kwargs):
        engine = import_module(settings.SESSION_ENGINE)
        session_key = request.GET.get(settings.SESSION_COOKIE_NAME, None)
        if session_key is None:
            session_key = request.POST.get(settings.SESSION_COOKIE_NAME, None)
        request.session = engine.SessionStore(session_key)
        return view_func(request, *args, **kwargs)
    return decorated

More like this

  1. Remember path decorator by robhudson 4 years, 4 months ago
  2. Simple Age Verification Middleware by eculver 4 years, 8 months ago
  3. Allow separation of GET and POST implementations by agore 1 year, 10 months ago
  4. A action decorator for URLs by Batiste 6 years ago
  5. PK->objects in view signature by AdamKG 6 years ago

Comments

(Forgotten your password?)