From patchwork Thu Feb 16 01:36:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Larson X-Patchwork-Id: 6812 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id D0E2A23DC3 for ; Thu, 16 Feb 2012 01:36:21 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 79BA8A18A5F for ; Thu, 16 Feb 2012 01:36:21 +0000 (UTC) Received: by iabz7 with SMTP id z7so3090163iab.11 for ; Wed, 15 Feb 2012 17:36:21 -0800 (PST) Received: by 10.43.48.65 with SMTP id uv1mr361487icb.57.1329356180954; Wed, 15 Feb 2012 17:36:20 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.80.19 with SMTP id r19cs1765ibk; Wed, 15 Feb 2012 17:36:20 -0800 (PST) Received: by 10.180.92.226 with SMTP id cp2mr850287wib.10.1329356179626; Wed, 15 Feb 2012 17:36:19 -0800 (PST) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id f58si4007968wed.83.2012.02.15.17.36.19 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 15 Feb 2012 17:36:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1RxqGh-0003EO-3g for ; Thu, 16 Feb 2012 01:36:19 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 137E4E01E8 for ; Thu, 16 Feb 2012 01:36:19 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: lava-server X-Launchpad-Branch: ~linaro-validation/lava-server/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 348 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-server/trunk] Rev 348: improve error 500 handler page Message-Id: <20120216013619.24417.42753.launchpad@ackee.canonical.com> Date: Thu, 16 Feb 2012 01:36:19 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14781"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 790b6f40d18670223a97c5aaa14f56f2f69a8479 X-Gm-Message-State: ALoCoQmqW9UkrpSrA+9MXhvH9NgCAERLzh3GamAWTFVJsv/5hNoT+zdW1Q8c0Yh23QYNR39L/hbj Merge authors: Michael Hudson-Doyle (mwhudson) Related merge proposals: https://code.launchpad.net/~mwhudson/lava-server/nicer-500-page/+merge/93305 proposed by: Michael Hudson-Doyle (mwhudson) review: Approve - Paul Larson (pwlars) ------------------------------------------------------------ revno: 348 [merge] committer: Paul Larson branch nick: lava-server timestamp: Wed 2012-02-15 17:31:54 -0800 message: improve error 500 handler page modified: lava_server/settings/debian.py lava_server/templates/500.html lava_server/urls.py lava_server/views.py --- lp:lava-server https://code.launchpad.net/~linaro-validation/lava-server/trunk You are subscribed to branch lp:lava-server. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-server/trunk/+edit-subscription === modified file 'lava_server/settings/debian.py' --- lava_server/settings/debian.py 2011-11-29 15:23:04 +0000 +++ lava_server/settings/debian.py 2012-02-15 21:52:35 +0000 @@ -1,5 +1,7 @@ # Django settings for django_hello project used on Debian systems. +import os + from django_debian.settings import Settings from lava_server.extension import loader @@ -43,7 +45,8 @@ ADMIN_MEDIA_PREFIX = debian_settings.ADMIN_MEDIA_PREFIX # List of absolute pathnames used to resolve templates. -TEMPLATE_DIRS = debian_settings.TEMPLATE_DIRS +TEMPLATE_DIRS = [os.path.join(os.path.dirname(__file__), '..', 'templates')] +TEMPLATE_DIRS.extend(debian_settings.TEMPLATE_DIRS) # Like TEMPLATE_DIRS but for static files STATICFILES_DIRS = debian_settings.STATICFILES_DIRS === modified file 'lava_server/templates/500.html' --- lava_server/templates/500.html 2011-07-08 04:23:51 +0000 +++ lava_server/templates/500.html 2012-02-15 21:53:07 +0000 @@ -1,9 +1,17 @@ {% extends "layouts/content.html" %} +{% block breadcrumb_container %}{% endblock %} + {% block title %} | HTTP 500 {% endblock %} {% block content %}

500 Internal Server Error

+

+ Oops, something has gone wrong! +

+{% if request.sentry.id %} +

If you need assistance, you may reference this error as {{ request.sentry.id }}.

+{% endif %} {% endblock %} === modified file 'lava_server/urls.py' --- lava_server/urls.py 2011-12-05 23:39:52 +0000 +++ lava_server/urls.py 2012-02-15 21:53:07 +0000 @@ -18,7 +18,7 @@ from django.conf import settings from django.conf.urls.defaults import ( - handler404, handler500, include, patterns, url) + handler404, include, patterns, url) from django.contrib import admin from staticfiles.urls import staticfiles_urlpatterns from linaro_django_xmlrpc import urls as api_urls @@ -27,6 +27,8 @@ from lava_server.views import index, me, version +handler500 = 'lava_server.views.server_error' + # Enable admin stuff admin.autodiscover() === modified file 'lava_server/views.py' --- lava_server/views.py 2011-11-22 16:26:07 +0000 +++ lava_server/views.py 2012-02-15 21:53:07 +0000 @@ -16,11 +16,12 @@ # You should have received a copy of the GNU Affero General Public License # along with LAVA Server. If not, see . +from django.conf import settings from django.contrib.auth.decorators import login_required -from django.http import HttpResponse -from django.template import loader, RequestContext +from django.http import HttpResponse, HttpResponseServerError +from django.template import Context, loader, RequestContext from django.utils.translation import ugettext as _ -from django.views.generic.simple import direct_to_template +from django.views.decorators.csrf import requires_csrf_token from lava_server.bread_crumbs import ( BreadCrumb, @@ -67,3 +68,16 @@ context = RequestContext(request, data) template = loader.get_template('version_details.html') return HttpResponse(template.render(context)) + + +@requires_csrf_token +def server_error(request, template_name='500.html'): + t = loader.get_template(template_name) + return HttpResponseServerError( + t.render( + Context( + { + 'STATIC_URL':settings.STATIC_URL, + 'user':request.user, + 'request':request, + })))