Add dedicated view config methods for "view" and "edit help"
so they can be invoked explicitly from elsewhere, keeping same logic cf. Catapult Worksheets
This commit is contained in:
parent
ac57ddbb16
commit
7b2faf90f2
|
@ -4906,21 +4906,7 @@ class MasterView(View):
|
||||||
default=True)
|
default=True)
|
||||||
|
|
||||||
# edit help info
|
# edit help info
|
||||||
config.add_tailbone_permission(permission_prefix,
|
cls._defaults_edit_help(config)
|
||||||
'{}.edit_help'.format(permission_prefix),
|
|
||||||
"Edit help info for {}".format(model_title_plural))
|
|
||||||
config.add_route('{}.edit_help'.format(route_prefix),
|
|
||||||
'{}/edit-help'.format(url_prefix),
|
|
||||||
request_method='POST')
|
|
||||||
config.add_view(cls, attr='edit_help',
|
|
||||||
route_name='{}.edit_help'.format(route_prefix),
|
|
||||||
renderer='json')
|
|
||||||
config.add_route('{}.edit_field_help'.format(route_prefix),
|
|
||||||
'{}/edit-field-help'.format(url_prefix),
|
|
||||||
request_method='POST')
|
|
||||||
config.add_view(cls, attr='edit_field_help',
|
|
||||||
route_name='{}.edit_field_help'.format(route_prefix),
|
|
||||||
renderer='json')
|
|
||||||
|
|
||||||
# list/search
|
# list/search
|
||||||
if cls.listable:
|
if cls.listable:
|
||||||
|
@ -5096,37 +5082,7 @@ class MasterView(View):
|
||||||
|
|
||||||
# view
|
# view
|
||||||
if cls.viewable:
|
if cls.viewable:
|
||||||
config.add_tailbone_permission(permission_prefix, '{}.view'.format(permission_prefix),
|
cls._defaults_view(config)
|
||||||
"View details for {}".format(model_title))
|
|
||||||
if cls.has_pk_fields:
|
|
||||||
config.add_tailbone_permission(permission_prefix, '{}.view_pk_fields'.format(permission_prefix),
|
|
||||||
"View all PK-type fields for {}".format(model_title_plural))
|
|
||||||
if cls.secure_global_objects:
|
|
||||||
config.add_tailbone_permission(permission_prefix, '{}.view_global'.format(permission_prefix),
|
|
||||||
"View *global* {}".format(model_title_plural))
|
|
||||||
|
|
||||||
# view by grid index
|
|
||||||
config.add_route('{}.view_index'.format(route_prefix), '{}/view'.format(url_prefix))
|
|
||||||
config.add_view(cls, attr='view_index', route_name='{}.view_index'.format(route_prefix),
|
|
||||||
permission='{}.view'.format(permission_prefix))
|
|
||||||
|
|
||||||
# view by record key
|
|
||||||
config.add_route('{}.view'.format(route_prefix), instance_url_prefix)
|
|
||||||
kwargs = {'http_cache': 0} if prevent_cache and cls.has_rows else {}
|
|
||||||
config.add_view(cls, attr='view', route_name='{}.view'.format(route_prefix),
|
|
||||||
permission='{}.view'.format(permission_prefix),
|
|
||||||
**kwargs)
|
|
||||||
|
|
||||||
# version history
|
|
||||||
if cls.has_versions and rattail_config and rattail_config.versioning_enabled():
|
|
||||||
config.add_tailbone_permission(permission_prefix, '{}.versions'.format(permission_prefix),
|
|
||||||
"View version history for {}".format(model_title))
|
|
||||||
config.add_route('{}.versions'.format(route_prefix), '{}/versions/'.format(instance_url_prefix))
|
|
||||||
config.add_view(cls, attr='versions', route_name='{}.versions'.format(route_prefix),
|
|
||||||
permission='{}.versions'.format(permission_prefix))
|
|
||||||
config.add_route('{}.version'.format(route_prefix), '{}/versions/{{txnid}}'.format(instance_url_prefix))
|
|
||||||
config.add_view(cls, attr='view_version', route_name='{}.version'.format(route_prefix),
|
|
||||||
permission='{}.versions'.format(permission_prefix))
|
|
||||||
|
|
||||||
# image
|
# image
|
||||||
if cls.has_image:
|
if cls.has_image:
|
||||||
|
@ -5272,6 +5228,110 @@ class MasterView(View):
|
||||||
config.add_view(cls, attr='delete_row', route_name='{}.delete_row'.format(route_prefix),
|
config.add_view(cls, attr='delete_row', route_name='{}.delete_row'.format(route_prefix),
|
||||||
permission='{}.delete_row'.format(permission_prefix))
|
permission='{}.delete_row'.format(permission_prefix))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _defaults_view(cls, config, **kwargs):
|
||||||
|
"""
|
||||||
|
Provide default "view" configuration, i.e. for "viewable" things.
|
||||||
|
"""
|
||||||
|
rattail_config = config.registry.settings.get('rattail_config')
|
||||||
|
route_prefix = cls.get_route_prefix()
|
||||||
|
url_prefix = cls.get_url_prefix()
|
||||||
|
instance_url_prefix = cls.get_instance_url_prefix()
|
||||||
|
model_title = cls.get_model_title()
|
||||||
|
model_title_plural = cls.get_model_title_plural()
|
||||||
|
|
||||||
|
# on windows/chrome we are seeing some caching when e.g. user
|
||||||
|
# applies some filters, then views a record, then clicks back
|
||||||
|
# button, filters no longer are applied. so by default we
|
||||||
|
# instruct browser to never cache certain pages which contain
|
||||||
|
# a grid. at this point only /index and /view
|
||||||
|
# cf. https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/viewconfig.html#non-predicate-arguments
|
||||||
|
prevent_cache = rattail_config.getbool('tailbone',
|
||||||
|
'prevent_cache_for_index_views',
|
||||||
|
default=True)
|
||||||
|
|
||||||
|
# nb. if caller specifies permission prefix, it's assumed they
|
||||||
|
# have registered it elsewhere
|
||||||
|
if 'permission_prefix' in kwargs:
|
||||||
|
permission_prefix = kwargs['permission_prefix']
|
||||||
|
else:
|
||||||
|
permission_prefix = cls.get_permission_prefix()
|
||||||
|
config.add_tailbone_permission(permission_prefix,
|
||||||
|
'{}.view'.format(permission_prefix),
|
||||||
|
"View details for {}".format(model_title))
|
||||||
|
|
||||||
|
if cls.has_pk_fields:
|
||||||
|
config.add_tailbone_permission(permission_prefix,
|
||||||
|
'{}.view_pk_fields'.format(permission_prefix),
|
||||||
|
"View all PK-type fields for {}".format(model_title_plural))
|
||||||
|
if cls.secure_global_objects:
|
||||||
|
config.add_tailbone_permission(permission_prefix,
|
||||||
|
'{}.view_global'.format(permission_prefix),
|
||||||
|
"View *global* {}".format(model_title_plural))
|
||||||
|
|
||||||
|
# view by grid index
|
||||||
|
config.add_route('{}.view_index'.format(route_prefix),
|
||||||
|
'{}/view'.format(url_prefix))
|
||||||
|
config.add_view(cls, attr='view_index',
|
||||||
|
route_name='{}.view_index'.format(route_prefix),
|
||||||
|
permission='{}.view'.format(permission_prefix))
|
||||||
|
|
||||||
|
# view by record key
|
||||||
|
config.add_route('{}.view'.format(route_prefix),
|
||||||
|
instance_url_prefix)
|
||||||
|
kwargs = {'http_cache': 0} if prevent_cache and cls.has_rows else {}
|
||||||
|
config.add_view(cls, attr='view', route_name='{}.view'.format(route_prefix),
|
||||||
|
permission='{}.view'.format(permission_prefix),
|
||||||
|
**kwargs)
|
||||||
|
|
||||||
|
# version history
|
||||||
|
if cls.has_versions and rattail_config and rattail_config.versioning_enabled():
|
||||||
|
config.add_tailbone_permission(permission_prefix,
|
||||||
|
'{}.versions'.format(permission_prefix),
|
||||||
|
"View version history for {}".format(model_title))
|
||||||
|
config.add_route('{}.versions'.format(route_prefix),
|
||||||
|
'{}/versions/'.format(instance_url_prefix))
|
||||||
|
config.add_view(cls, attr='versions',
|
||||||
|
route_name='{}.versions'.format(route_prefix),
|
||||||
|
permission='{}.versions'.format(permission_prefix))
|
||||||
|
config.add_route('{}.version'.format(route_prefix),
|
||||||
|
'{}/versions/{{txnid}}'.format(instance_url_prefix))
|
||||||
|
config.add_view(cls, attr='view_version',
|
||||||
|
route_name='{}.version'.format(route_prefix),
|
||||||
|
permission='{}.versions'.format(permission_prefix))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _defaults_edit_help(cls, config, **kwargs):
|
||||||
|
route_prefix = cls.get_route_prefix()
|
||||||
|
url_prefix = cls.get_url_prefix()
|
||||||
|
model_title_plural = cls.get_model_title_plural()
|
||||||
|
|
||||||
|
# nb. if caller specifies permission prefix, it's assumed they
|
||||||
|
# have registered it elsewhere
|
||||||
|
if 'permission_prefix' in kwargs:
|
||||||
|
permission_prefix = kwargs['permission_prefix']
|
||||||
|
else:
|
||||||
|
permission_prefix = cls.get_permission_prefix()
|
||||||
|
config.add_tailbone_permission(permission_prefix,
|
||||||
|
'{}.edit_help'.format(permission_prefix),
|
||||||
|
"Edit help info for {}".format(model_title_plural))
|
||||||
|
|
||||||
|
# edit page help
|
||||||
|
config.add_route('{}.edit_help'.format(route_prefix),
|
||||||
|
'{}/edit-help'.format(url_prefix),
|
||||||
|
request_method='POST')
|
||||||
|
config.add_view(cls, attr='edit_help',
|
||||||
|
route_name='{}.edit_help'.format(route_prefix),
|
||||||
|
renderer='json')
|
||||||
|
|
||||||
|
# edit field help
|
||||||
|
config.add_route('{}.edit_field_help'.format(route_prefix),
|
||||||
|
'{}/edit-field-help'.format(url_prefix),
|
||||||
|
request_method='POST')
|
||||||
|
config.add_view(cls, attr='edit_field_help',
|
||||||
|
route_name='{}.edit_field_help'.format(route_prefix),
|
||||||
|
renderer='json')
|
||||||
|
|
||||||
|
|
||||||
class ViewSupplement(object):
|
class ViewSupplement(object):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue