-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
299 additions
and
86 deletions.
There are no files selected for viewing
Empty file.
Empty file.
36 changes: 36 additions & 0 deletions
36
example_project/example/management/commands/showtemplates.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""A management command to list all templates in the project.""" | ||
import os | ||
from importlib import import_module | ||
|
||
from django.conf import settings | ||
from django.core.management.base import BaseCommand | ||
from django.template.loader import get_template | ||
|
||
|
||
class Command(BaseCommand): | ||
"""A management command to list all templates in the project.""" | ||
help = "List all templates" | ||
|
||
def handle(self, *args, **options): | ||
templates = [] | ||
for app in settings.INSTALLED_APPS: | ||
try: | ||
app_module = import_module(app) | ||
app_dir = os.path.dirname(app_module.__file__) | ||
templates_dir = os.path.join(app_dir, 'templates') | ||
|
||
if os.path.exists(templates_dir): | ||
for root, _, files in os.walk(templates_dir): | ||
for file in files: | ||
templated_email_file_extension = getattr(settings, 'TEMPLATED_EMAIL_FILE_EXTENSION', 'md') | ||
if file.endswith('.html') or file.endswith(f'.{templated_email_file_extension}'): | ||
template_path = os.path.join(root, file) | ||
try: | ||
get_template(template_path) | ||
templates.append(template_path) | ||
except Exception: | ||
pass | ||
except ImportError: | ||
pass | ||
|
||
self.stdout.write('\n'.join(templates)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"""App configuration for templated_email_md.""" | ||
|
||
from django.apps import AppConfig | ||
|
||
|
||
class TemplatedEmailMdConfig(AppConfig): | ||
"""App configuration for templated_email_md.""" | ||
|
||
name = "templated_email_md" | ||
verbose_name = "Templated Email Markdown" |
Oops, something went wrong.