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

Implemented support for specifying different endpoint name than the...

Implemented support for specifying different endpoint name than the concatenation of module name and view name.
parent 51f14b36
No related branches found
No related tags found
No related merge requests found
......@@ -118,6 +118,21 @@ class BaseView(flask.views.View):
"""
raise NotImplementedError()
@classmethod
def get_view_endpoint_name(cls):
"""
Return unique name for the view endpoint. Name must be unique in the namespace of
parent blueprint/module and should contain only characters ``[a-z0-9]``.
It will be used for generating endpoint name for the view.
*This method does not have any default implementation and must be overridden
by a subclass.*
:return: Name for the view.
:rtype: str
"""
return cls.get_view_name()
@classmethod
def get_view_endpoint(cls):
"""
......@@ -129,7 +144,10 @@ class BaseView(flask.views.View):
:return: Routing endpoint for the view within the whole application.
:rtype: str
"""
return '{}.{}'.format(cls.module_name, cls.get_view_name())
return '{}.{}'.format(
cls.module_name,
cls.get_view_endpoint_name()
)
@classmethod
def get_view_url(cls, **kwargs):
......@@ -456,7 +474,7 @@ class RenderableView(BaseView): # pylint: disable=locally-disabled,abstract-met
if cls.module_name:
return '{}/{}.html'.format(
cls.module_name,
cls.get_view_name()
cls.get_view_endpoint_name()
)
raise RuntimeError("Unable to guess default view template, because module name was not yet set.")
......@@ -804,10 +822,10 @@ class BaseSearchView(RenderableView, VialUtils):
)
breadcrumbs_menu.add_entry(
'endpoint',
cls.get_view_name(),
cls.get_view_endpoint_name(),
endpoint = '{}.{}'.format(
cls.module_name,
cls.get_view_name()
cls.get_view_endpoint_name()
)
)
return breadcrumbs_menu
......@@ -1084,7 +1102,6 @@ class ItemListView(RenderableView): # pylint: disable=locally-disabled,abstract
Base class for item *list* views. These views provide quick and simple access
to lists of all objects.
"""
@classmethod
def get_view_name(cls):
"""*Implementation* of :py:func:`vial.view.BaseView.get_view_name`."""
......@@ -1104,7 +1121,10 @@ class ItemListView(RenderableView): # pylint: disable=locally-disabled,abstract
action_menu.add_entry(
'endpoint',
'list',
endpoint = '{}.list'.format(cls.module_name)
endpoint = '{}.{}'.format(
cls.module_name,
cls.get_view_endpoint_name()
)
)
return action_menu
......@@ -1171,6 +1191,12 @@ class ItemShowView(RenderableView): # pylint: disable=locally-disabled,abstract
@classmethod
def get_view_url(cls, **kwargs):
"""*Implementation* of :py:func:`vial.view.BaseView.get_view_url`."""
if 'item' not in kwargs or not kwargs['item']:
raise ValueError(
"Missing item parameter for show URL view '{}'". format(
cls.get_view_endpoint()
)
)
return flask.url_for(
cls.get_view_endpoint(),
item_id = kwargs['item'].get_id()
......@@ -1209,13 +1235,19 @@ class ItemShowView(RenderableView): # pylint: disable=locally-disabled,abstract
action_menu.add_entry(
'endpoint',
'list',
endpoint = '{}.list'.format(cls.module_name),
endpoint = '{}.{}'.format(
cls.module_name,
cls.get_view_endpoint_name().replace('show', 'list')
),
paramlist = []
)
action_menu.add_entry(
'endpoint',
'show',
endpoint = '{}.show'.format(cls.module_name)
endpoint = '{}.{}'.format(
cls.module_name,
cls.get_view_endpoint_name()
)
)
return action_menu
......@@ -1486,12 +1518,18 @@ class ItemCreateView(ItemActionView): # pylint: disable=locally-disabled,abstra
breadcrumbs_menu.add_entry(
'endpoint',
'list',
endpoint = '{}.list'.format(cls.module_name)
endpoint = '{}.{}'.format(
cls.module_name,
cls.get_view_endpoint_name().replace('create', 'list')
),
)
breadcrumbs_menu.add_entry(
'endpoint',
'create',
endpoint = '{}.create'.format(cls.module_name)
endpoint = '{}.{}'.format(
cls.module_name,
cls.get_view_endpoint_name()
)
)
return breadcrumbs_menu
......@@ -1977,17 +2015,26 @@ class ItemUpdateView(ItemActionView): # pylint: disable=locally-disabled,abstra
breadcrumbs_menu.add_entry(
'endpoint',
'list',
endpoint = '{}.list'.format(cls.module_name)
endpoint = '{}.{}'.format(
cls.module_name,
cls.get_view_endpoint_name().replace('update', 'list')
)
)
breadcrumbs_menu.add_entry(
'endpoint',
'show',
endpoint = '{}.show'.format(cls.module_name)
endpoint = '{}.{}'.format(
cls.module_name,
cls.get_view_endpoint_name().replace('update', 'show')
)
)
breadcrumbs_menu.add_entry(
'endpoint',
'update',
endpoint = '{}.update'.format(cls.module_name)
endpoint = '{}.{}'.format(
cls.module_name,
cls.get_view_endpoint_name()
)
)
return breadcrumbs_menu
......@@ -2363,7 +2410,7 @@ class ItemObjectRelationView(ItemChangeView): # pylint: disable=locally-disable
:rtype: str
"""
if cls.module_name:
return '{}/{}.html'.format(cls.module_name, cls.get_view_name())
return '{}/{}.html'.format(cls.module_name, cls.get_view_endpoint_name())
raise RuntimeError("Unable to guess default view template, because module name was not yet set.")
@classmethod
......
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