Skip to content

Conversation

@sal-uva
Copy link
Collaborator

@sal-uva sal-uva commented Dec 18, 2025

This allows to add files with the name [datasource-id]-explorer.html and [datasource-id]-explorer.css to be added to config/extensions. These are then used in the Explorer. For HTML, Flask needs to know where to read templates from, which becomes a bit tricky if it's not in webtool. So on startup, it now walks through config/extensions and loads Explorer templates there if present. Speed and memory hits should be minimal.

@sal-uva sal-uva requested a review from stijn-uva December 19, 2025 10:29
Copy link
Member

@stijn-uva stijn-uva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be best if we could combine the template gathering code with the other modular file collection code in ModuleLoader, to keep that functionality centralised and not repeat ourselves too much. There's a load_modules and load_datasources in there - a load_templates could fit in as well. Otherwise looks like a good change.


# Load Explorer HTML templates from extensions
extension_explorer_templates = {}
def get_explorer_templates_from_extensions():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be done in ModuleLoader()? That already has logic to traverse the extension folders and could also collect template files, then they could be passed to app.jinja_loader here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have a config.get("PATH_EXTENSIONS") that ca be used instead of re-constructing the path here

with open(standard_path, "r", encoding="utf-8") as f:
return f.read()

# Check extensions folder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise this could perhaps be collected on startup in ModuleLoader, also saves some time on pageview

@sal-uva
Copy link
Collaborator Author

sal-uva commented Dec 19, 2025

Will make the changes.

@stijn-uva I was doubting whether to also put Explorer templates in datasource folders. That's how it was originally, and it keeps datasource files nicely contained in one directory. But it doesn't really follow the logic of front/backend and will require traversing datasources for Explorer templates as well--though these are already walked through in the module loader of course. Any preference?

@sal-uva
Copy link
Collaborator Author

sal-uva commented Dec 19, 2025

@stijn-uva , okay, I moved the Explorer html and css files to datasource folders. The module loader now adds a 'explorer-templates' key with css and html files, if present for this datasource. These are then loaded in with a new function in __init__.py, as well as in a new template filter for the CSS (these couldn't just be passed as template, need to be scoped etc.).

One thing I'm not sure about is whether/if to use current_app or g in __init__.py, but this seems to work well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants