misc: disable momo by default, enable it with ENABLE_MOMO in settings (#8115)
This commit is contained in:
parent
06ff8acdbf
commit
769d252856
|
@ -15,12 +15,16 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import django.apps
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
class AppConfig(django.apps.AppConfig):
|
||||
name = 'combo.apps.momo'
|
||||
|
||||
def is_enabled(self):
|
||||
return getattr(settings, 'ENABLE_MOMO', False)
|
||||
|
||||
def get_before_urls(self):
|
||||
from . import urls
|
||||
return urls.urlpatterns
|
||||
|
|
|
@ -14,11 +14,14 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from functools import wraps
|
||||
from pkg_resources import iter_entry_points
|
||||
import logging
|
||||
|
||||
from django.apps import apps
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.http import Http404
|
||||
from django.views.debug import technical_404_response
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -28,6 +31,24 @@ class PluginError(Exception):
|
|||
pass
|
||||
|
||||
|
||||
def get_plugin_includes(plugin, url_serie):
|
||||
if not hasattr(plugin, url_serie):
|
||||
return
|
||||
urls = getattr(plugin, url_serie)()
|
||||
if not hasattr(plugin, 'is_enabled'):
|
||||
return url('^', include(urls))
|
||||
|
||||
def plugin_enabled(func):
|
||||
@wraps(func)
|
||||
def f(request, *args, **kwargs):
|
||||
if not plugin.is_enabled():
|
||||
return technical_404_response(request, Http404())
|
||||
return func(request, *args, **kwargs)
|
||||
return f
|
||||
|
||||
from .urls_utils import decorated_includes
|
||||
return url('^', decorated_includes(plugin_enabled, include(urls)))
|
||||
|
||||
def get_plugins(*args, **kwargs):
|
||||
plugins = []
|
||||
for entrypoint in iter_entry_points(PLUGIN_GROUP_NAME):
|
||||
|
@ -43,14 +64,12 @@ def register_plugins_urls(urlpatterns):
|
|||
pre_urls = []
|
||||
post_urls = []
|
||||
for plugin in apps.get_app_configs():
|
||||
if hasattr(plugin, 'get_before_urls'):
|
||||
urls = plugin.get_before_urls()
|
||||
if urls:
|
||||
pre_urls.append(url('^', include(urls)))
|
||||
if hasattr(plugin, 'get_after_urls'):
|
||||
urls = plugin.get_after_urls()
|
||||
if urls:
|
||||
post_urls.append(url('^', include(urls)))
|
||||
urls = get_plugin_includes(plugin, 'get_before_urls')
|
||||
if urls:
|
||||
pre_urls.append(urls)
|
||||
urls = get_plugin_includes(plugin, 'get_after_urls')
|
||||
if urls:
|
||||
post_urls.append(urls)
|
||||
pre_patterns = patterns('', *pre_urls)
|
||||
post_patterns = patterns('', *post_urls)
|
||||
return pre_patterns + urlpatterns + post_patterns
|
||||
|
@ -59,14 +78,12 @@ def register_plugins_manager_urls(urlpatterns):
|
|||
pre_urls = []
|
||||
post_urls = []
|
||||
for plugin in apps.get_app_configs():
|
||||
if hasattr(plugin, 'get_before_manager_urls'):
|
||||
urls = plugin.get_before_manager_urls()
|
||||
if urls:
|
||||
pre_urls.append(url('^', include(urls)))
|
||||
if hasattr(plugin, 'get_after_manager_urls'):
|
||||
urls = plugin.get_after_manager_urls()
|
||||
if urls:
|
||||
post_urls.append(url('^', include(urls)))
|
||||
urls = get_plugin_includes(plugin, 'get_before_manager_urls')
|
||||
if urls:
|
||||
pre_urls.append(urls)
|
||||
urls = get_plugin_includes(plugin, 'get_after_manager_urls')
|
||||
if urls:
|
||||
post_urls.append(urls)
|
||||
pre_patterns = patterns('', *pre_urls)
|
||||
post_patterns = patterns('', *post_urls)
|
||||
return pre_patterns + urlpatterns + post_patterns
|
||||
|
@ -84,6 +101,8 @@ def get_extra_manager_actions():
|
|||
with href and text keys.'''
|
||||
actions = []
|
||||
for plugin in apps.get_app_configs():
|
||||
if hasattr(plugin, 'is_enabled') and not plugin.is_enabled():
|
||||
continue
|
||||
if hasattr(plugin, 'get_extra_manager_actions'):
|
||||
actions.extend(plugin.get_extra_manager_actions())
|
||||
return actions
|
||||
|
|
Loading…
Reference in New Issue