Skip to content
Snippets Groups Projects
Commit 14be3783 authored by Jan Mach's avatar Jan Mach
Browse files

Moved the built-in index page into separate pluggable module.

To be more consistent with the rest of the system this patch moves the built-in index page to separate pluggable module. There is still room for improvement by using Jinja2 macro for rendering breadcrumb navigation. Currently it is used only within part of the system. (Redmine issue: #4220,#3443)
parent 80b313b0
No related branches found
No related tags found
No related merge requests found
Showing
with 64 additions and 62 deletions
......@@ -416,13 +416,6 @@ def _setup_app_core(app):
app.json_encoder = HawatJSONEncoder
@app.route('/')
def index(): # pylint: disable=locally-disabled,unused-variable
"""
Default route for index page.
"""
return flask.render_template('index.html')
@app.route('/hawat-main.js')
def mainjs(): # pylint: disable=locally-disabled,unused-variable
"""
......@@ -681,7 +674,9 @@ def _setup_app_babel(app):
# Redirect user back to original page.
return flask.redirect(
hawat.forms.get_redirect_target(
default_url = flask.url_for('index')
default_url = flask.url_for(
flask.current_app.config['HAWAT_ENDPOINT_HOME']
)
)
)
......
......@@ -87,7 +87,6 @@ class HawatAppException(Exception):
"""
Custom class for Hawat application exceptions.
"""
pass
class URLParamsBuilder:
......@@ -641,6 +640,12 @@ class PsycopgViewMixin:
@staticmethod
def get_db():
"""
Get database connection service.
:return: database connection service.
:rtype: mentat.services.eventstorage.EventStorageService
"""
return hawat.events.db_get()
@staticmethod
......@@ -1058,7 +1063,6 @@ class HawatRenderableView(HawatBaseView): # pylint: disable=locally-disabled,ab
:param kwargs: Custom additional arguments.
"""
pass
def generate_response(self):
"""
......@@ -1213,10 +1217,9 @@ class HawatSearchView(HawatRenderableView, HawatUtils):
"""
breadcrumbs_menu = hawat.menu.HawatMenu()
breadcrumbs_menu.add_entry(
'link',
'index',
link = flask.url_for('index'),
title = gettext('Home')
'endpoint',
'home',
endpoint = flask.current_app.config['HAWAT_ENDPOINT_HOME']
)
breadcrumbs_menu.add_entry(
'endpoint',
......@@ -1252,13 +1255,11 @@ class HawatSearchView(HawatRenderableView, HawatUtils):
"""
This hook method will be called before search attempt.
"""
pass
def do_after_search(self, items): # pylint: disable=locally-disabled,no-self-use,unused-argument
"""
This hook method will be called after successfull search.
"""
pass
def dispatch_request(self): # pylint: disable=locally-disabled,arguments-differ
"""
......@@ -1376,10 +1377,9 @@ class HawatItemListView(HawatRenderableView): # pylint: disable=locally-disable
"""
action_menu = hawat.menu.HawatMenu()
action_menu.add_entry(
'link',
'index',
link = flask.url_for('index'),
title = gettext('Home')
'endpoint',
'home',
endpoint = flask.current_app.config['HAWAT_ENDPOINT_HOME']
)
action_menu.add_entry(
'endpoint',
......@@ -1482,10 +1482,9 @@ class HawatItemShowView(HawatRenderableView): # pylint: disable=locally-disable
"""
action_menu = hawat.menu.HawatMenu()
action_menu.add_entry(
'link',
'index',
link = flask.url_for('index'),
title = gettext('Home')
'endpoint',
'home',
endpoint = flask.current_app.config['HAWAT_ENDPOINT_HOME']
)
action_menu.add_entry(
'endpoint',
......@@ -1540,21 +1539,28 @@ class HawatItemActionView(HawatRenderableView): # pylint: disable=locally-disab
"""
*Interface implementation* of :py:func:`hawat.base.HawatBaseView.get_menu_icon`.
"""
return 'action-{}'.format(cls.get_view_name().replace('_', '-'))
return 'action-{}'.format(
cls.get_view_name().replace('_', '-')
)
@classmethod
def get_menu_link(cls, item = None):
"""
*Interface implementation* of :py:func:`hawat.base.HawatBaseView.get_menu_link`.
"""
return flask.url_for(cls.get_view_endpoint(), item_id = item.get_id())
return flask.url_for(
cls.get_view_endpoint(),
item_id = item.get_id()
)
@classmethod
def get_view_template(cls):
"""
*Interface implementation* of :py:func:`hawat.base.HawatRenderableView.get_view_template`.
"""
return 'form_{}.html'.format(cls.get_view_name().replace('-', '_'))
return 'form_{}.html'.format(
cls.get_view_name().replace('-', '_')
)
@staticmethod
def get_message_success(**kwargs):
......@@ -1590,9 +1596,13 @@ class HawatItemActionView(HawatRenderableView): # pylint: disable=locally-disab
somewhere in this method.
"""
try:
return flask.url_for('{}.{}'.format(self.module_name, 'list'))
return flask.url_for(
'{}.{}'.format(self.module_name, 'list')
)
except werkzeug.routing.BuildError:
return flask.url_for('index')
return flask.url_for(
flask.current_app.config['HAWAT_ENDPOINT_HOME']
)
def check_action_cancel(self, form, **kwargs):
"""
......
......@@ -5,7 +5,7 @@
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<li><a href="{{ url_for('index') }}">{{ gettext('Home') }}</a></li>
<li><a href="{{ url_for('home.index') }}">{{ gettext('Home') }}</a></li>
<li class="active">{{ gettext('Register user account') }}</li>
</ol>
<hr>
......
......@@ -198,10 +198,9 @@ class ShowView(HTMLViewMixin, SQLAlchemyViewMixin, HawatItemShowView):
"""
action_menu = hawat.menu.HawatMenu()
action_menu.add_entry(
'link',
'index',
link = flask.url_for('index'),
title = gettext('Home')
'endpoint',
'home',
endpoint = flask.current_app.config['HAWAT_ENDPOINT_HOME']
)
action_menu.add_entry(
'endpoint',
......
......@@ -5,7 +5,7 @@
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<li><a href="{{ url_for('index') }}">{{ _('Home') }}</a></li>
<li><a href="{{ url_for('home.index') }}">{{ _('Home') }}</a></li>
<li class="active">{{ _('Database status') }}</li>
</ol>
<h2>{{ hawat_current_view.get_view_title() }}</h2>
......
......@@ -212,7 +212,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{{ url_for('index') }}">
<a class="navbar-brand" href="{{ url_for(config['HAWAT_ENDPOINT_HOME']) }}">
<img src="{{ url_for('design.static', filename='images/app-logo-mini.png') }}" class="mentat-logo-mini" alt="Mentat logo">
Mentat
</a>
......
......@@ -12,7 +12,7 @@
</p>
<hr>
<p class="text-center">
{{ _('It seems you have done something naughty, perhaps <a href="%(link)s">go somewhere nice</a> instead.', link = url_for('index')) | safe }}
{{ _('It seems you have done something naughty, perhaps <a href="%(link)s">go somewhere nice</a> instead.', link = url_for(config['HAWAT_ENDPOINT_HOME'])) | safe }}
</p>
</div>
</div>
......
......@@ -12,7 +12,7 @@
</p>
<hr>
<p class="text-center">
{{ _('It seems you do not have sufficient permissions to access this resource, perhaps <a href="%(link)s">go somewhere nice</a> instead.', link = url_for('index')) | safe }}
{{ _('It seems you do not have sufficient permissions to access this resource, perhaps <a href="%(link)s">go somewhere nice</a> instead.', link = url_for(config['HAWAT_ENDPOINT_HOME'])) | safe }}
</p>
</div>
</div>
......
......@@ -12,7 +12,7 @@
</p>
<hr>
<p class="text-center">
{{ _('What you were looking for is just not there, perhaps <a href="%(link)s">go somewhere nice</a> instead.', link = url_for('index')) | safe }}
{{ _('What you were looking for is just not there, perhaps <a href="%(link)s">go somewhere nice</a> instead.', link = url_for(config['HAWAT_ENDPOINT_HOME'])) | safe }}
</p>
</div>
</div>
......
......@@ -12,7 +12,7 @@
</p>
<hr>
<p class="text-center">
{{ _('What you were looking for is just not there anymore, perhaps <a href="%(link)s">go somewhere nice</a> instead.', link = url_for('index')) | safe }}
{{ _('What you were looking for is just not there anymore, perhaps <a href="%(link)s">go somewhere nice</a> instead.', link = url_for(config['HAWAT_ENDPOINT_HOME'])) | safe }}
</p>
</div>
</div>
......
......@@ -12,7 +12,7 @@
</p>
<hr>
<p class="text-center">
{{ _('We are sorry, but something went terribly wrong. Please try again later.') }}
{{ _('We are sorry, but something went terribly wrong. Please try again later, or perhaps <a href="%(link)s">go somewhere nice</a> instead.', link = url_for(config['HAWAT_ENDPOINT_HOME'])) | safe }}
</p>
</div>
</div>
......
......@@ -640,10 +640,9 @@ class SearchView(HTMLViewMixin, AbstractSearchView): # pylint: disable=locally-
"""
breadcrumbs_menu = hawat.menu.HawatMenu()
breadcrumbs_menu.add_entry(
'link',
'index',
link = flask.url_for('index'),
title = gettext('Home')
'endpoint',
'home',
endpoint = flask.current_app.config['HAWAT_ENDPOINT_HOME']
)
breadcrumbs_menu.add_entry(
'endpoint',
......
......@@ -6,7 +6,7 @@
<div class="col-lg-12">
<ol class="breadcrumb">
<li><a href="{{ url_for('index') }}">{{ gettext('Home') }}</a></li>
<li><a href="{{ url_for('home.index') }}">{{ gettext('Home') }}</a></li>
<li><a href="{{ url_for('events.search') }}">{{ gettext('Event database') }}</a></li>
<li class="active">{{ gettext('Event detail') }}</li>
</ol>
......
......@@ -873,10 +873,9 @@ class PlaygroundView(HTMLViewMixin, HawatRenderableView):
"""
breadcrumbs_menu = hawat.menu.HawatMenu()
breadcrumbs_menu.add_entry(
'link',
'index',
link = flask.url_for('index'),
title = gettext('Home')
'endpoint',
'home',
endpoint = flask.current_app.config['HAWAT_ENDPOINT_HOME']
)
breadcrumbs_menu.add_entry(
'endpoint',
......
......@@ -5,7 +5,7 @@
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<li><a href="{{ url_for('index') }}">{{ gettext('Home') }}</a></li>
<li><a href="{{ url_for('home.index') }}">{{ gettext('Home') }}</a></li>
<li><a href="{{ url_for('filters.list') }}">{{ gettext('Filter management') }}</a></li>
{%- if item_action == 'update' %}
<li><a href="{{ url_for('filters.show', item_id = item.id) }}">{{ gettext('Filter detail') }}</a></li>
......
......@@ -114,8 +114,8 @@
{{ macros_site.render_raw_var('form_data', form_data) }}
{{ macros_site.render_raw_var('event', event) }}
{{ macros_site.render_raw_var('filter_tree', filter_tree) }}
{{ macros_site.render_raw_var('filter_preview', filter_preview) }}
{{ macros_site.render_raw_var('filter_compiled', filter_compiled) }}
{{ macros_site.render_raw_var('filter_preview', filter_preview) }}
{{ macros_site.render_raw_var('filter_compiled_preview', filter_compiled_preview) }}
{{ macros_site.render_raw_var('filter_result', filter_result) }}
{%- endif %}
......
......@@ -4,8 +4,9 @@
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<li><a href="{{ url_for('index') }}">{{ gettext('Home') }}</a></li>
<li><a href="{{ url_for('home.index') }}">{{ gettext('Home') }}</a></li>
<li><a href="{{ url_for('groups.list') }}">{{ gettext('Group management') }}</a></li>
{%- if item_action == 'update' %}
<li><a href="{{ url_for('groups.show', item_id = item.id) }}">{{ gettext('Group detail') }}</a></li>
......@@ -64,6 +65,9 @@
</div> <!-- /.well -->
</div> <!-- /.col-lg-12 -->
</div> <!-- /.row -->
{%- if permission_can('developer') %}
{%- if item %}
......@@ -74,7 +78,4 @@
{%- endif %}
{%- endif %}
</div> <!-- /.col-lg-12 -->
</div> <!-- /.row -->
{%- endblock content %}
......@@ -5,7 +5,7 @@
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<li><a href="{{ url_for('index') }}">{{ gettext('Home') }}</a></li>
<li><a href="{{ url_for('home.index') }}">{{ gettext('Home') }}</a></li>
<li><a href="{{ url_for('networks.list') }}">{{ gettext('Network management') }}</a></li>
{%- if item_action == 'update' %}
<li><a href="{{ url_for('networks.show', item_id = item.id) }}">{{ gettext('Network detail') }}</a></li>
......
......@@ -228,10 +228,9 @@ class ShowView(HTMLViewMixin, SQLAlchemyViewMixin, HawatItemShowView):
"""
action_menu = hawat.menu.HawatMenu()
action_menu.add_entry(
'link',
'index',
link = flask.url_for('index'),
title = gettext('Home')
'endpoint',
'home',
endpoint = flask.current_app.config['HAWAT_ENDPOINT_HOME']
)
action_menu.add_entry(
'endpoint',
......
......@@ -7,7 +7,7 @@
{%- if not unauth %}
<ol class="breadcrumb">
<li><a href="{{ url_for('index') }}">{{ gettext('Home') }}</a></li>
<li><a href="{{ url_for('home.index') }}">{{ gettext('Home') }}</a></li>
<li><a href="{{ url_for('reports.search') }}">{{ gettext('Reports') }}</a></li>
<li class="active">{{ gettext('Report detail') }}</li>
</ol>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment