From fff5c5b1490b698a7485e4e2f1480034fc1892f2 Mon Sep 17 00:00:00 2001 From: vincenzoarcidiacono Date: Sun, 19 Nov 2023 09:37:58 +0100 Subject: [PATCH] fix(drw): Correct broken link when same object is rendered twice. --- schedula/utils/drw/__init__.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/schedula/utils/drw/__init__.py b/schedula/utils/drw/__init__.py index 637b2a0cb..f41e9aec4 100644 --- a/schedula/utils/drw/__init__.py +++ b/schedula/utils/drw/__init__.py @@ -159,15 +159,26 @@ def site_view( 'alive_url': 'alive' in app.view_functions and app.url_for('alive') } render_ctx.update(app.jinja_env.globals) - if not osp.isfile(osp.join(static_folder, filepath)): + fpath = osp.join(static_folder, filepath) + if not osp.isfile(fpath): if filepath not in rules: from flask import abort return abort(404) - + rdir = osp.dirname(fpath) + directory = None + node = rules[filepath] for v in cached_view( - rules[filepath], static_folder, context, rendered, viz, - executor, **render_ctx).values(): - v.result() + node, static_folder, context, rendered, viz, executor, + **render_ctx).values(): + fp = v.result() + if directory is None: + directory = osp.dirname(fp) + if fp != fpath: + shutil.copy(fp, fpath) + + if directory != rdir: + shutil.copy(fp, osp.join(rdir, osp.relpath(fp, directory))) + return app.send_static_file(filepath) @@ -207,10 +218,7 @@ def __init__( @property def name(self): - try: - return parent_func(self.item).__name__ - except AttributeError: - return self.node_id + return self.node_id @property def view_id(self):