'Decorator to create an admin view attached to this ``AdminSite``. This
wraps the view and provides permission checking by calling
``self.has_permission``.
You\'ll want to use this from within ``AdminSite.get_urls()``:
class MyAdminSite(AdminSite):
def get_urls(self):
from django.conf.urls import patterns, url
urls = super(MyAdminSite, self).get_urls()
urls += patterns(\'\',
url(r\'^my_view/$\', self.admin_view(some_view))
return urls
By default, admin_views are marked non-cacheable using the
``never_cache`` decorator. If the view can be safely cached, set
cacheable=True.'

def admin_view(self, view, cacheable=False):

    def inner(request, *args, **kwargs):
        if ((LOGIN_FORM_KEY in request.POST) and request.user.is_authenticated()):
            auth_logout(request)
        if (not self.has_permission(request)):
            if (request.path == reverse('admin:logout', current_app=self.name)):
                index_path = reverse('admin:index', current_app=self.name)
                return HttpResponseRedirect(index_path)
            return self.login(request)
        return view(request, *args, **kwargs)
    if (not cacheable):
        inner = never_cache(inner)
    if (not getattr(view, 'csrf_exempt', False)):
        inner = csrf_protect(inner)
    return update_wrapper(inner, view)
