|
@@ -721,7 +721,9 @@ class CustomLinkColumn(tables.Column):
|
|
|
super().__init__(*args, **kwargs)
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def _render_customlink(self, record, table):
|
|
def _render_customlink(self, record, table):
|
|
|
- request = getattr(table, 'context', {}).get('request')
|
|
|
|
|
|
|
+ # A table rendered in a template has a context, while one being exported has only the request it was
|
|
|
|
|
+ # configured for
|
|
|
|
|
+ request = getattr(table, 'context', {}).get('request') or getattr(table, 'request', None)
|
|
|
# Share the render state, and the objects serialized for it, among all of the table's custom link columns.
|
|
# Share the render state, and the objects serialized for it, among all of the table's custom link columns.
|
|
|
# Retain them only for the request they were created for.
|
|
# Retain them only for the request they were created for.
|
|
|
cached_request, state, objects = getattr(table, '_custom_link_render_state', (None, None, None))
|
|
cached_request, state, objects = getattr(table, '_custom_link_render_state', (None, None, None))
|
|
@@ -750,16 +752,14 @@ class CustomLinkColumn(tables.Column):
|
|
|
def _get_template_object(record, table, state, objects):
|
|
def _get_template_object(record, table, state, objects):
|
|
|
"""
|
|
"""
|
|
|
Return the TemplateObject for a record, retaining the objects serialized in the given dict. The records on the
|
|
Return the TemplateObject for a record, retaining the objects serialized in the given dict. The records on the
|
|
|
- table's current page are serialized at once, or for an unpaginated table (e.g. an export), the records in
|
|
|
|
|
|
|
+ table's current page are serialized at once, or for a record not on it (e.g. in an export), the records in
|
|
|
chunks following this one.
|
|
chunks following this one.
|
|
|
"""
|
|
"""
|
|
|
if record.pk not in objects:
|
|
if record.pk not in objects:
|
|
|
- if page := getattr(table, 'page', None):
|
|
|
|
|
- pks = [row.record.pk for row in page.object_list]
|
|
|
|
|
- if record.pk not in pks:
|
|
|
|
|
- pks.append(record.pk)
|
|
|
|
|
- else:
|
|
|
|
|
- # Retain only the current chunk of an unpaginated table, and the related objects fetched for it
|
|
|
|
|
|
|
+ page = getattr(table, 'page', None)
|
|
|
|
|
+ pks = [row.record.pk for row in page.object_list] if page else []
|
|
|
|
|
+ if record.pk not in pks:
|
|
|
|
|
+ # Retain only the current chunk of the table, and the related objects fetched for it
|
|
|
objects.clear()
|
|
objects.clear()
|
|
|
state.cache.clear()
|
|
state.cache.clear()
|
|
|
pks = CustomLinkColumn._get_chunk(record, table)
|
|
pks = CustomLinkColumn._get_chunk(record, table)
|