Skip to content

Commit

Permalink
show_template_tags should handle AppConfig class in INSTALLED applica…
Browse files Browse the repository at this point in the history
jrd committed Aug 23, 2018
1 parent b288d4c commit ddf93b3
Showing 1 changed file with 29 additions and 34 deletions.
63 changes: 29 additions & 34 deletions django_extensions/management/commands/show_template_tags.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
import inspect
import os

from django.conf import settings
from django.apps import apps
from django.core.management import color
from django.core.management import BaseCommand
from django.utils import termcolors
@@ -72,38 +72,33 @@ def handle(self, *args, **options):

style = color_style()

if getattr(settings, 'ADMIN_FOR', None):
settings_modules = [__import__(m, {}, {}, ['']) for m in settings.ADMIN_FOR]
else:
settings_modules = [settings]

for settings_mod in settings_modules:
for app in settings_mod.INSTALLED_APPS:
try:
templatetag_mod = __import__(app + '.templatetags', {}, {}, [''])
except ImportError:
for app_config in apps.get_app_configs():
app = app_config.name
try:
templatetag_mod = __import__(app + '.templatetags', {}, {}, [''])
except ImportError:
continue
mod_path = inspect.getabsfile(templatetag_mod)
mod_files = os.listdir(os.path.dirname(mod_path))
tag_files = [i.rstrip('.py') for i in mod_files if i.endswith('.py') and i[0] != '_']
app_labeled = False
for taglib in tag_files:
lib = load_tag_library(taglib)
if lib is None:
continue
mod_path = inspect.getabsfile(templatetag_mod)
mod_files = os.listdir(os.path.dirname(mod_path))
tag_files = [i.rstrip('.py') for i in mod_files if i.endswith('.py') and i[0] != '_']
app_labeled = False
for taglib in tag_files:
lib = load_tag_library(taglib)
if lib is None:
continue

if not app_labeled:
self.add_result('App: %s' % style.MODULE_NAME(app))
app_labeled = True
self.add_result('load: %s' % style.TAGLIB(taglib), 1)
libstuff = [
(lib.tags, 'Tag:', style.TAG),
(lib.filters, 'Filter:', style.FILTER)
]
for items, label, style_func in libstuff:
for item in items:
self.add_result('%s %s' % (label, style_func(item)), 2)
doc = inspect.getdoc(items[item])
if doc:
self.add_result(format_block(doc, 12))

if not app_labeled:
self.add_result('App: %s' % style.MODULE_NAME(app))
app_labeled = True
self.add_result('load: %s' % style.TAGLIB(taglib), 1)
libstuff = [
(lib.tags, 'Tag:', style.TAG),
(lib.filters, 'Filter:', style.FILTER)
]
for items, label, style_func in libstuff:
for item in items:
self.add_result('%s %s' % (label, style_func(item)), 2)
doc = inspect.getdoc(items[item])
if doc:
self.add_result(format_block(doc, 12))
return self.results

0 comments on commit ddf93b3

Please sign in to comment.