3 from django
.conf
import settings
5 from muddle
.util
import path_to_class
8 def load_app_plugin(module_name
, Klass
=None, method
=None):
10 Helper method for loading an app plugin. An app plugin is defined as some
11 form of plugin that uses a form of registration logic that other apps must
12 use to register their usage of the plugin.
14 Some examples built into django:
15 * models found within models.py
16 * admin classes within admin.py
18 @param module_name: module name to load. This is a string,
19 @param klass: class type(s) to load. This may be a single class or a list
21 @param method: method to run passing in each class that is found, or the
22 module if no classes are specified
25 for app
in settings
.INSTALLED_APPS
:
27 module
= path_to_class('.'.join([app
, module_name
]))
30 assert(callable(method
))
32 for name
in dir(module
):
33 # run the method for each member
34 obj
= getattr(module
, name
)
35 if inspect
.isclass(obj
) and issubclass(obj
, (Klass
,)):
38 elif callable(method
):
39 # no classes specified, but there was a method. execute the method
44 # no class or method, importing the module is enough
47 # not all apps will have the module we are looking for