Skip to content

Commit

Permalink
Added ability to unregister plugins from the plugin pool.
Browse files Browse the repository at this point in the history
  • Loading branch information
jezdez committed Apr 2, 2010
1 parent cf68c11 commit 045f84c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cms/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
class PluginAllreadyRegistered(Exception):
pass

class PluginNotRegistered(Exception):
pass

class AppAllreadyRegistered(Exception):
pass

Expand Down
22 changes: 18 additions & 4 deletions cms/plugin_pool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cms.exceptions import PluginAllreadyRegistered
from cms.exceptions import PluginAllreadyRegistered, PluginNotRegistered
from django.conf import settings
from cms.plugin_base import CMSPluginBase
from cms.utils.helpers import reversion_register
Expand All @@ -7,12 +7,12 @@ class PluginPool(object):
def __init__(self):
self.plugins = {}
self.discovered = False

def discover_plugins(self):
if self.discovered:
return
for app in settings.INSTALLED_APPS:
__import__(app, {}, {}, ['cms_plugins'])
__import__(app, {}, {}, ['cms_plugins'])
self.discovered = True

def register_plugin(self, plugin):
Expand All @@ -33,6 +33,20 @@ def register_plugin(self, plugin):
except RegistrationError:
pass

def unregister_plugin(self, plugin_or_iterable):
"""
Unregisters the given plugin(s).
If a plugin isn't already registered, this will raise PluginNotRegistered.
"""
if isinstance(plugin_or_iterable, CMSPluginBase):
plugin_or_iterable = [plugin_or_iterable]
for plugin in plugin_or_iterable:
plugin_name = plugin.__name__
if plugin_name not in self.plugins:
raise PluginNotRegistered('The plugin %s is not registered' % plugin_name)
del self.plugins[plugin_name]

def get_all_plugins(self, placeholder=None, page=None, setting_key="plugins"):
self.discover_plugins()
plugins = self.plugins.values()[:]
Expand All @@ -49,7 +63,7 @@ def get_all_plugins(self, placeholder=None, page=None, setting_key="plugins"):
final_plugins.append(plugin)
plugins = final_plugins
return plugins

def get_text_enabled_plugins(self, placeholder, page):
plugins = self.get_all_plugins(placeholder, page) + self.get_all_plugins(placeholder, page, 'text_only_plugins')
final = []
Expand Down

0 comments on commit 045f84c

Please sign in to comment.