Coverage for src/django_resume/plugin_registry.py: 100%
16 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-27 17:15 +0200
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-27 17:15 +0200
1from django_resume.plugins import Plugin
4class PluginRegistry:
5 """
6 A registry for plugins. This is used to register and unregister plugins.
7 """
9 def __init__(self):
10 self.plugins = {}
12 def register(self, plugin_class: type[Plugin]):
13 """
14 Register a plugin class. This will instantiate the plugin and add it to the registry.
16 It will also add the plugin's inline URLs to the urlpatterns list.
17 """
18 plugin = plugin_class()
19 self.plugins[plugin.name] = plugin
20 from .urls import urlpatterns
22 urlpatterns.extend(plugin.get_inline_urls())
24 def unregister(self, plugin_class: type[Plugin]):
25 del self.plugins[plugin_class.name]
27 def get_plugin(self, name):
28 return self.plugins.get(name)
30 def get_all_plugins(self):
31 return self.plugins.values()
34# The global plugin registry - this is a singleton since module level variables are shared across the application.
35plugin_registry = PluginRegistry()