Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rolled django.core.extensions.DjangoRequest into django.utils.httpwra…

…ppers.ModPythonRequest, in preparation for WSGI support

git-svn-id: http://code.djangoproject.com/svn/django/trunk@167 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit feeeda969c68757a26e769e7c6bbd2c7e5d58f8b 1 parent 246c1f8
Adrian Holovaty adrianholovaty authored
41 django/core/extensions.py
View
@@ -38,44 +38,3 @@ def __init__(self, user):
self.user = user
def __getitem__(self, module_name):
return PermLookupDict(self.user, module_name)
-
-class DjangoRequest(ModPythonRequest):
- "A special version of ModPythonRequest with support for Django sessions."
- def __init__(self, req):
- ModPythonRequest.__init__(self, req)
-
- def __repr__(self):
- return '<DjangoRequest\npath:%s,\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s,\nuser:%s>' % \
- (self.path, pformat(self.GET), pformat(self.POST), pformat(self.COOKIES),
- pformat(self.META), pformat(self.user))
-
- def _load_session_and_user(self):
- from django.models.auth import sessions
- from django.conf.settings import AUTH_SESSION_COOKIE
- session_cookie = self.COOKIES.get(AUTH_SESSION_COOKIE, '')
- try:
- self._session = sessions.get_session_from_cookie(session_cookie)
- self._user = self._session.get_user()
- except sessions.SessionDoesNotExist:
- from django.parts.auth import anonymoususers
- self._session = None
- self._user = anonymoususers.AnonymousUser()
-
- def _get_session(self):
- if not hasattr(self, '_session'):
- self._load_session_and_user()
- return self._session
-
- def _set_session(self, session):
- self._session = session
-
- def _get_user(self):
- if not hasattr(self, '_user'):
- self._load_session_and_user()
- return self._user
-
- def _set_user(self, user):
- self._user = user
-
- session = property(_get_session, _set_session)
- user = property(_get_user, _set_user)
4 django/core/handler.py
View
@@ -18,14 +18,14 @@ def __call__(self, req):
# that use settings now can work
from django.conf import settings
from django.core import db
- from django.core.extensions import DjangoRequest
+ from django.utils.httpwrappers import ModPythonRequest
# if we need to set up middleware, now that settings works we can do it now.
if self._request_middleware is None:
self.load_middleware()
try:
- request = DjangoRequest(req)
+ request = ModPythonRequest(req)
response = self.get_response(req.uri, request)
finally:
db.db.close()
36 django/utils/httpwrappers.py
View
@@ -30,9 +30,9 @@ def __init__(self, req):
self.path = req.uri
def __repr__(self):
- return '<ModPythonRequest\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s>' % \
- (pformat(self.GET), pformat(self.POST), pformat(self.COOKIES),
- pformat(self.META))
+ return '<ModPythonRequest\npath:%s,\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s,\nuser:%s>' % \
+ (self.path, pformat(self.GET), pformat(self.POST), pformat(self.COOKIES),
+ pformat(self.META), pformat(self.user))
def get_full_path(self):
return '%s%s' % (self.path, self._req.args and ('?' + self._req.args) or '')
@@ -105,12 +105,42 @@ def _get_meta(self):
self._meta[key] = value
return self._meta
+ def _load_session_and_user(self):
+ from django.models.auth import sessions
+ from django.conf.settings import AUTH_SESSION_COOKIE
+ session_cookie = self.COOKIES.get(AUTH_SESSION_COOKIE, '')
+ try:
+ self._session = sessions.get_session_from_cookie(session_cookie)
+ self._user = self._session.get_user()
+ except sessions.SessionDoesNotExist:
+ from django.parts.auth import anonymoususers
+ self._session = None
+ self._user = anonymoususers.AnonymousUser()
+
+ def _get_session(self):
+ if not hasattr(self, '_session'):
+ self._load_session_and_user()
+ return self._session
+
+ def _set_session(self, session):
+ self._session = session
+
+ def _get_user(self):
+ if not hasattr(self, '_user'):
+ self._load_session_and_user()
+ return self._user
+
+ def _set_user(self, user):
+ self._user = user
+
GET = property(_get_get, _set_get)
POST = property(_get_post, _set_post)
COOKIES = property(_get_cookies, _set_cookies)
FILES = property(_get_files)
META = property(_get_meta)
REQUEST = property(_get_request)
+ session = property(_get_session, _set_session)
+ user = property(_get_user, _set_user)
def parse_file_upload(header_dict, post_data):
"Returns a tuple of (POST MultiValueDict, FILES MultiValueDict)"
Please sign in to comment.
Something went wrong with that request. Please try again.