Split graph/import/meta into Django apps, add API v1 with OpenAPI and pytest, and introduce plugin registry with the tags reference plugin on both FE and BE. Co-authored-by: Cursor <cursoragent@cursor.com>
49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
"""Plugin platform base classes and registry."""
|
|
|
|
from abc import ABC, abstractmethod
|
|
from typing import List
|
|
|
|
from django.conf import settings
|
|
from django.urls import URLPattern
|
|
|
|
|
|
class Plugin(ABC):
|
|
id: str = ''
|
|
version: str = '1.0.0'
|
|
min_core_version: str = '1.0.0'
|
|
permissions: List[str] = []
|
|
|
|
@abstractmethod
|
|
def urlpatterns(self) -> List[URLPattern]:
|
|
pass
|
|
|
|
def installed_apps(self) -> List[str]:
|
|
return []
|
|
|
|
|
|
_REGISTRY: dict[str, Plugin] = {}
|
|
|
|
|
|
def register_plugin(plugin: Plugin) -> None:
|
|
_REGISTRY[plugin.id] = plugin
|
|
|
|
|
|
def get_plugin(plugin_id: str) -> Plugin | None:
|
|
return _REGISTRY.get(plugin_id)
|
|
|
|
|
|
def get_enabled_plugins() -> List[Plugin]:
|
|
enabled = getattr(settings, 'ENABLED_PLUGINS', [])
|
|
return [_REGISTRY[pid] for pid in enabled if pid in _REGISTRY]
|
|
|
|
|
|
def plugin_urlpatterns() -> List[URLPattern]:
|
|
from django.urls import path, include
|
|
|
|
patterns: List[URLPattern] = []
|
|
for plugin in get_enabled_plugins():
|
|
patterns.append(
|
|
path(f'plugins/{plugin.id}/', include((plugin.urlpatterns(), plugin.id)))
|
|
)
|
|
return patterns
|