Issue #4 resolved

PluginPoint.get_plugin(name)

Anonymous created an issue

In my project I found useful to have a method that returns a plugin providing their name. This is the code that I use if you're interested on it.

{{{ AWS Solution Division def get_plugin(cls, name): """ Returns the plugin based on their name, if exists

Example::
    MyPluginPoint.get_plugin('name')

"""
if is_plugin_point(cls):
    point_pythonpath = cls.get_pythonpath()
    return Plugin.objects.get(point__pythonpath=point_pythonpath,
                              status=ENABLED,
                              name=name)
else:
    raise Exception(_('This method is only available to plugin point '
                      'classes.'))

}}}

Comments (2)

  1. sirex repo owner

    Actually, this does almost exactly what you want:

    MyPluginPoint.get_model('plugin-name')
    

    Method name is get_model to be not confused with get_plugin method name of plugin model instance.

    My example only lacks checking for plugin status, what I just fixed in e764253ff683.

    That you for this proposal.

  2. Anonymous

    Thank you very much sirex, I was thinking that get_model returns a Model instead of a Model instance. :) I'll use it!

  3. Log in to comment