diff --git a/src/cmsplugin_blurp/utils.py b/src/cmsplugin_blurp/utils.py index b462078..d7ebe4e 100644 --- a/src/cmsplugin_blurp/utils.py +++ b/src/cmsplugin_blurp/utils.py @@ -17,13 +17,17 @@ def renderers_choices(): renderer = resolve_renderer(slug) yield slug, renderer_description(renderer) or slug +def create_renderer(name, instance): + '''Create a renderer instance of given name from a settings dictionary''' + module_name, class_name = instance['class'].rsplit('.', 1) + module = import_module(module_name) + return getattr(module, class_name)(name, instance) + def resolve_renderer(name): '''Create a renderer instance from slug name of its settings''' instance = app_settings.RENDERERS.get(name) if instance: - module_name, class_name = instance['class'].rsplit('.', 1) - module = import_module(module_name) - return getattr(module, class_name)(name, instance) + return create_renderer(name, instance) def insert_blurp_in_context(name, context): renderer = resolve_renderer(name)