From 52c0a932937768cdbb4c17cc41718ffdfd8391eb Mon Sep 17 00:00:00 2001 From: Chris Church Date: Tue, 19 Nov 2013 22:58:46 -0500 Subject: [PATCH] Fix error views to use base REST framework template instead of admin, since admin is disabled. --- awx/main/views.py | 33 +++++++++++++++----- awx/templates/403.html | 7 ----- awx/templates/404.html | 6 ---- awx/templates/500.html | 6 ---- awx/templates/admin/403.html | 20 ------------ awx/templates/admin/404.html | 18 ----------- awx/templates/admin/{500.html => error.html} | 8 ++--- awx/templates/error.html | 28 +++++++++++++++++ awx/templates/rest_framework/api.html | 10 +++--- awx/urls.py | 20 ++++++------ 10 files changed, 73 insertions(+), 83 deletions(-) delete mode 100644 awx/templates/403.html delete mode 100644 awx/templates/404.html delete mode 100644 awx/templates/500.html delete mode 100644 awx/templates/admin/403.html delete mode 100644 awx/templates/admin/404.html rename awx/templates/admin/{500.html => error.html} (60%) create mode 100644 awx/templates/error.html diff --git a/awx/main/views.py b/awx/main/views.py index cc487ee4ed..72298fabc0 100644 --- a/awx/main/views.py +++ b/awx/main/views.py @@ -4,20 +4,39 @@ # Django from django.shortcuts import render from django.template import RequestContext +from django.utils.safestring import mark_safe -def handle_error(request, status=404): - context = {} +def handle_error(request, status=404, **kwargs): + # FIXME: Should attempt to check HTTP Accept request header and return + # plain JSON response instead of HTML (maybe only for /api/*). + context = kwargs if request.path.startswith('/admin/'): - template_name = 'admin/%d.html' % status + template_name = 'admin/error.html' else: - template_name = '%d.html' % status + # Return enough context to popuplate the base API template. + description = u'
%s
' % context.get('content', '') + context['description'] = mark_safe(description) + context['content'] = '' + template_name = 'error.html' return render(request, template_name, context, status=status) def handle_403(request): - return handle_error(request, 403) + kwargs = { + 'name': 'Forbidden', + 'content': 'You don\'t have permission to access the requested page.', + } + return handle_error(request, 403, **kwargs) def handle_404(request): - return handle_error(request, 404) + kwargs = { + 'name': 'Not Found', + 'content': 'The requested page could not be found.', + } + return handle_error(request, 404, **kwargs) def handle_500(request): - return handle_error(request, 500) + kwargs = { + 'name': 'Server Error', + 'content': 'A server error has occurred.', + } + return handle_error(request, 500, **kwargs) diff --git a/awx/templates/403.html b/awx/templates/403.html deleted file mode 100644 index a429102a5e..0000000000 --- a/awx/templates/403.html +++ /dev/null @@ -1,7 +0,0 @@ -{% extends "admin/403.html" %} - -{% block branding_title %}AWX{% endblock %} - -{% block breadcrumbs %} -{% endblock %} - diff --git a/awx/templates/404.html b/awx/templates/404.html deleted file mode 100644 index d3e75e07b3..0000000000 --- a/awx/templates/404.html +++ /dev/null @@ -1,6 +0,0 @@ -{% extends "admin/404.html" %} - -{% block branding_title %}AWX{% endblock %} - -{% block breadcrumbs %} -{% endblock %} diff --git a/awx/templates/500.html b/awx/templates/500.html deleted file mode 100644 index 009b7e07a9..0000000000 --- a/awx/templates/500.html +++ /dev/null @@ -1,6 +0,0 @@ -{% extends "admin/500.html" %} - -{% block branding_title %}AWX{% endblock %} - -{% block breadcrumbs %} -{% endblock %} diff --git a/awx/templates/admin/403.html b/awx/templates/admin/403.html deleted file mode 100644 index 8e38808645..0000000000 --- a/awx/templates/admin/403.html +++ /dev/null @@ -1,20 +0,0 @@ -{% extends "admin/base_site.html" %} -{% load i18n %} - -{% block title %}{% trans "Forbidden" %}{% endblock %} - -{% block nav-global %}{% endblock %} - -{% block content_title %}{% endblock %} - -{% block breadcrumbs %} - -{% endblock %} - -{% block content %} -

{% trans 'Forbidden' %}

-

{% trans "You don't have permission to access the requested page." %}

-{% endblock %} diff --git a/awx/templates/admin/404.html b/awx/templates/admin/404.html deleted file mode 100644 index 0ec799602e..0000000000 --- a/awx/templates/admin/404.html +++ /dev/null @@ -1,18 +0,0 @@ -{% extends "admin/base_site.html" %} -{% load i18n %} - -{% block title %}{% trans "Not Found" %}{% endblock %} - -{% block nav-global %}{% endblock %} - -{% block breadcrumbs %} - -{% endblock %} - -{% block content %} -

{% trans 'Not Found' %}

-

{% trans "We're sorry, but the requested page could not be found." %}

-{% endblock %} diff --git a/awx/templates/admin/500.html b/awx/templates/admin/error.html similarity index 60% rename from awx/templates/admin/500.html rename to awx/templates/admin/error.html index 3a015f0942..185e18ab63 100644 --- a/awx/templates/admin/500.html +++ b/awx/templates/admin/error.html @@ -1,7 +1,7 @@ {% extends "admin/base_site.html" %} {% load i18n %} -{% block title %}{% trans "Server Error" %}{% endblock %} +{% block title %}{{ name }}{% endblock %} {% block nav-global %}{% endblock %} @@ -10,11 +10,11 @@ {% block breadcrumbs %} {% endblock %} {% block content %} -

{% trans 'Server Error' %}

-

{% trans "A server error has occurred." %}

+

{{ name }}

+

{{ content }}

{% endblock %} diff --git a/awx/templates/error.html b/awx/templates/error.html new file mode 100644 index 0000000000..660740ce52 --- /dev/null +++ b/awx/templates/error.html @@ -0,0 +1,28 @@ +{% extends "rest_framework/api.html" %} +{% load i18n %} + +{% block style %} +{{ block.super }} + +{% endblock %} + +{% block branding_title %}{% endblock %} + +{% block breadcrumbs %} + +{% endblock %} diff --git a/awx/templates/rest_framework/api.html b/awx/templates/rest_framework/api.html index d0c3270494..e80b4b7dfd 100644 --- a/awx/templates/rest_framework/api.html +++ b/awx/templates/rest_framework/api.html @@ -1,7 +1,7 @@ {% extends 'rest_framework/base.html' %} {% load i18n %} -{% block title %}{% trans 'AWX REST API' %}{% endblock %} +{% block title %}{{ name }} · {% trans 'AWX REST API' %}{% endblock %} {% block style %} {{ block.super }} @@ -101,6 +101,7 @@ html body .description { font-size: 0.8em; text-align: center; padding-bottom: 1em; + line-height: 1.6em; } #footer a, #footer a:hover { @@ -125,7 +126,7 @@ html body #push { {% endblock %} {% block branding %} - {% trans 'REST API' %} + {% block branding_title %}{% trans 'REST API' %}{% endblock %} {% endblock %} {% block userlinks %} @@ -139,8 +140,9 @@ html body #push { {% block footer %} + Copyright © 2013 AnsibleWorks, Inc. All rights reserved.
+ 1482 East Valley Road, Suite 888 · Santa Barbara, California 93108 · +1-800-825-0212
+
www.ansibleworks.com {% endblock %} {% block script %} diff --git a/awx/urls.py b/awx/urls.py index 33c73c3958..7da3baa234 100644 --- a/awx/urls.py +++ b/awx/urls.py @@ -13,22 +13,20 @@ urlpatterns = patterns('', url(r'^api/', include('awx.api.urls', namespace='api', app_name='api')), ) +urlpatterns += patterns('awx.main.views', + url(r'^403.html$', 'handle_403'), + url(r'^404.html$', 'handle_404'), + url(r'^500.html$', 'handle_500'), +) + if 'django.contrib.admin' in settings.INSTALLED_APPS: from django.contrib import admin admin.autodiscover() urlpatterns += patterns('', url(r'^admin/', include(admin.site.urls)), ) - -if settings.DEBUG: urlpatterns += patterns('awx.main.views', - url(r'^403.html$', 'handle_403'), - url(r'^404.html$', 'handle_404'), - url(r'^500.html$', 'handle_500'), + url(r'^admin/403.html$', 'handle_403'), + url(r'^admin/404.html$', 'handle_404'), + url(r'^admin/500.html$', 'handle_500'), ) - if 'django.contrib.admin' in settings.INSTALLED_APPS: - urlpatterns += patterns('awx.main.views', - url(r'^admin/403.html$', 'handle_403'), - url(r'^admin/404.html$', 'handle_404'), - url(r'^admin/500.html$', 'handle_500'), - )