kopia lustrzana https://github.com/wagtail/wagtail
Make hooks and image formats importing work with Django 1.7 AppConfigs
This also fixes #398pull/497/head
rodzic
61278ddfcd
commit
3a1099e330
|
@ -68,7 +68,6 @@ INSTALLED_APPS = [
|
||||||
'wagtail.wagtailimages',
|
'wagtail.wagtailimages',
|
||||||
'wagtail.wagtailembeds',
|
'wagtail.wagtailembeds',
|
||||||
'wagtail.wagtailsearch',
|
'wagtail.wagtailsearch',
|
||||||
'wagtail.wagtailredirects',
|
|
||||||
'wagtail.wagtailforms',
|
'wagtail.wagtailforms',
|
||||||
'wagtail.contrib.wagtailstyleguide',
|
'wagtail.contrib.wagtailstyleguide',
|
||||||
'wagtail.contrib.wagtailsitemaps',
|
'wagtail.contrib.wagtailsitemaps',
|
||||||
|
@ -81,6 +80,15 @@ if django.VERSION[:2] == (1, 6):
|
||||||
INSTALLED_APPS.append('south')
|
INSTALLED_APPS.append('south')
|
||||||
|
|
||||||
|
|
||||||
|
# If we are using Django 1.7 install wagtailredirects with its appconfig
|
||||||
|
# Theres nothing special about wagtailredirects, we just need to have one
|
||||||
|
# app which uses AppConfigs to test that hooks load properly
|
||||||
|
|
||||||
|
if django.VERSION[:2] == (1, 6):
|
||||||
|
INSTALLED_APPS.append('wagtail.wagtailredirects')
|
||||||
|
else:
|
||||||
|
INSTALLED_APPS.append('wagtail.wagtailredirects.apps.WagtailRedirectsAppConfig')
|
||||||
|
|
||||||
# As we don't have south migrations for tests, South thinks
|
# As we don't have south migrations for tests, South thinks
|
||||||
# the Django 1.7 migrations are South migrations.
|
# the Django 1.7 migrations are South migrations.
|
||||||
SOUTH_MIGRATION_MODULES = {
|
SOUTH_MIGRATION_MODULES = {
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
try:
|
||||||
|
from importlib import import_module
|
||||||
|
except ImportError:
|
||||||
|
# for Python 2.6, fall back on django.utils.importlib (deprecated as of Django 1.7)
|
||||||
|
from django.utils.importlib import import_module
|
||||||
|
|
||||||
|
import django
|
||||||
|
from django.conf import settings
|
||||||
|
from django.utils.module_loading import module_has_submodule
|
||||||
|
|
||||||
|
|
||||||
|
def get_app_modules():
|
||||||
|
"""
|
||||||
|
Generator function that yields a module object for each installed app
|
||||||
|
yields tuples of (app_name, module)
|
||||||
|
"""
|
||||||
|
if django.VERSION[:2] == (1, 6):
|
||||||
|
# Django 1.6
|
||||||
|
for app in settings.INSTALLED_APPS:
|
||||||
|
yield app, import_module(app)
|
||||||
|
else:
|
||||||
|
# Django 1.7+
|
||||||
|
from django.apps import apps
|
||||||
|
for app in apps.get_app_configs():
|
||||||
|
yield app.name, app.module
|
||||||
|
|
||||||
|
|
||||||
|
def get_app_submodules(submodule_name):
|
||||||
|
"""
|
||||||
|
Searches each app module for the specified submodule
|
||||||
|
yields tuples of (app_name, module)
|
||||||
|
"""
|
||||||
|
for name, module in get_app_modules():
|
||||||
|
if module_has_submodule(module, submodule_name):
|
||||||
|
yield name, import_module('%s.%s' % (name, submodule_name))
|
|
@ -1,9 +1,5 @@
|
||||||
from django.conf import settings
|
from wagtail.utils.apps import get_app_submodules
|
||||||
try:
|
|
||||||
from importlib import import_module
|
|
||||||
except ImportError:
|
|
||||||
# for Python 2.6, fall back on django.utils.importlib (deprecated as of Django 1.7)
|
|
||||||
from django.utils.importlib import import_module
|
|
||||||
|
|
||||||
_hooks = {}
|
_hooks = {}
|
||||||
|
|
||||||
|
@ -40,12 +36,7 @@ _searched_for_hooks = False
|
||||||
def search_for_hooks():
|
def search_for_hooks():
|
||||||
global _searched_for_hooks
|
global _searched_for_hooks
|
||||||
if not _searched_for_hooks:
|
if not _searched_for_hooks:
|
||||||
for app_module in settings.INSTALLED_APPS:
|
list(get_app_submodules('wagtail_hooks'))
|
||||||
try:
|
|
||||||
import_module('%s.wagtail_hooks' % app_module)
|
|
||||||
except ImportError:
|
|
||||||
continue
|
|
||||||
|
|
||||||
_searched_for_hooks = True
|
_searched_for_hooks = True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
from django.conf import settings
|
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
|
|
||||||
try:
|
from wagtail.utils.apps import get_app_submodules
|
||||||
from importlib import import_module
|
|
||||||
except ImportError:
|
|
||||||
# for Python 2.6, fall back on django.utils.importlib (deprecated as of Django 1.7)
|
|
||||||
from django.utils.importlib import import_module
|
|
||||||
|
|
||||||
|
|
||||||
class Format(object):
|
class Format(object):
|
||||||
|
@ -85,12 +80,7 @@ _searched_for_image_formats = False
|
||||||
def search_for_image_formats():
|
def search_for_image_formats():
|
||||||
global _searched_for_image_formats
|
global _searched_for_image_formats
|
||||||
if not _searched_for_image_formats:
|
if not _searched_for_image_formats:
|
||||||
for app_module in settings.INSTALLED_APPS:
|
list(get_app_submodules('image_formats'))
|
||||||
try:
|
|
||||||
import_module('%s.image_formats' % app_module)
|
|
||||||
except ImportError:
|
|
||||||
continue
|
|
||||||
|
|
||||||
_searched_for_image_formats = True
|
_searched_for_image_formats = True
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue