# HG changeset patch # User Thierry Florac # Date 1526651615 -7200 # Node ID 7340e6c1429ff8659baae26f7f65451eccd26480 # Parent 43048fb84b87aa0420c575265ef1750eb4c39dde Updated associations views to handle multiple associations tables in the same view diff -r 43048fb84b87 -r 7340e6c1429f src/pyams_content/component/association/zmi/__init__.py --- a/src/pyams_content/component/association/zmi/__init__.py Fri May 18 15:52:22 2018 +0200 +++ b/src/pyams_content/component/association/zmi/__init__.py Fri May 18 15:53:35 2018 +0200 @@ -36,6 +36,7 @@ from pyams_skin.event import get_json_switched_table_refresh_event, get_json_table_row_refresh_event from pyams_skin.viewlet.menu import MenuItem from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter +from pyams_utils.registry import get_current_registry from pyams_utils.traversing import get_parent from pyams_utils.url import absolute_url from pyams_viewlet.viewlet import viewlet_config @@ -100,6 +101,7 @@ """Associations view inner table""" prefix = 'associations' + associations_name = '' hide_header = True sortOn = None @@ -114,10 +116,13 @@ @property def data_attributes(self): + registry = get_current_registry() + target = get_parent(self.context, IAssociationTarget) + container = registry.getAdapter(target, IAssociationContainer, name=self.associations_name) attributes = super(AssociationsTable, self).data_attributes attributes['table'] = { 'id': self.id, - 'data-ams-location': absolute_url(IAssociationContainer(self.context), self.request), + 'data-ams-location': absolute_url(container, self.request), 'data-ams-tablednd-drag-handle': 'td.sorter', 'data-ams-tablednd-drop-target': 'set-associations-order.json', 'data-ams-visibility-switcher': 'switch-association-visibility.json' @@ -135,7 +140,8 @@ @property def values(self): - return IAssociationContainer(self.context).values() + registry = get_current_registry() + return registry.getAdapter(self.context, IAssociationContainer, name=self.view.associations_name).values() @adapter_config(name='sorter', context=(IAssociationTarget, IPyAMSLayer, AssociationsTable), provides=IColumn) @@ -146,7 +152,7 @@ @view_config(name='set-associations-order.json', context=IAssociationContainer, request_type=IPyAMSLayer, permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True) def set_associations_order(request): - """Update asociations order""" + """Update associations order""" order = list(map(str, json.loads(request.params.get('names')))) request.context.updateOrder(order) return {'status': 'success'}