diff --git a/ansibleworks/main/views.py b/ansibleworks/main/views.py index f813b3d528..4d414de5ca 100644 --- a/ansibleworks/main/views.py +++ b/ansibleworks/main/views.py @@ -2,6 +2,8 @@ # All Rights Reserved. from django.http import HttpResponse +from django.shortcuts import render_to_response +from django.template import RequestContext from django.views.decorators.csrf import csrf_exempt from django.shortcuts import get_object_or_404 from ansibleworks.main.models import * @@ -26,6 +28,25 @@ import json as python_json from base_views import * from ansibleworks.main.access import * +def handle_error(request, status=404): + context = {} + print request.path, status + if request.path.startswith('/admin/'): + template_name = 'admin/%d.html' % status + else: + template_name = '%d.html' % status + return render_to_response(template_name, context, + context_instance=RequestContext(request)) + +def handle_403(request): + return handle_error(request, 403) + +def handle_404(request): + return handle_error(request, 404) + +def handle_500(request): + return handle_error(request, 500) + class ApiRootView(APIView): ''' Ansible Commander REST API diff --git a/ansibleworks/middleware/exceptions.py b/ansibleworks/middleware/exceptions.py index 293f8eae47..9bfc948513 100644 --- a/ansibleworks/middleware/exceptions.py +++ b/ansibleworks/middleware/exceptions.py @@ -7,6 +7,7 @@ from django.http import HttpResponse class ExceptionMiddleware(object): def process_exception(self, request, exception): - # FIXME: Should only format plain text for API exceptions. - return HttpResponse(traceback.format_exc(exception), content_type="text/plain", status=500) - + if request.path.startswith('/api/'): + # FIXME: For GA, we shouldn't provide this level of detail to the + # end user. + return HttpResponse(traceback.format_exc(exception), content_type="text/plain", status=500) diff --git a/ansibleworks/settings/defaults.py b/ansibleworks/settings/defaults.py index a1a275654b..3dbaa999be 100644 --- a/ansibleworks/settings/defaults.py +++ b/ansibleworks/settings/defaults.py @@ -110,7 +110,6 @@ TEMPLATE_CONTEXT_PROCESSORS += ( ) MIDDLEWARE_CLASSES += ( - 'django.contrib.auth.middleware.AuthenticationMiddleware', 'ansibleworks.middleware.exceptions.ExceptionMiddleware', 'django.middleware.transaction.TransactionMiddleware', # middleware loaded after this point will be subject to transactions @@ -221,24 +220,27 @@ LOGGING = { 'handlers': { 'console': { 'level': 'DEBUG', - #'filters': ['require_debug_true'], + 'filters': ['require_debug_true'], 'class': 'logging.StreamHandler', }, 'null': { 'class': 'django.utils.log.NullHandler', }, + 'file': { + 'class': 'django.utils.log.NullHandler', + }, 'mail_admins': { 'level': 'ERROR', 'filters': ['require_debug_false'], - 'class': 'django.utils.log.AdminEmailHandler' - } + 'class': 'django.utils.log.AdminEmailHandler', + }, }, 'loggers': { 'django': { 'handlers': ['console'], }, 'django.request': { - 'handlers': ['mail_admins', 'console'], + 'handlers': ['mail_admins', 'console', 'file'], 'level': 'ERROR', 'propagate': False, }, diff --git a/ansibleworks/templates/403.html b/ansibleworks/templates/403.html new file mode 100644 index 0000000000..afd194228d --- /dev/null +++ b/ansibleworks/templates/403.html @@ -0,0 +1,4 @@ +{% extends "admin/403.html" %} + +{% block breadcrumbs %} +{% endblock %} diff --git a/ansibleworks/templates/404.html b/ansibleworks/templates/404.html new file mode 100644 index 0000000000..0ccb3c59c5 --- /dev/null +++ b/ansibleworks/templates/404.html @@ -0,0 +1,4 @@ +{% extends "admin/404.html" %} + +{% block breadcrumbs %} +{% endblock %} diff --git a/ansibleworks/templates/500.html b/ansibleworks/templates/500.html new file mode 100644 index 0000000000..2937275395 --- /dev/null +++ b/ansibleworks/templates/500.html @@ -0,0 +1,4 @@ +{% extends "admin/500.html" %} + +{% block breadcrumbs %} +{% endblock %} diff --git a/ansibleworks/templates/admin/403.html b/ansibleworks/templates/admin/403.html new file mode 100644 index 0000000000..8e38808645 --- /dev/null +++ b/ansibleworks/templates/admin/403.html @@ -0,0 +1,20 @@ +{% 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 "You don't have permission to access the requested page." %}
+{% endblock %} diff --git a/ansibleworks/templates/admin/404.html b/ansibleworks/templates/admin/404.html new file mode 100644 index 0000000000..0ec799602e --- /dev/null +++ b/ansibleworks/templates/admin/404.html @@ -0,0 +1,18 @@ +{% extends "admin/base_site.html" %} +{% load i18n %} + +{% block title %}{% trans "Not Found" %}{% endblock %} + +{% block nav-global %}{% endblock %} + +{% block breadcrumbs %} + +{% endblock %} + +{% block content %} +{% trans "We're sorry, but the requested page could not be found." %}
+{% endblock %} diff --git a/ansibleworks/templates/admin/500.html b/ansibleworks/templates/admin/500.html new file mode 100644 index 0000000000..3a015f0942 --- /dev/null +++ b/ansibleworks/templates/admin/500.html @@ -0,0 +1,20 @@ +{% extends "admin/base_site.html" %} +{% load i18n %} + +{% block title %}{% trans "Server Error" %}{% endblock %} + +{% block nav-global %}{% endblock %} + +{% block content_title %}{% endblock %} + +{% block breadcrumbs %} + +{% endblock %} + +{% block content %} +{% trans "A server error has occurred." %}
+{% endblock %} diff --git a/ansibleworks/templates/admin/base_site.html b/ansibleworks/templates/admin/base_site.html index c99e253c11..d3e2a08ab1 100644 --- a/ansibleworks/templates/admin/base_site.html +++ b/ansibleworks/templates/admin/base_site.html @@ -2,7 +2,7 @@ {% extends "admin/base.html" %} {% load i18n %} -{% block title %}{{ title }} | {% trans 'Ansible Commander Admin' %}{% endblock %} +{% block title %}{{ title }} | {% trans 'AnsibleWorks Admin' %}{% endblock %} {% block extrastyle %} {{ block.super }} @@ -172,7 +172,7 @@ if (django.jQuery) { {% endblock %} {% block branding %} -