general: use django.apps to register URLs and actions (#6979)

This commit is contained in:
Frédéric Péters 2015-04-18 14:26:00 +02:00
parent b5fee77f5e
commit 6c86f26186
2 changed files with 5 additions and 12 deletions

View File

@ -13,7 +13,3 @@
# #
# You should have received a copy of the GNU Affero General Public License # 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import plugins
plugins.init()

View File

@ -17,7 +17,9 @@
from pkg_resources import iter_entry_points from pkg_resources import iter_entry_points
import logging import logging
from django.apps import apps
from django.conf.urls import patterns, include, url from django.conf.urls import patterns, include, url
from django.conf import settings
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -41,7 +43,7 @@ def get_plugins(*args, **kwargs):
def register_plugins_urls(urlpatterns): def register_plugins_urls(urlpatterns):
pre_urls = [] pre_urls = []
post_urls = [] post_urls = []
for plugin in get_plugins(): for plugin in apps.get_app_configs():
if hasattr(plugin, 'get_before_urls'): if hasattr(plugin, 'get_before_urls'):
urls = plugin.get_before_urls() urls = plugin.get_before_urls()
if urls: if urls:
@ -74,15 +76,10 @@ def register_plugins_middleware(middlewares):
return middlewares return middlewares
def get_extra_manager_actions(): def get_extra_manager_actions():
'''This iterates over all plugins and returns a list of dictionaries, '''This iterates over all appconfigs and returns a list of dictionaries,
with href and text keys.''' with href and text keys.'''
actions = [] actions = []
for plugin in get_plugins(): for plugin in apps.get_app_configs():
if hasattr(plugin, 'get_extra_manager_actions'): if hasattr(plugin, 'get_extra_manager_actions'):
actions.extend(plugin.get_extra_manager_actions()) actions.extend(plugin.get_extra_manager_actions())
return actions return actions
def init():
for plugin in get_plugins():
if hasattr(plugin, 'init'):
plugin.init()