Skip to content

Commit b9e1792

Browse files
committed
fixes widget listing
1 parent 0f22fe8 commit b9e1792

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

jssg/management/commands/list-widgets.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from django.core.management import call_command
33
from django.core.management.base import BaseCommand
44
from jinja2.nodes import Macro
5-
6-
from jssg.jinja2 import Environment
5+
from django.template import engines
76

87

98
class Command(BaseCommand):
@@ -46,31 +45,36 @@ def handle(self, *args, **options):
4645
nb_file_found = 0
4746
nb_macro_found = 0
4847
visited = []
48+
49+
jinja_engine = engines['jinja2']
50+
jinja2_env = jinja_engine.env
51+
4952
for template_dir in settings.JFME_TEMPLATES_DIRS:
5053
for widget in (template_dir / "jinja2" / "widgets").rglob("*"):
5154
rel_widget_path = widget.relative_to(template_dir.parent.parent)
5255
if widget.is_file():
5356
with open(widget, "r") as w:
5457
self.stdout.write("%s" % str(rel_widget_path))
5558
nb_file_found += 1
56-
for macro in Environment().parse(w.read()).find_all(Macro):
59+
60+
for macro in jinja2_env.parse(w.read()).find_all(Macro):
5761
visited.append(
5862
(widget.stem, macro.name, rel_widget_path)
5963
)
6064
self.stdout.write("\t%s()" % macro.name)
6165
nb_macro_found += 1
62-
6366
self.stdout.write(
6467
self.style.HTTP_INFO(
65-
"%d jinja2 widget %s found (%d %s)"
68+
"%d jinja2 %s found in %d %s."
6669
% (
67-
nb_file_found,
68-
"file" if nb_file_found <= 1 else "files",
6970
nb_macro_found,
7071
"macro" if nb_file_found <= 1 else "macros",
72+
nb_file_found,
73+
"file" if nb_file_found <= 1 else "files",
7174
)
7275
)
7376
)
77+
7478
couple_visited = [(x[0], x[1]) for x in visited]
7579
duplicates = set(
7680
[t for t in couple_visited if couple_visited.count(t) > 1]

0 commit comments

Comments
 (0)