コード例 #1
0
 def load_plugins(self):
     """
     Enable plugins and set "loaded" attribute. This method is threadsafe, in the
     sense that every caller will see the same state upon return, and if the
     cache is already initialised, it does no work.
     """
     if self.loaded:
         return
     self.write_lock.acquire()
     try:
         if self.loaded:
             return
         from merengue.registry import invalidate_registereditem
         from merengue.pluggable.utils import (enable_plugin,
                                               get_plugin_module_name,
                                               reload_models_cache)
         from merengue.pluggable.models import RegisteredPlugin
         # enable active plugins
         active_plugins = RegisteredPlugin.objects.actives()
         plugin_names = [get_plugin_module_name(p.directory_name)
                         for p in active_plugins]
         for plugin_name in plugin_names:
             enable_plugin(plugin_name, register=True)
         # invalidate any existing cache
         invalidate_registereditem()
         # reload models cache. needed because new plugins could bring new models
         reload_models_cache()
         self.loaded = True
     finally:
         self.write_lock.release()
コード例 #2
0
def save_plugin_signal(sender, instance, **kwargs):
    from merengue.pluggable.utils import (get_plugin_module_name,
                                          enable_plugin, disable_plugin)
    app_name = get_plugin_module_name(instance.directory_name)
    if not getattr(instance, 'id', None) and getattr(instance, 'pk', None):
        instance = instance._default_manager.get(pk=instance.pk)
    if instance.installed and instance.active and instance.directory_name and not instance.broken:
        enable_plugin(app_name)
    elif not instance.active and instance.directory_name and instance.config:
        try:
            disable_plugin(app_name)
        except ImportError:
            if instance.broken:
                pass  # the plugin is broken
            else:
                raise
コード例 #3
0
ファイル: models.py プロジェクト: creativify/merengueproj
def save_plugin_signal(sender, instance, **kwargs):
    from merengue.pluggable.utils import (get_plugin_module_name,
                                          enable_plugin,
                                          disable_plugin)
    app_name = get_plugin_module_name(instance.directory_name)
    if not getattr(instance, 'id', None) and getattr(instance, 'pk', None):
        instance = instance._default_manager.get(pk=instance.pk)
    if instance.installed and instance.active and instance.directory_name and not instance.broken:
        enable_plugin(app_name)
    elif not instance.active and instance.directory_name and instance.config:
        try:
            disable_plugin(app_name)
        except ImportError:
            if instance.broken:
                pass  # the plugin is broken
            else:
                raise