Ticket #6552: admin-context.patch

File admin-context.patch, 6.3 KB (added by Ole Laursen, 16 years ago)

Patch against 9820 for removing admin's dependency on auth context processor

  • django/contrib/admin/options.py

     
    33from django.forms.models import modelform_factory, inlineformset_factory
    44from django.forms.models import BaseInlineFormSet
    55from django.contrib.contenttypes.models import ContentType
    6 from django.contrib.admin import widgets
    7 from django.contrib.admin import helpers
     6from django.contrib.admin import widgets, helpers
     7from django.contrib.admin.context import AdminContext
    88from django.contrib.admin.util import unquote, flatten_fieldsets, get_deleted_objects
    99from django.core.exceptions import PermissionDenied
    1010from django.db import models, transaction
     
    442442            "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
    443443            "admin/%s/change_form.html" % app_label,
    444444            "admin/change_form.html"
    445         ], context, context_instance=template.RequestContext(request))
     445        ], context, context_instance=AdminContext(request))
    446446   
    447447    def response_add(self, request, obj, post_url_continue='../%s/'):
    448448        """
     
    688688            'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
    689689            'admin/%s/change_list.html' % app_label,
    690690            'admin/change_list.html'
    691         ], context, context_instance=template.RequestContext(request))
     691        ], context, context_instance=AdminContext(request))
    692692   
    693693    def delete_view(self, request, object_id, extra_context=None):
    694694        "The 'delete' admin view for this model."
     
    743743            "admin/%s/%s/delete_confirmation.html" % (app_label, opts.object_name.lower()),
    744744            "admin/%s/delete_confirmation.html" % app_label,
    745745            "admin/delete_confirmation.html"
    746         ], context, context_instance=template.RequestContext(request))
     746        ], context, context_instance=AdminContext(request))
    747747   
    748748    def history_view(self, request, object_id, extra_context=None):
    749749        "The 'history' admin view for this model."
     
    770770            "admin/%s/%s/object_history.html" % (app_label, opts.object_name.lower()),
    771771            "admin/%s/object_history.html" % app_label,
    772772            "admin/object_history.html"
    773         ], context, context_instance=template.RequestContext(request))
     773        ], context, context_instance=AdminContext(request))
    774774
    775775    #
    776776    # DEPRECATED methods.
  • django/contrib/admin/context.py

     
     1from django import template
     2from django.conf import settings
     3
     4class AdminContext(template.RequestContext):
     5    """RequestContext subclass that adds a few context variables
     6    useful for admin.
     7
     8    The variables are 'user', 'messages' and 'perms' (internally, it
     9    uses the auth context processor if it's not already in the settings).
     10    """
     11   
     12    def __init__(self, request, dict=None, processors=None):
     13        template.RequestContext.__init__(self, request, dict, processors)
     14
     15        if 'django.core.context_processors.auth' not in settings.TEMPLATE_CONTEXT_PROCESSORS:
     16            from django.core import context_processors
     17            self.update(context_processors.auth(request))
  • django/contrib/admin/views/template.py

     
    11from django import template, forms
     2from django.contrib.admin.context import AdminContext
    23from django.contrib.admin.views.decorators import staff_member_required
    34from django.template import loader
    45from django.shortcuts import render_to_response
     
    2829    return render_to_response('admin/template_validator.html', {
    2930        'title': 'Template validator',
    3031        'form': form,
    31     }, context_instance=template.RequestContext(request))
     32    }, context_instance=AdminContext(request))
    3233template_validator = staff_member_required(template_validator)
    3334
    3435
  • django/contrib/admin/sites.py

     
    11import re
    22from django import http, template
    33from django.contrib.admin import ModelAdmin
     4from django.contrib.admin.context import AdminContext
    45from django.contrib.auth import authenticate, login
    56from django.db.models.base import ModelBase
    67from django.core.exceptions import ImproperlyConfigured
     
    120121            raise ImproperlyConfigured("Put 'django.contrib.admin' in your INSTALLED_APPS setting in order to use the admin application.")
    121122        if not ContentType._meta.installed:
    122123            raise ImproperlyConfigured("Put 'django.contrib.contenttypes' in your INSTALLED_APPS setting in order to use the admin application.")
    123         if 'django.core.context_processors.auth' not in settings.TEMPLATE_CONTEXT_PROCESSORS:
    124             raise ImproperlyConfigured("Put 'django.core.context_processors.auth' in your TEMPLATE_CONTEXT_PROCESSORS setting in order to use the admin application.")
    125124       
    126125    def admin_view(self, view):
    127126        """
     
    331330        }
    332331        context.update(extra_context or {})
    333332        return render_to_response(self.index_template or 'admin/index.html', context,
    334             context_instance=template.RequestContext(request)
     333            context_instance=AdminContext(request)
    335334        )
    336335    index = never_cache(index)
    337336   
     
    345344        }
    346345        context.update(extra_context or {})
    347346        return render_to_response(self.login_template or 'admin/login.html', context,
    348             context_instance=template.RequestContext(request)
     347            context_instance=AdminContext(request)
    349348        )
    350349   
    351350    def app_index(self, request, app_label, extra_context=None):
     
    391390        }
    392391        context.update(extra_context or {})
    393392        return render_to_response(self.app_index_template or 'admin/app_index.html', context,
    394             context_instance=template.RequestContext(request)
     393            context_instance=AdminContext(request)
    395394        )
    396395       
    397396    def root(self, request, url):
Back to Top