app/django/contrib/auth/middleware.py
author Lennard de Rijk <ljvderijk@gmail.com>
Mon, 13 Jul 2009 00:59:11 +0200
changeset 2617 274efd5c769d
parent 54 03e267d67478
permissions -rw-r--r--
Added methods to GradingRecord Logic to facilitate creating/updating them. UpdateOrCreateRecordsFor will batch put GradingRecords for a given SurveyGroup and StudentProject. getFieldsForGradingRecord will return the fields that need to be set for a single GradingRecord entity given a StudentProject, GradingSurveyGroup and if it is an update a GradingRecord entity.

class LazyUser(object):
    def __get__(self, request, obj_type=None):
        if not hasattr(request, '_cached_user'):
            from django.contrib.auth import get_user
            request._cached_user = get_user(request)
        return request._cached_user

class AuthenticationMiddleware(object):
    def process_request(self, request):
        assert hasattr(request, 'session'), "The Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'."
        request.__class__.user = LazyUser()
        return None