Commit cd60dfde by benjaoming

Removing after refactor

parent 8d7f6064
# -*- coding: utf-8 -*-
"""
Credits to ojii, functions get_module and load are from:
https://github.com/ojii/django-load.
Thanks for the technique!
"""
from django.conf import settings
from django.utils.importlib import import_module
def get_module(app, modname, verbose, failfast):
"""
Internal function to load a module from a single app.
"""
module_name = '%s.%s' % (app, modname)
try:
module = import_module(module_name)
except ImportError, e:
if failfast:
raise e
elif verbose:
print "Could not load %r from %r: %s" % (modname, app, e)
return None
if verbose:
print "Loaded %r from %r" % (modname, app)
return module
def load(modname, verbose=False, failfast=False):
"""
Loads all modules with name 'modname' from all installed apps.
If verbose is True, debug information will be printed to stdout.
If failfast is True, import errors will not be surpressed.
"""
for app in settings.INSTALLED_APPS:
get_module(app, modname, verbose, failfast)
def load_wiki_plugins():
load('wiki_plugin', verbose=False)
# -*- coding: utf-8 -*-
from django.utils.importlib import import_module
_cache = {}
_settings_forms = []
_markdown_extensions = []
_article_tabs = []
_sidebar = []
def register(PluginClass):
"""
Register a plugin class. This function will call back your plugin's
constructor.
"""
if PluginClass in _cache.keys():
raise Exception("Plugin class already registered")
plugin = PluginClass()
_cache[PluginClass] = plugin
settings_form = getattr(PluginClass, 'settings_form', None)
if settings_form:
if isinstance(settings_form, basestring):
klassname = settings_form.split(".")[-1]
modulename = ".".join(settings_form.split(".")[:-1])
form_module = import_module(modulename)
settings_form = getattr(form_module, klassname)
_settings_forms.append(settings_form)
if getattr(PluginClass, 'article_tab', None):
_article_tabs.append(plugin)
if getattr(PluginClass, 'sidebar', None):
_sidebar.append(plugin)
_markdown_extensions.extend(getattr(PluginClass, 'markdown_extensions', []))
def get_plugins():
return _cache
def get_markdown_extensions():
return _markdown_extensions
def get_article_tabs():
"""Returns plugin classes that should connect to the article tab menu"""
return _article_tabs
def get_sidebar():
"""Returns plugin classes that should connect to the sidebar"""
return _sidebar
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment