Skip to content

Commit

Permalink
fix(drw): Correct broken link when same object is rendered twice.
Browse files Browse the repository at this point in the history
  • Loading branch information
vinci1it2000 committed Nov 19, 2023
1 parent bb6c7ac commit 3e7aa02
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions schedula/utils/drw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,23 @@ 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)):
if filepath not in rules:
fpath = osp.join(static_folder, filepath)
if not osp.isfile(fpath):
try:
node = rules[filepath]
except KeyError:
from flask import abort
return abort(404)
rend, expected = cached_view(
node, static_folder, context, rendered, viz, executor, **render_ctx
)
for k, v in rend.items():
fpath_rendered = v.result()
fpath_expected = expected[k]
if fpath_rendered != fpath_expected:
os.makedirs(osp.dirname(fpath_expected), exist_ok=True)
shutil.copy(fpath_rendered, fpath_expected)

for v in cached_view(
rules[filepath], static_folder, context, rendered, viz,
executor, **render_ctx).values():
v.result()
return app.send_static_file(filepath)


Expand Down Expand Up @@ -207,10 +215,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):
Expand Down Expand Up @@ -1820,7 +1825,11 @@ def cached_view(node, directory, context, rendered, viz=False, executor='async',
**render_ctx):
n_id = node.view_id
rend = {k: v for k, v in rendered.items() if k[0] == n_id}
expected = {(n_id, e): f for (n, e), f in context.items() if n == node}
expected = {
(n_id, e): uncpath(osp.join(directory, f))
for (n, e), f in context.items()
if n == node
}
res = {k: Future() for k in expected if k not in rendered}
if res:
rendered.update(res)
Expand All @@ -1831,7 +1840,7 @@ def cached_view(node, directory, context, rendered, viz=False, executor='async',
_set_rendered, res, expected=expected
))
rend.update(res)
return rend
return rend, expected


def _compile_subs(o, n):
Expand Down

0 comments on commit 3e7aa02

Please sign in to comment.