From 1bfed070c32173e69be6272b274506c1bd56d413 Mon Sep 17 00:00:00 2001
From: Adrian Holovaty <adrian@holovaty.com>
Date: Mon, 8 Sep 2008 05:45:17 +0000
Subject: [PATCH] Fixed #7929 -- Removed some snippets of admin code that
 weren't doing anything, and tightened up a few more lines. Plus, an
 indentation fix. Thanks, julien

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8985 bcc190cf-cafb-0310-a4f2-bffc1f526a37
---
 django/contrib/admin/options.py | 17 ++++-------------
 django/contrib/admin/sites.py   |  1 -
 django/contrib/admin/widgets.py |  2 +-
 3 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index ba48ded09a..ea322dab14 100644
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -471,18 +471,10 @@ class ModelAdmin(BaseModelAdmin):
         "The 'add' admin view for this model."
         model = self.model
         opts = model._meta
-        app_label = opts.app_label
 
         if not self.has_add_permission(request):
             raise PermissionDenied
 
-        if self.has_change_permission(request, None):
-            # redirect to list view
-            post_url = '../'
-        else:
-            # Object list will give 'Permission Denied', so go back to admin home
-            post_url = '../../../'
-
         ModelForm = self.get_form(request)
         formsets = []
         if request.method == 'POST':
@@ -541,7 +533,7 @@ class ModelAdmin(BaseModelAdmin):
             'inline_admin_formsets': inline_admin_formsets,
             'errors': helpers.AdminErrorList(form, formsets),
             'root_path': self.admin_site.root_path,
-            'app_label': app_label,
+            'app_label': opts.app_label,
         }
         context.update(extra_context or {})
         return self.render_change_form(request, context, add=True)
@@ -551,7 +543,6 @@ class ModelAdmin(BaseModelAdmin):
         "The 'change' admin view for this model."
         model = self.model
         opts = model._meta
-        app_label = opts.app_label
 
         try:
             obj = model._default_manager.get(pk=object_id)
@@ -620,7 +611,7 @@ class ModelAdmin(BaseModelAdmin):
             'inline_admin_formsets': inline_admin_formsets,
             'errors': helpers.AdminErrorList(form, formsets),
             'root_path': self.admin_site.root_path,
-            'app_label': app_label,
+            'app_label': opts.app_label,
         }
         context.update(extra_context or {})
         return self.render_change_form(request, context, change=True, obj=obj)
@@ -738,8 +729,8 @@ class ModelAdmin(BaseModelAdmin):
         }
         context.update(extra_context or {})
         return render_to_response(self.object_history_template or [
-            "admin/%s/%s/object_history.html" % (opts.app_label, opts.object_name.lower()),
-            "admin/%s/object_history.html" % opts.app_label,
+            "admin/%s/%s/object_history.html" % (app_label, opts.object_name.lower()),
+            "admin/%s/object_history.html" % app_label,
             "admin/object_history.html"
         ], context, context_instance=template.RequestContext(request))
 
diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
index 0be93a20c3..f0bb0493b2 100644
--- a/django/contrib/admin/sites.py
+++ b/django/contrib/admin/sites.py
@@ -105,7 +105,6 @@ class AdminSite(object):
         The default implementation checks that LogEntry, ContentType and the
         auth context processor are installed.
         """
-        from django.conf import settings
         from django.contrib.admin.models import LogEntry
         from django.contrib.contenttypes.models import ContentType
 
diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
index f9ddf9acd9..6a2d982351 100644
--- a/django/contrib/admin/widgets.py
+++ b/django/contrib/admin/widgets.py
@@ -114,7 +114,7 @@ class ForeignKeyRawIdWidget(forms.TextInput):
         else:
             url = ''
         if not attrs.has_key('class'):
-          attrs['class'] = 'vForeignKeyRawIdAdminField' # The JavaScript looks for this hook.
+            attrs['class'] = 'vForeignKeyRawIdAdminField' # The JavaScript looks for this hook.
         output = [super(ForeignKeyRawIdWidget, self).render(name, value, attrs)]
         # TODO: "id_" is hard-coded here. This should instead use the correct
         # API to determine the ID dynamically.