From 3d0a7092eecda696bf5feb4ed7fb6b43d9d660e1 Mon Sep 17 00:00:00 2001 From: "John N. Milner" Date: Thu, 26 Sep 2024 22:18:03 -0400 Subject: [PATCH] Regenerate snapshots when downloading XForm XML Avoids serving stale XML in certain situations, such as when the form has *not* been changed but pyxform has been updated --- kpi/renderers.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/kpi/renderers.py b/kpi/renderers.py index 49019edd62..df79591354 100644 --- a/kpi/renderers.py +++ b/kpi/renderers.py @@ -237,6 +237,8 @@ def render( accepted_media_type=None, renderer_context=None, relationship=None, + relationship_args=None, + relationship_kwargs=None, ): if hasattr(renderer_context.get('view'), 'get_object'): obj = renderer_context.get('view').get_object() @@ -246,7 +248,10 @@ def render( if relationship is not None and hasattr(obj, relationship): var_or_callable = getattr(obj, relationship) if isinstance(var_or_callable, Callable): - return var_or_callable().xml + return var_or_callable( + *(relationship_args or tuple()), + **(relationship_kwargs or dict()) + ).xml return var_or_callable.xml return add_xml_declaration(obj.xml) else: @@ -260,10 +265,13 @@ def render( class XFormRenderer(XMLRenderer): def render(self, data, accepted_media_type=None, renderer_context=None): - return super().render(data=data, - accepted_media_type=accepted_media_type, - renderer_context=renderer_context, - relationship="snapshot") + return super().render( + data=data, + accepted_media_type=accepted_media_type, + renderer_context=renderer_context, + relationship='snapshot', + relationship_kwargs={'regenerate': 'True'}, + ) class XlsRenderer(renderers.BaseRenderer):