diff --git a/dashboard/templates/404.html b/dashboard/templates/404.html index f90525863..f85c4ea8f 100644 --- a/dashboard/templates/404.html +++ b/dashboard/templates/404.html @@ -1,5 +1,3 @@ -{% extends "base.html" %} - {% block head %} {% endblock %} @@ -8,8 +6,7 @@

404 Not Found

-
The requested page is not found. The page will be automatically redirected to Overview +
The requested page is not found. The page will be automatically redirected to Main
- {% endblock %} diff --git a/dashboard/templates/layout.html b/dashboard/templates/layout.html index f676b836e..6fa974a49 100644 --- a/dashboard/templates/layout.html +++ b/dashboard/templates/layout.html @@ -4,7 +4,14 @@ -Stackalytics +Stackalytics {% if page_title %}| {{ page_title }} {% endif %} + +{% if not page_title %} + +{% else %} + +{% endif %} + diff --git a/dashboard/web.py b/dashboard/web.py index 257e61a3e..43a2b4c84 100644 --- a/dashboard/web.py +++ b/dashboard/web.py @@ -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 diff --git a/tests/unit/test_web_utils.py b/tests/unit/test_web_utils.py index 75c7976c1..f9b005b28 100644 --- a/tests/unit/test_web_utils.py +++ b/tests/unit/test_web_utils.py @@ -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'))