Explorar o código

HUE-672 [about] Logs page can't handle non-ascii characters

Converting logs to UTF-8 before rendering them.
500 header layout made prettier
Fix missing </li> in common header
Romain Rigaux %!s(int64=13) %!d(string=hai) anos
pai
achega
8139c60bd3

+ 24 - 21
desktop/core/src/desktop/templates/500.html

@@ -37,32 +37,35 @@ limitations under the License.
 		$(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="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>There's been an error. It's been reported to the site administrators
+		<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>

+ 1 - 1
desktop/core/src/desktop/templates/common_header.html

@@ -84,7 +84,7 @@ limitations under the License.
 						<li {% is_selected section "help" %}><a href="/help/">Help</a></li>
 						<li {% is_selected section "about" %}><a href="/about/">About</a></li>
 						<li class="divider-vertical"></li>
-						<li id="checkConfig"><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>

+ 2 - 1
desktop/core/src/desktop/templates/logs.mako

@@ -15,6 +15,7 @@
 ## limitations under the License.
 <%!
 from desktop.lib.conf import BoundConfig
+from desktop.lib.i18n import smart_unicode
 from desktop.views import commonheader, commonfooter
 import re
 %>
@@ -29,7 +30,7 @@ ${layout.menubar(section='log_view')}
 		<% log.reverse() %>
 		<pre>
 		% for l in log:
-${l | h}
+${smart_unicode(l) | h}
 		% endfor
 		</pre>
 

+ 13 - 0
desktop/core/src/desktop/tests.py

@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+# -*- coding: utf-8 -*-
 # Licensed to Cloudera, Inc. under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
@@ -19,6 +20,7 @@ from desktop.lib import django_mako
 from nose.tools import assert_true, assert_equal
 from desktop.lib.django_test_util import make_logged_in_client
 from django.conf.urls.defaults import patterns, url
+from django.core.urlresolvers import reverse
 from django.http import HttpResponse
 from django.db.models import query, CharField, SmallIntegerField
 from desktop.lib.paginator import Paginator
@@ -63,6 +65,17 @@ def teardown_test_environment():
   django_mako.render_to_string = django_mako.render_to_string_normal
 teardown_test_environment.__test__ = False
 
+def test_log_view():
+  c = make_logged_in_client()
+
+  URL = reverse(views.log_view)
+
+  LOG = logging.getLogger(__name__)
+  LOG.warn('une voix m’a réveillé')
+
+  # UnicodeDecodeError: 'ascii' codec can't decode byte... should not happen
+  response = c.get(URL)
+
 def test_dump_config():
   c = make_logged_in_client()
 

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

@@ -48,7 +48,7 @@ def log_view(request):
   l = logging.getLogger()
   for h in l.handlers:
     if isinstance(h, desktop.log.log_buffer.FixedBufferHandler):
-	  return render('logs.mako', request, dict(log=[l for l in h.buf]))
+      return render('logs.mako', request, dict(log=[l for l in h.buf]))
 
   return render('logs.mako', request, dict(log=["No logs found!"]))