diff --git a/epdb/apps.py b/epdb/apps.py index 5a0c4023..2aa4dc66 100644 --- a/epdb/apps.py +++ b/epdb/apps.py @@ -16,6 +16,10 @@ class EPDBConfig(AppConfig): model_name = getattr(settings, "EPDB_PACKAGE_MODEL", "epdb.Package") logger.info(f"Using Package model: {model_name}") + from .autodiscovery import autodiscover + + autodiscover() + if settings.PLUGINS_ENABLED: from bridge.contracts import Property from utilities.plugin import discover_plugins diff --git a/epdb/autodiscovery.py b/epdb/autodiscovery.py new file mode 100644 index 00000000..1a214cab --- /dev/null +++ b/epdb/autodiscovery.py @@ -0,0 +1,5 @@ +from django.utils.module_loading import autodiscover_modules + + +def autodiscover(): + autodiscover_modules("epdb_hooks") diff --git a/epdb/template_registry.py b/epdb/template_registry.py new file mode 100644 index 00000000..d2da8aff --- /dev/null +++ b/epdb/template_registry.py @@ -0,0 +1,17 @@ +from collections import defaultdict +from threading import Lock + +_registry = defaultdict(list) +_lock = Lock() + + +def register_template(slot: str, template_name: str, *, order: int = 100): + item = (order, template_name) + with _lock: + if item not in _registry[slot]: + _registry[slot].append(item) + _registry[slot].sort(key=lambda x: x[0]) + + +def get_templates(slot: str): + return [template_name for _, template_name in _registry.get(slot, [])] diff --git a/epdb/templatetags/envipytags.py b/epdb/templatetags/envipytags.py index 6c250e63..a61cc5a7 100644 --- a/epdb/templatetags/envipytags.py +++ b/epdb/templatetags/envipytags.py @@ -2,6 +2,8 @@ from django import template from pydantic import AnyHttpUrl, ValidationError from pydantic.type_adapter import TypeAdapter +from epdb.template_registry import get_templates + register = template.Library() url_adapter = TypeAdapter(AnyHttpUrl) @@ -19,3 +21,8 @@ def is_url(value): return True except ValidationError: return False + + +@register.simple_tag +def epdb_slot_templates(slot): + return get_templates(slot) diff --git a/templates/collections/compounds_paginated.html b/templates/collections/compounds_paginated.html index 7248da95..f5868225 100644 --- a/templates/collections/compounds_paginated.html +++ b/templates/collections/compounds_paginated.html @@ -1,21 +1,34 @@ {% extends "collections/paginated_base.html" %} +{% load envipytags %} {% block page_title %}Compounds{% endblock %} {% block action_button %} - {% if meta.can_edit %} - - {% endif %} +