瀏覽代碼

[ui] Convert common_header to mako

* Removed (now) unused templatetags
bc Wong 13 年之前
父節點
當前提交
02e83253f5

+ 0 - 114
desktop/core/src/desktop/templates/common_header.html

@@ -1,114 +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>{{title}}</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: {{padding}};
-		}
-        .tooltip.fade.bottom{
-            border-style: none;
-            background-color: transparent;
-        }
-        .tooltip{
-            margin-left: -10px;
-            margin-top: -10px;
-        }
-        .tooltip-inner{
-            margin-top: -10px;
-        }
-	</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/bootstrap-tooltip.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");
-		});
-
-        function showTooltip(appName, niceName){
-            $('#' + appName + "Icon").tooltip({title:niceName, placement:'bottom'})
-            $('#' + appName + "Icon").tooltip('show')
-        }
-
-
-	</script>
-</head>
-<body>
-
-<div class="navbar navbar-fixed-top">
-		<div class="navbar-inner">
-			<div class="container-fluid">
-				<a class="brand" href="/about">Hue</a>
-				<div class="nav-collapse">
-					<ul class="nav">
-						{% for app in apps %}
-							{%if app.icon_path%}
-							<li id="{{app.display_name}}Icon" {% is_selected section app.display_name %}>
-								<a href="/{{app.display_name}}"><img width="25" height="25" 
-									onmouseover="showTooltip('{{app.display_name}}', '{{app.nice_name}}')"
-									src="{{app.icon_path}}"/></a></li>
-							{%endif%}
-						{% endfor %}
-						<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>
-
-

+ 114 - 0
desktop/core/src/desktop/templates/common_header.mako

@@ -0,0 +1,114 @@
+## 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.
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="utf-8">
+  <title>${title}</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: ${padding};
+    }
+    .tooltip.fade.bottom{
+        border-style: none;
+        background-color: transparent;
+    }
+    .tooltip{
+        margin-left: -10px;
+        margin-top: -10px;
+    }
+    .tooltip-inner{
+        margin-top: -10px;
+    }
+  </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/bootstrap-tooltip.js"></script>
+  <script src="/static/ext/js/fileuploader.js"></script>
+
+  <script type="text/javascript" charset="utf-8">
+    $(document).ready(function(){
+      $(".navbar .nav-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");
+      $(".navbar .nav-tooltip").tooltip({
+        delay:0,
+        placement:'bottom'});
+    });
+  </script>
+</head>
+<body>
+
+
+<%def name="is_selected(section, matcher)">
+  %if section == matcher:
+    class="active"
+  %endif
+</%def>
+
+<div class="navbar navbar-fixed-top">
+    <div class="navbar-inner">
+      <div class="container-fluid">
+        <a class="brand nav-tooltip" title="About Hue" href="/about">Hue</a>
+        <div class="nav-collapse">
+          <ul class="nav">
+            %for app in apps:
+              %if app.icon_path:
+              <li id="${app.display_name}Icon" ${is_selected(section, app.display_name)}>
+                <a class="nav-tooltip" title="${app.nice_name}"
+                  href="/${app.display_name}"><img width="25" height="25"
+                  src="${app.icon_path}"/></a></li>
+              %endif
+            %endfor
+            <li class="divider-vertical"></li>
+            <li id="checkConfig"></li>
+          </ul>
+          <p class="navbar-text pull-right">Logged in as <strong><span class="nav-username">&nbsp;</span></strong> - <a href="/accounts/logout/">Sign out</a></p>
+        </div>
+      </div>
+    </div>
+  </div>
+
+

+ 1 - 2
desktop/core/src/desktop/templates/common_header_iframe.html

@@ -15,7 +15,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 See the License for the specific language governing permissions and
 limitations under the License.
 limitations under the License.
 {% endcomment %}
 {% endcomment %}
-{% load is_selected %}
 <!DOCTYPE html>
 <!DOCTYPE html>
 <html lang="en">
 <html lang="en">
 <head>
 <head>
@@ -47,4 +46,4 @@ limitations under the License.
 	<script src="/static/ext/js/bootstrap.min.js"></script>
 	<script src="/static/ext/js/bootstrap.min.js"></script>
 	<script src="/static/ext/js/fileuploader.js"></script>
 	<script src="/static/ext/js/fileuploader.js"></script>
 </head>
 </head>
-<body>
+<body>

+ 6 - 4
desktop/core/templates/error.mako → desktop/core/src/desktop/templates/error.mako

@@ -20,11 +20,13 @@ ${commonheader("Error", "")}
 
 
   <div class="container-fluid">
   <div class="container-fluid">
     <h1>Error!</h1>
     <h1>Error!</h1>
-    <pre>{{ error }}</pre>
+    <pre>${error | h }</pre>
 
 
-    <textarea style="width: 100%;" rows=80 readonly="readonly">
-    {{ traceback }}
-    </textarea>
+    %if traceback:
+      <textarea style="width: 100%;" rows=80 readonly="readonly">
+      ${traceback | h}
+      </textarea>
+    %endif
   </div>
   </div>
 
 
 ${commonfooter()}
 ${commonfooter()}

+ 0 - 0
desktop/core/src/desktop/templatetags/__init__.py


+ 0 - 27
desktop/core/src/desktop/templatetags/is_selected.py

@@ -1,27 +0,0 @@
-#!/usr/bin/env python
-# 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.
-import django
-
-register = django.template.Library()
-
-@register.simple_tag
-def is_selected(section, matcher):
-  if section == matcher:
-    return 'class="active"'
-  else:
-    return ''
-is_selected.is_safe = True

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

@@ -28,6 +28,7 @@ from django.http import HttpResponse
 from django.core.servers.basehttp import FileWrapper
 from django.core.servers.basehttp import FileWrapper
 import django.views.debug
 import django.views.debug
 
 
+from desktop.lib import django_mako
 from desktop.lib.django_util import login_notrequired, render_json, render, render_to_string
 from desktop.lib.django_util import login_notrequired, render_json, render, render_to_string
 from desktop.lib.paths import get_desktop_root
 from desktop.lib.paths import get_desktop_root
 from desktop.log.access import access_log_level, access_warn
 from desktop.log.access import access_log_level, access_warn
@@ -266,7 +267,7 @@ def commonheader(title, section, padding="60px"):
   """
   """
   apps_list = sorted(appmanager.DESKTOP_APPS[:], key=lambda app: app.menu_index)
   apps_list = sorted(appmanager.DESKTOP_APPS[:], key=lambda app: app.menu_index)
 
 
-  return render_to_string("common_header.html", dict(
+  return django_mako.render_to_string("common_header.mako", dict(
     apps=apps_list,
     apps=apps_list,
     title=title,
     title=title,
     section=section,
     section=section,