diff mbox

[Branch,~linaro-validation/lava-server/trunk] Rev 348: improve error 500 handler page

Message ID 20120216013619.24417.42753.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Paul Larson Feb. 16, 2012, 1:36 a.m. UTC
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 <paul.larson@linaro.org>
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
diff mbox

Patch

=== 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 %}
 <h1>500 Internal Server Error</h1>
+<p>
+  Oops, something has gone wrong!
+</p>
+{% if request.sentry.id %}
+    <p>If you need assistance, you may reference this error as <strong>{{ request.sentry.id }}</strong>.</p>
+{% 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 <http://www.gnu.org/licenses/>.
 
+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,
+                })))