Renamed CMSRequest to DjangoRequest, and CMSContext to DjangoContext. Old code will still work.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@57 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
960644ab08
commit
f4c581158d
|
@ -1,7 +1,7 @@
|
||||||
from django.core import formfields, template_loader, validators
|
from django.core import formfields, template_loader, validators
|
||||||
from django.core.mail import mail_admins, mail_managers
|
from django.core.mail import mail_admins, mail_managers
|
||||||
from django.core.exceptions import Http404, ObjectDoesNotExist
|
from django.core.exceptions import Http404, ObjectDoesNotExist
|
||||||
from django.core.extensions import CMSContext as Context
|
from django.core.extensions import DjangoContext as Context
|
||||||
from django.models.auth import sessions
|
from django.models.auth import sessions
|
||||||
from django.models.comments import comments, freecomments
|
from django.models.comments import comments, freecomments
|
||||||
from django.models.core import contenttypes
|
from django.models.core import contenttypes
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.core import template_loader
|
from django.core import template_loader
|
||||||
from django.core.extensions import CMSContext as Context
|
from django.core.extensions import DjangoContext as Context
|
||||||
from django.core.exceptions import Http404
|
from django.core.exceptions import Http404
|
||||||
from django.models.comments import comments, karma
|
from django.models.comments import comments, karma
|
||||||
from django.utils.httpwrappers import HttpResponse
|
from django.utils.httpwrappers import HttpResponse
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.core import template_loader
|
from django.core import template_loader
|
||||||
from django.core.extensions import CMSContext as Context
|
from django.core.extensions import DjangoContext as Context
|
||||||
from django.core.exceptions import Http404
|
from django.core.exceptions import Http404
|
||||||
from django.models.comments import comments, moderatordeletions, userflags
|
from django.models.comments import comments, moderatordeletions, userflags
|
||||||
from django.views.decorators.auth import login_required
|
from django.views.decorators.auth import login_required
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
"Specialized Context and ModPythonRequest classes for our CMS. Use these!"
|
"Specialized Context and ModPythonRequest classes for Django. Use these!"
|
||||||
|
|
||||||
from django.core.template import Context
|
from django.core.template import Context
|
||||||
from django.utils.httpwrappers import ModPythonRequest
|
from django.utils.httpwrappers import ModPythonRequest
|
||||||
from django.conf.settings import DEBUG, INTERNAL_IPS
|
from django.conf.settings import DEBUG, INTERNAL_IPS
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
|
|
||||||
class CMSContext(Context):
|
class DjangoContext(Context):
|
||||||
"""This subclass of template.Context automatically populates 'user' and
|
"""
|
||||||
'messages' in the context. Use this."""
|
This subclass of template.Context automatically populates 'user' and
|
||||||
|
'messages' in the context.
|
||||||
|
"""
|
||||||
def __init__(self, request, dict={}):
|
def __init__(self, request, dict={}):
|
||||||
Context.__init__(self, dict)
|
Context.__init__(self, dict)
|
||||||
self['user'] = request.user
|
self['user'] = request.user
|
||||||
|
@ -37,13 +39,13 @@ class PermWrapper:
|
||||||
def __getitem__(self, module_name):
|
def __getitem__(self, module_name):
|
||||||
return PermLookupDict(self.user, module_name)
|
return PermLookupDict(self.user, module_name)
|
||||||
|
|
||||||
class CMSRequest(ModPythonRequest):
|
class DjangoRequest(ModPythonRequest):
|
||||||
"A special version of ModPythonRequest with support for CMS sessions"
|
"A special version of ModPythonRequest with support for Django sessions."
|
||||||
def __init__(self, req):
|
def __init__(self, req):
|
||||||
ModPythonRequest.__init__(self, req)
|
ModPythonRequest.__init__(self, req)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<CMSRequest\npath:%s,\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s,\nuser:%s>' % \
|
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),
|
(self.path, pformat(self.GET), pformat(self.POST), pformat(self.COOKIES),
|
||||||
pformat(self.META), pformat(self.user))
|
pformat(self.META), pformat(self.user))
|
||||||
|
|
||||||
|
@ -77,3 +79,7 @@ class CMSRequest(ModPythonRequest):
|
||||||
|
|
||||||
session = property(_get_session, _set_session)
|
session = property(_get_session, _set_session)
|
||||||
user = property(_get_user, _set_user)
|
user = property(_get_user, _set_user)
|
||||||
|
|
||||||
|
# For legacy purposes.
|
||||||
|
CMSContext = DjangoContext
|
||||||
|
CMSRequest = DjangoRequest
|
||||||
|
|
|
@ -77,8 +77,8 @@ class CoreHandler:
|
||||||
|
|
||||||
def get_request(self, req):
|
def get_request(self, req):
|
||||||
"Returns an HttpRequest object for the given mod_python req object"
|
"Returns an HttpRequest object for the given mod_python req object"
|
||||||
from django.core.extensions import CMSRequest
|
from django.core.extensions import DjangoRequest
|
||||||
return CMSRequest(req)
|
return DjangoRequest(req)
|
||||||
|
|
||||||
def get_response(self, path, request):
|
def get_response(self, path, request):
|
||||||
"Returns an HttpResponse object for the given HttpRequest"
|
"Returns an HttpResponse object for the given HttpRequest"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.utils import httpwrappers
|
from django.utils import httpwrappers
|
||||||
from django.core import template_loader
|
from django.core import template_loader
|
||||||
from django.core.extensions import CMSContext as Context
|
from django.core.extensions import DjangoContext as Context
|
||||||
from django.models.auth import sessions, users
|
from django.models.auth import sessions, users
|
||||||
from django.views.registration import passwords
|
from django.views.registration import passwords
|
||||||
import base64, md5
|
import base64, md5
|
||||||
|
|
|
@ -6,7 +6,7 @@ from django import templatetags
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.models.core import sites
|
from django.models.core import sites
|
||||||
from django.views.decorators.cache import cache_page
|
from django.views.decorators.cache import cache_page
|
||||||
from django.core.extensions import CMSContext as Context
|
from django.core.extensions import DjangoContext as Context
|
||||||
from django.core.exceptions import Http404, ViewDoesNotExist
|
from django.core.exceptions import Http404, ViewDoesNotExist
|
||||||
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
|
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
|
||||||
from django.core import template, template_loader, defaulttags, defaultfilters, urlresolvers
|
from django.core import template, template_loader, defaulttags, defaultfilters, urlresolvers
|
||||||
|
@ -14,18 +14,18 @@ try:
|
||||||
from django.parts.admin import doc
|
from django.parts.admin import doc
|
||||||
except ImportError:
|
except ImportError:
|
||||||
doc = None
|
doc = None
|
||||||
|
|
||||||
# Exclude methods starting with these strings from documentation
|
# Exclude methods starting with these strings from documentation
|
||||||
MODEL_METHODS_EXCLUDE = ('_', 'add_', 'delete', 'save', 'set_')
|
MODEL_METHODS_EXCLUDE = ('_', 'add_', 'delete', 'save', 'set_')
|
||||||
|
|
||||||
def doc_index(request):
|
def doc_index(request):
|
||||||
if not doc:
|
if not doc:
|
||||||
return missing_docutils_page(request)
|
return missing_docutils_page(request)
|
||||||
|
|
||||||
t = template_loader.get_template('doc/index')
|
t = template_loader.get_template('doc/index')
|
||||||
c = Context(request, {})
|
c = Context(request, {})
|
||||||
return HttpResponse(t.render(c))
|
return HttpResponse(t.render(c))
|
||||||
|
|
||||||
def bookmarklets(request):
|
def bookmarklets(request):
|
||||||
t = template_loader.get_template('doc/bookmarklets')
|
t = template_loader.get_template('doc/bookmarklets')
|
||||||
c = Context(request, {
|
c = Context(request, {
|
||||||
|
@ -36,10 +36,10 @@ def bookmarklets(request):
|
||||||
def template_tag_index(request):
|
def template_tag_index(request):
|
||||||
if not doc:
|
if not doc:
|
||||||
return missing_docutils_page(request)
|
return missing_docutils_page(request)
|
||||||
|
|
||||||
# We have to jump through some hoops with registered_tags to make sure
|
# We have to jump through some hoops with registered_tags to make sure
|
||||||
# they don't get messed up by loading outside tagsets
|
# they don't get messed up by loading outside tagsets
|
||||||
saved_tagset = template.registered_tags.copy(), template.registered_filters.copy()
|
saved_tagset = template.registered_tags.copy(), template.registered_filters.copy()
|
||||||
load_all_installed_template_libraries()
|
load_all_installed_template_libraries()
|
||||||
|
|
||||||
# Gather docs
|
# Gather docs
|
||||||
|
@ -76,8 +76,8 @@ template_tag_index = cache_page(template_tag_index, 15*60)
|
||||||
def template_filter_index(request):
|
def template_filter_index(request):
|
||||||
if not doc:
|
if not doc:
|
||||||
return missing_docutils_page(request)
|
return missing_docutils_page(request)
|
||||||
|
|
||||||
saved_tagset = template.registered_tags.copy(), template.registered_filters.copy()
|
saved_tagset = template.registered_tags.copy(), template.registered_filters.copy()
|
||||||
load_all_installed_template_libraries()
|
load_all_installed_template_libraries()
|
||||||
|
|
||||||
filters = []
|
filters = []
|
||||||
|
@ -191,7 +191,7 @@ def model_detail(request, model):
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise Http404
|
raise Http404
|
||||||
opts = model.Klass._meta
|
opts = model.Klass._meta
|
||||||
|
|
||||||
# Gather fields/field descriptions
|
# Gather fields/field descriptions
|
||||||
fields = []
|
fields = []
|
||||||
for field in opts.fields:
|
for field in opts.fields:
|
||||||
|
@ -251,7 +251,7 @@ def load_all_installed_template_libraries():
|
||||||
reload(mod)
|
reload(mod)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_return_data_type(func_name):
|
def get_return_data_type(func_name):
|
||||||
"""Return a somewhat-helpful data type given a function name"""
|
"""Return a somewhat-helpful data type given a function name"""
|
||||||
if func_name.startswith('get_'):
|
if func_name.startswith('get_'):
|
||||||
|
@ -292,13 +292,13 @@ DATA_TYPE_MAPPING = {
|
||||||
'XMLField' : 'XML text',
|
'XMLField' : 'XML text',
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_readable_field_data_type(field):
|
def get_readable_field_data_type(field):
|
||||||
return DATA_TYPE_MAPPING[field.__class__.__name__] % field.__dict__
|
return DATA_TYPE_MAPPING[field.__class__.__name__] % field.__dict__
|
||||||
|
|
||||||
def extract_views_from_urlpatterns(urlpatterns, base=''):
|
def extract_views_from_urlpatterns(urlpatterns, base=''):
|
||||||
"""
|
"""
|
||||||
Return a list of views from a list of urlpatterns.
|
Return a list of views from a list of urlpatterns.
|
||||||
|
|
||||||
Each object in the returned list is a two-tuple: (view_func, regex)
|
Each object in the returned list is a two-tuple: (view_func, regex)
|
||||||
"""
|
"""
|
||||||
views = []
|
views = []
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
from django.core import formfields, meta, template_loader
|
from django.core import formfields, meta, template_loader
|
||||||
from django.core.exceptions import Http404, ObjectDoesNotExist, PermissionDenied
|
from django.core.exceptions import Http404, ObjectDoesNotExist, PermissionDenied
|
||||||
from django.core.extensions import CMSContext as Context
|
from django.core.extensions import DjangoContext as Context
|
||||||
from django.models.auth import log
|
from django.models.auth import log
|
||||||
from django.utils.html import strip_tags
|
from django.utils.html import strip_tags
|
||||||
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
|
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.core import formfields, template_loader, validators
|
from django.core import formfields, template_loader, validators
|
||||||
from django.core import template
|
from django.core import template
|
||||||
from django.core.extensions import CMSContext as Context
|
from django.core.extensions import DjangoContext as Context
|
||||||
from django.utils.httpwrappers import HttpResponse
|
from django.utils.httpwrappers import HttpResponse
|
||||||
from django.models.core import sites
|
from django.models.core import sites
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.parts.auth.formfields import AuthenticationForm
|
from django.parts.auth.formfields import AuthenticationForm
|
||||||
from django.core import formfields, template_loader
|
from django.core import formfields, template_loader
|
||||||
from django.core.extensions import CMSContext as Context
|
from django.core.extensions import DjangoContext as Context
|
||||||
from django.models.auth import sessions
|
from django.models.auth import sessions
|
||||||
from django.models.core import sites
|
from django.models.core import sites
|
||||||
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
|
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.core import template_loader
|
from django.core import template_loader
|
||||||
from django.core.exceptions import Http404
|
from django.core.exceptions import Http404
|
||||||
from django.core.extensions import CMSContext as Context
|
from django.core.extensions import DjangoContext as Context
|
||||||
from django.models.core import flatfiles
|
from django.models.core import flatfiles
|
||||||
from django.utils.httpwrappers import HttpResponse
|
from django.utils.httpwrappers import HttpResponse
|
||||||
from django.conf.settings import SITE_ID
|
from django.conf.settings import SITE_ID
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.core import template_loader
|
from django.core import template_loader
|
||||||
from django.core.exceptions import Http404, ObjectDoesNotExist
|
from django.core.exceptions import Http404, ObjectDoesNotExist
|
||||||
from django.core.extensions import CMSContext as Context
|
from django.core.extensions import DjangoContext as Context
|
||||||
from django.models.core import sites
|
from django.models.core import sites
|
||||||
from django.utils import httpwrappers
|
from django.utils import httpwrappers
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.core import template_loader
|
from django.core import template_loader
|
||||||
from django.core.exceptions import Http404, ObjectDoesNotExist
|
from django.core.exceptions import Http404, ObjectDoesNotExist
|
||||||
from django.core.extensions import CMSContext as Context
|
from django.core.extensions import DjangoContext as Context
|
||||||
from django.core.xheaders import populate_xheaders
|
from django.core.xheaders import populate_xheaders
|
||||||
from django.models import get_module
|
from django.models import get_module
|
||||||
from django.utils.httpwrappers import HttpResponse
|
from django.utils.httpwrappers import HttpResponse
|
||||||
|
|
|
@ -2,7 +2,7 @@ from django import models
|
||||||
from django.core import template_loader
|
from django.core import template_loader
|
||||||
from django.utils.httpwrappers import HttpResponse
|
from django.utils.httpwrappers import HttpResponse
|
||||||
from django.core.xheaders import populate_xheaders
|
from django.core.xheaders import populate_xheaders
|
||||||
from django.core.extensions import CMSContext as Context
|
from django.core.extensions import DjangoContext as Context
|
||||||
from django.core.paginator import ObjectPaginator, InvalidPage
|
from django.core.paginator import ObjectPaginator, InvalidPage
|
||||||
from django.core.exceptions import Http404, ObjectDoesNotExist
|
from django.core.exceptions import Http404, ObjectDoesNotExist
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.core import formfields, template_loader, validators
|
from django.core import formfields, template_loader, validators
|
||||||
from django.core.extensions import CMSContext as Context
|
from django.core.extensions import DjangoContext as Context
|
||||||
from django.models.auth import users
|
from django.models.auth import users
|
||||||
from django.views.decorators.auth import login_required
|
from django.views.decorators.auth import login_required
|
||||||
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
|
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
|
||||||
|
|
Loading…
Reference in New Issue