From 2543d0ae9373eeea9eebce3d48df930b3220a506 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Wed, 31 May 2006 15:25:23 +0000 Subject: [PATCH] Fixed bug in admin where it would redirect infinitely if invalid lookup parameters were given in the URL. Refs #2024 git-svn-id: http://code.djangoproject.com/svn/django/trunk@3024 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- .../contrib/admin/templates/admin/invalid_setup.html | 10 ++++++++++ django/contrib/admin/views/main.py | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 django/contrib/admin/templates/admin/invalid_setup.html diff --git a/django/contrib/admin/templates/admin/invalid_setup.html b/django/contrib/admin/templates/admin/invalid_setup.html new file mode 100644 index 0000000000..1fa0d32358 --- /dev/null +++ b/django/contrib/admin/templates/admin/invalid_setup.html @@ -0,0 +1,10 @@ +{% extends "admin/base_site.html" %} +{% load i18n %} + +{% block breadcrumbs %}{% endblock %} + +{% block content %} + +

{% trans "Something's wrong with your database installation. Make sure the appropriate database tables have been created, and make sure the database is readable by the appropriate user." %}

+ +{% endblock %} diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index acaf1fcae6..14bd678758 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -35,6 +35,7 @@ ORDER_TYPE_VAR = 'ot' PAGE_VAR = 'p' SEARCH_VAR = 'q' IS_POPUP_VAR = 'pop' +ERROR_FLAG = 'e' # Text to display within change-list table cells if the value is blank. EMPTY_CHANGELIST_VALUE = '(None)' @@ -557,6 +558,8 @@ class ChangeList(object): self.params = dict(request.GET.items()) if self.params.has_key(PAGE_VAR): del self.params[PAGE_VAR] + if self.params.has_key(ERROR_FLAG): + del self.params[ERROR_FLAG] self.order_field, self.order_type = self.get_ordering() self.query = request.GET.get(SEARCH_VAR, '') @@ -730,7 +733,14 @@ def change_list(request, app_label, model_name): try: cl = ChangeList(request, model) except IncorrectLookupParameters: - return HttpResponseRedirect(request.path) + # Wacky lookup parameters were given, so redirect to the main + # changelist page, without parameters, and pass an 'invalid=1' + # parameter via the query string. If wacky parameters were given and + # the 'invalid=1' parameter was already in the query string, something + # is screwed up with the database, so display an error page. + if ERROR_FLAG in request.GET.keys(): + return render_to_response('admin/invalid_setup.html', {'title': _('Database error')}) + return HttpResponseRedirect(request.path + '?' + ERROR_FLAG + '=1') c = template.RequestContext(request, { 'title': cl.title, 'is_popup': cl.is_popup,