Browse Source

[ui] Use the same common header on all error views

bc Wong 13 years ago
parent
commit
ce76e7ec49

+ 3 - 3
desktop/core/src/desktop/middleware.py

@@ -25,7 +25,6 @@ from django.contrib.auth import REDIRECT_FIELD_NAME
 from django.core import exceptions, urlresolvers
 import django.db
 from django.http import HttpResponseRedirect, HttpResponse
-from django.shortcuts import render_to_response
 from django.utils.http import urlquote
 from django.utils.encoding import iri_to_uri
 import django.views.static
@@ -34,7 +33,7 @@ import django.contrib.auth.views
 
 import desktop.conf
 from desktop.lib import apputil, i18n
-from desktop.lib.django_util import render_json, is_jframe_request, PopupException
+from desktop.lib.django_util import render, render_json, is_jframe_request, PopupException
 from desktop.log.access import access_log, log_page_hit
 from desktop import appmanager
 from hadoop import cluster
@@ -76,7 +75,8 @@ class ExceptionMiddleware(object):
         response[MIDDLEWARE_HEADER] = 'EXCEPTION'
         return response
       else:
-        return render_to_response("error.html", dict(error=exception.response_data.get("message")))
+        return render("error.mako", request,
+                      dict(error=exception.response_data.get("message")))
 
     # We didn't handle it as a special exception, but if we're ajax we still
     # need to do some kind of nicer handling than the built-in page

+ 0 - 70
desktop/core/src/desktop/templates/404.html

@@ -1,70 +0,0 @@
-{% comment %}
-Licensed to Cloudera, Inc. under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  Cloudera, Inc. licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-{% endcomment %}
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
-	<title>Page Not Found</title>
-	<link rel="stylesheet" href="/static/ext/css/bootstrap.min.css" type="text/css" media="screen" title="no title" charset="utf-8" />
-	<link rel="stylesheet" href="/static/css/jhue.css" type="text/css" media="screen" title="no title" charset="utf-8" />
-	
-	<style type="text/css">
-      body {
-        padding-top: 60px;
-      }
-    </style>
-	<script src="/static/ext/js/jquery/jquery-1.7.min.js" type="text/javascript" charset="utf-8"></script>
-	
-
-	<script type="text/javascript" charset="utf-8">
-		$(document).ready(function(){
-		});
-	</script>
-	
-</head>
-<body>
-	<div class="topbar">
-		<div class="topbar-inner">
-			<div class="container-fluid">
-				<a class="brand" href="#">Hue</a>
-				<ul class="nav">
-					<li><a href="/beeswax">Beeswax</a></li>
-					<li><a href="/filebrowser/">File Browser</a></li>
-					<li><a href="/jobsub/">Job Designer</a></li>
-					<li><a href="/jobbrowser/jobs/">Job Browser</a></li>
-					<li><a href="/useradmin/">User Admin</a></li>
-					<li><a href="/shell/">Shell</a></li>
-					<li><a href="/help/">Help</a></li>
-					<li><a href="/about/">About</a></li>
-				</ul>
-			</div>
-		</div>
-	</div>
-	
-	<div class="container-fluid">
-		<h1>Page not found</h1>
-		<p>We're sorry, but the requested page could not be found:</p>
-		<br/>
-		<code>{{uri}}</code>
-	</div>
-</body>
-</html>
-
-

+ 28 - 0
desktop/core/src/desktop/templates/404.mako

@@ -0,0 +1,28 @@
+## Licensed to Cloudera, Inc. under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  Cloudera, Inc. licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##     http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+<%!
+from desktop.views import commonheader, commonfooter
+%>
+${commonheader("Not Found", "")}
+
+  <div class="container-fluid">
+    <h1>Page not found</h1>
+    <p>We're sorry, but the requested page could not be found:</p>
+    <br/>
+    <code>${uri}</code>
+  </div>
+
+${commonfooter()}

+ 0 - 71
desktop/core/src/desktop/templates/500.html

@@ -1,71 +0,0 @@
-{% comment %}
-Licensed to Cloudera, Inc. under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  Cloudera, Inc. licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-{% endcomment %}
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
-	<title>Internal server error</title>
-	<link rel="stylesheet" href="/static/ext/css/bootstrap.min.css" type="text/css" media="screen" title="no title" charset="utf-8" />
-	<link rel="stylesheet" href="/static/css/jhue.css" type="text/css" media="screen" title="no title" charset="utf-8" />
-	
-	<style type="text/css">
-      body {
-        padding-top: 60px;
-      }
-    </style>
-	<script src="/static/ext/js/jquery/jquery-1.7.min.js" type="text/javascript" charset="utf-8"></script>
-	
-
-	<script type="text/javascript" charset="utf-8">
-		$(document).ready(function(){
-		});
-	</script>
-
-</head>
-<body>
-  <div class="navbar navbar-fixed-top">
-    <div class="navbar-inner">
-      <div class="container-fluid">
-        <a class="brand" href="#">Hue</a>
-        <div class="nav-collapse">
-          <ul class="nav">
-            <li><a href="/beeswax/">Beeswax</a></li>
-            <li><a href="/filebrowser/">File Browser</a></li>
-            <li><a href="/jobsub/">Job Designer</a></li>
-            <li><a href="/jobbrowser/jobs/">Job Browser</a></li>
-            <li><a href="/useradmin/">User Admin</a></li>
-            <li><a href="/shell/">Shell</a></li>
-            <li><a href="/help/">Help</a></li>
-            <li><a href="/about/">About</a></li>
-            <li class="divider-vertical"></li>
-            <li id="checkConfig"></li>
-          </ul>
-        </div>
-      </div>
-    </div>
-  </div>
-
-	<div class="container-fluid">
-		<h1>Server Error (500)</h1>
-		<p>Sorry, there's been an error. It's been reported to the site administrators
-	  via e-mail and should be fixed shortly. Thanks for your patience.</p>
-	</div>
-</body>
-</html>

+ 27 - 0
desktop/core/src/desktop/templates/500.mako

@@ -0,0 +1,27 @@
+## Licensed to Cloudera, Inc. under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  Cloudera, Inc. licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##     http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+<%!
+from desktop.views import commonheader, commonfooter
+%>
+${commonheader("Error", "")}
+
+  <div class="container-fluid">
+    <h1>Server Error (500)</h1>
+    <p>Sorry, there's been an error. It's been reported to the site administrators
+    via e-mail and should be fixed shortly. Thanks for your patience.</p>
+  </div>
+
+${commonfooter()}

+ 3 - 3
desktop/core/src/desktop/tests.py

@@ -231,7 +231,7 @@ def test_500_handling():
     c.store_exc_info = store_exc_info
 
     response = c.get('/500_internal_error')
-    assert_equal(response.template.name, '500.html')
+    assert_true('500.mako' in response.template)
     assert_true('should be fixed shortly. Thanks for your patience' in response.content)
     assert_true(exc_msg not in response.content)
 
@@ -251,8 +251,8 @@ def test_404_handling():
   view_name = '/the-view-that-is-not-there'
   c = make_logged_in_client()
   response = c.get(view_name)
-  assert_equal(response.template.name, '404.html')
-  assert_true('Page Not Found' in response.content)
+  assert_true('404.mako' in response.template)
+  assert_true('Not Found' in response.content)
   assert_true(view_name in response.content)
 
 class RecordingHandler(logging.Handler):

+ 2 - 2
desktop/core/src/desktop/views.py

@@ -209,13 +209,13 @@ def index(request):
 def serve_404_error(request, *args, **kwargs):
   """Registered handler for 404. We just return a simple error"""
   access_warn(request, "404 not found")
-  return render_to_response("404.html", dict(uri=request.build_absolute_uri()))
+  return render("404.mako", request, dict(uri=request.build_absolute_uri()))
 
 def serve_500_error(request, *args, **kwargs):
   """Registered handler for 500. We use the debug view to make debugging easier."""
   if desktop.conf.HTTP_500_DEBUG_MODE.get():
     return django.views.debug.technical_500_response(request, *sys.exc_info())
-  return render_to_response("500.html")
+  return render("500.mako", request, {})
 
 _LOG_LEVELS = {
   "critical": logging.CRITICAL,

+ 0 - 108
desktop/core/templates/error.html

@@ -1,108 +0,0 @@
-{% comment %}
-Licensed to Cloudera, Inc. under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  Cloudera, Inc. licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-{% endcomment %}
-{% load is_selected %}
-<!DOCTYPE html>
-<html lang="en">
-<head>
-	<meta charset="utf-8">
-	<title>Error</title>
-	<meta name="viewport" content="width=device-width, initial-scale=1.0">
-	<meta name="description" content="">
-	<meta name="author" content="">
-
-	<link href="/static/ext/css/bootstrap.min.css" rel="stylesheet">
-	<link href="/static/ext/css/bootstrap-responsive.min.css" rel="stylesheet">
-	<link href="/static/css/jhue.css" rel="stylesheet">
-	<link href="/static/ext/css/fileuploader.css" rel="stylesheet">
-
-	<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
-	<!--[if lt IE 9]>
-	<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
-	<![endif]-->
-
-	<style type="text/css">
-		body {
-			padding-top: 60px;
-		}
-	</style>
-
-	<script src="/static/ext/js/jquery/jquery-1.7.1.min.js"></script>
-	<script src="/static/js/Source/jHue/jquery.showusername.js"></script>
-	<script src="/static/js/Source/jHue/jquery.filechooser.js"></script>
-	<script src="/static/js/Source/jHue/jquery.contextmenu.js"></script>
-	<script src="/static/js/Source/jHue/jquery.selector.js"></script>
-	<script src="/static/js/Source/jHue/jquery.alert.js"></script>
-	<script src="/static/ext/js/jquery/plugins/jquery.simpleplaceholder.js"></script>
-	<script src="/static/ext/js/jquery/plugins/jquery.dataTables.1.8.2.min.js"></script>
-	<script src="/static/ext/js/bootstrap.min.js"></script>
-	<script src="/static/ext/js/fileuploader.js"></script>
-
-	<script type="text/javascript" charset="utf-8">
-		$(document).ready(function(){
-			$("#username").showUsername();
-			$("input:text[placeholder]").simplePlaceholder();
-			$(".submitter").keydown(function(e){
-				if (e.keyCode==13){
-					$(this).closest("form").submit();
-				}
-			}).change(function(){
-				$(this).closest("form").submit();
-			});
-			$("#checkConfig").load("/debug/check_config_ajax");
-		});
-	</script>
-</head>
-<body>
-
-	<div class="navbar navbar-fixed-top">
-		<div class="navbar-inner">
-			<div class="container-fluid">
-				<a class="brand" href="#">Hue</a>
-				<div class="nav-collapse">
-					<ul class="nav">
-						<li><a href="/beeswax/">Beeswax</a></li>
-						<li><a href="/filebrowser/">File Browser</a></li>
-						<li><a href="/jobsub/">Job Designer</a></li>
-						<li><a href="/jobbrowser/jobs/">Job Browser</a></li>
-						<li><a href="/useradmin/">User Admin</a></li>
-						<li><a href="/shell/">Shell</a></li>
-						<li><a href="/help/">Help</a></li>
-						<li><a href="/about/">About</a></li>
-						<li class="divider-vertical"></li>
-						<li id="checkConfig"><li>
-					</ul>
-					<p class="navbar-text pull-right">Logged in as <strong><span id="username">xxx</span></strong> - <a href="/accounts/logout/">Sign out</a></p>
-				</div>
-			</div>
-		</div>
-	</div>
-
-
-	<div class="container-fluid">
-		<h1>Error!</h1>
-		<pre>{{ error }}</pre>
-
-		<textarea style="width: 100%;" rows=80 readonly="readonly">
-		{{ traceback }}
-		</textarea>
-
-
-	</div>
-</body>
-</html>
-

+ 31 - 0
desktop/core/templates/error.mako

@@ -0,0 +1,31 @@
+## Licensed to Cloudera, Inc. under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  Cloudera, Inc. licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##     http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+<%!
+from desktop.views import commonheader, commonfooter
+%>
+${commonheader("Error", "")}
+
+  <div class="container-fluid">
+    <h1>Error!</h1>
+    <pre>{{ error }}</pre>
+
+    <textarea style="width: 100%;" rows=80 readonly="readonly">
+    {{ traceback }}
+    </textarea>
+  </div>
+
+${commonfooter()}
+