فهرست منبع

[desktop] Header configuration

Configuration added to hue.ini and pseudo-distributed.ini.tmpl.
New configuration, custom.banner_top_html, is picked up by conf.py in desktop app.
common_header.mako was updated to extract HTML from custom.banner_top_html config.
login.mako, which isn't using the common header, was updated to extra HMTML from custom.banner_top_html config.
abec 13 سال پیش
والد
کامیت
7f0bca6

+ 7 - 0
desktop/conf.dist/hue.ini

@@ -58,6 +58,13 @@
   # Default encoding for site data
   ## default_site_encoding=utf-8
 
+  # UI customizations
+  # -------------------
+  [[custom]]
+
+  # Top banner HTML code
+  ## banner_top_html=
+
   # Configuration options for user authentication into the web application
   # ------------------------------------------------------------------------
   [[auth]]

+ 7 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -67,6 +67,13 @@
   # Default encoding for site data
   ## default_site_encoding=utf-8
 
+  # UI customizations
+  # -------------------
+  [[custom]]
+
+  # Top banner HTML code
+  ## banner_top_html=
+
   # Configuration options for user authentication into the web application
   # ------------------------------------------------------------------------
   [[auth]]

+ 11 - 0
desktop/core/src/desktop/conf.py

@@ -244,6 +244,17 @@ SERVER_GROUP = Config(
   default="hue")
 
 
+CUSTOM = ConfigSection(
+  key="custom",
+  help=_("Customizations to the UI."),
+  members=dict(
+    BANNER_TOP_HTML=Config("banner_top_html",
+                   default="",
+                   help=_("Top banner HTML code. This code will be placed in the navigation bar "
+                        "so that it will reside at the top of the page in a fixed position. " +
+                        "One common value is `<img src=\"http://www.example.com/example.gif\" />`")),
+))
+
 AUTH = ConfigSection(
   key="auth",
   help=_("Configuration options for user authentication into the web application."),

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

@@ -14,6 +14,7 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 <%!
+from desktop import conf
 from desktop.lib.i18n import smart_unicode
 from django.utils.translation import ugettext as _
 %>
@@ -88,6 +89,11 @@ from django.utils.translation import ugettext as _
 </%def>
 
 <div class="navbar navbar-fixed-top">
+    % if conf.CUSTOM.BANNER_TOP_HTML.get():
+    <div id="banner-top" class="banner">
+        ${conf.CUSTOM.BANNER_TOP_HTML.get()}
+    </div>
+    % endif
     <div class="navbar-inner">
       <div class="container-fluid">
         <a class="brand nav-tooltip" title="${_('About Hue')}" href="/about">Hue</a>

+ 11 - 5
desktop/core/src/desktop/templates/login.mako

@@ -1,12 +1,12 @@
 ## Licensed to Cloudera, Inc. under one
-## or more contributor license agreements.  See the NOTICE file
+## 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
+##	   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,
@@ -14,6 +14,7 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 <%!
+from desktop import conf
 from django.utils.translation import ugettext as _
 %>
 <!DOCTYPE html>
@@ -42,6 +43,11 @@ from django.utils.translation import ugettext as _
 
 <body>
 	<div class="navbar navbar-fixed-top">
+		% if conf.CUSTOM.BANNER_TOP_HTML.get():
+		<div id="banner-top" class="banner">
+			${conf.CUSTOM.BANNER_TOP_HTML.get()}
+		</div>
+		% endif
 		<div class="navbar-inner">
 			<div class="container-fluid">
 				<a class="brand" href="#">Hue</a>
@@ -52,7 +58,7 @@ from django.utils.translation import ugettext as _
 	<div class="container">
 		<div class="row">
 			<div class="span4 offset4">
-    			<form method="POST" action="${action}" class="well">
+				<form method="POST" action="${action}" class="well">
 					<label>${_('Username')}
 						<input name="username" class="input-large" type="text" maxlength="30">
 					</label>
@@ -65,7 +71,7 @@ from django.utils.translation import ugettext as _
 					%else:
 						<input type="submit" class="btn primary" value="${_('Sign in')}" />
 					%endif
-		    		<input type="hidden" name="next" value="${next}" />
+					<input type="hidden" name="next" value="${next}" />
 
 					%if login_errors==True:
 						<br/>
@@ -83,7 +89,7 @@ from django.utils.translation import ugettext as _
 			<div class="span6 offset3">
 				<div class="alert alert-block">
 					<p>${_('Since this is your first time logging in, please pick any username and password. Be sure to remember these, as')}
-				     <strong>${_('they will become your superuser credentials for Hue')}</strong>.</p>
+					 <strong>${_('they will become your superuser credentials for Hue')}</strong>.</p>
 				</div>
 			</div>
 		</div>

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

@@ -355,3 +355,18 @@ def test_last_access_time():
   # Check that 'last_access_time' is in between the timestamps before and after the last access path
   assert_true(before_access_time < access_time)
   assert_true(access_time < after_access_time)
+
+
+def test_ui_customizations():
+  custom_banner = 'test ui customization'
+  reset = (
+    desktop.conf.CUSTOM.BANNER_TOP_HTML.set_for_testing(custom_banner),
+  )
+
+  try:
+    c = make_logged_in_client()
+    resp = c.get('/debug/check_config')
+    assert_true(custom_banner in resp.content)
+  finally:
+    for old_conf in reset:
+      old_conf()