Added page title and description meta header

Partially fixes bug 1215919

Change-Id: Id1ddf10ed216422c8052ec42c5ecba67c19bb000
This commit is contained in:
Ilya Shakhat 2013-08-23 17:59:47 +04:00
parent 5e7f9a7b9a
commit e4cfd89959
4 changed files with 57 additions and 5 deletions

View File

@ -1,5 +1,3 @@
{% extends "base.html" %}
{% block head %}
<meta http-equiv="refresh" content="5; url=/">
{% endblock %}
@ -8,8 +6,7 @@
<h2>404 Not Found</h2>
<div>The requested page is not found. The page will be automatically redirected to <a href="/">Overview</a>
<div>The requested page is not found. The page will be automatically redirected to <a href="/">Main</a>
</div>
{% endblock %}

View File

@ -4,7 +4,14 @@
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Stackalytics</title>
<title>Stackalytics {% if page_title %}| {{ page_title }} {% endif %}</title>
{% if not page_title %}
<meta name="description" content="OpenStack contribution dashboard collects and processes development activity data such as commits, lines of code changed, and code reviews"/>
{% else %}
<meta name="description" content="Full commits and review statistics of {{ page_title }}"/>
{% endif %}
<meta name="keywords" content="openstack, contribution, community, review, commit, {{ company }}"/>
<link href='http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic&subset=latin,cyrillic' rel='stylesheet' type='text/css' />
<link href='http://fonts.googleapis.com/css?family=PT+Sans+Caption&subset=latin,cyrillic' rel='stylesheet' type='text/css' />

View File

@ -380,6 +380,29 @@ def exception_handler():
return decorator
def make_page_title(company, user_id, module, release):
if company:
memory_storage = get_vault()['memory_storage']
company = memory_storage.get_original_company_name(company)
if company or user_id:
if user_id:
s = get_user_from_runtime_storage(user_id)['user_name']
if company:
s += ' (%s)' % company
else:
s = company
else:
s = 'OpenStack community'
s += ' contribution'
if module:
s += ' to %s' % module
if release != 'all':
s += ' in %s release' % release.capitalize()
else:
s += ' in all releases'
return s
def templated(template=None, return_code=200):
def decorator(f):
@functools.wraps(f)
@ -425,6 +448,8 @@ def templated(template=None, return_code=200):
ctx['company'] = get_single_parameter(kwargs, 'company')
ctx['module'] = get_single_parameter(kwargs, 'module')
ctx['user_id'] = get_single_parameter(kwargs, 'user_id')
ctx['page_title'] = make_page_title(ctx['company'], ctx['user_id'],
ctx['module'], ctx['release'])
return flask.render_template(template_name, **ctx), return_code

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
import testtools
from dashboard import web
@ -85,3 +86,25 @@ Implements Blueprint ''' + (
expected = 'Lorem ipsum. Dolor sit amet.\n Lorem\n ipsum.\ndolor!'
self.assertEqual(expected, web.unwrap_text(original))
@mock.patch('dashboard.web.get_vault')
@mock.patch('dashboard.web.get_user_from_runtime_storage')
def test_make_page_title(self, user_patch, vault_patch):
memory_storage_mock = mock.Mock()
memory_storage_mock.get_original_company_name = mock.Mock(
return_value='Mirantis'
)
vault_patch.return_value = {'memory_storage': memory_storage_mock}
user_patch.return_value = {'user_name': 'John Doe'}
self.assertEqual('OpenStack community contribution in all releases',
web.make_page_title('', '', '', 'all'))
self.assertEqual('OpenStack community contribution in Havana release',
web.make_page_title('', '', '', 'Havana'))
self.assertEqual('Mirantis contribution in Havana release',
web.make_page_title('Mirantis', '', '', 'Havana'))
self.assertEqual('John Doe contribution in Havana release',
web.make_page_title('', 'john_doe', '', 'Havana'))
self.assertEqual(
'John Doe (Mirantis) contribution to neutron in Havana release',
web.make_page_title('Mirantis', 'John Doe', 'neutron', 'Havana'))