Skip to content

Commit

Permalink
Major refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jacklinke committed Oct 22, 2024
1 parent 4bf6868 commit 0857add
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 86 deletions.
Empty file.
Empty file.
36 changes: 36 additions & 0 deletions example_project/example/management/commands/showtemplates.py
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))
1 change: 1 addition & 0 deletions example_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"anymail",
"templated_email_md",
"example_project.example",
]

Expand Down
12 changes: 2 additions & 10 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,10 @@ def safety(session: Session, django: str) -> None:
@nox.parametrize("django", DJANGO_VERSIONS)
def tests(session: Session, django: str) -> None:
"""Run the test suite."""
session.install(f"django=={django}")
session.install(".")
session.install(
"coverage[toml]",
"pytest",
"pytest-django",
"requests",
"pygments",
)
session.run("uv", "sync", "--prerelease=allow", "--extra=dev")
try:

session.run("coverage", "run", "-m", "pytest", *session.posargs)
session.run("coverage", "run", "-m", "pytest", "-vv", *session.posargs)
finally:
if session.interactive:
session.notify("coverage", posargs=[])
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies = [
"premailer~=3.10",
"html2text~=2024.2",
"django-templated-email~=3.0",
"django-render-block~=0.8",
]

[project.urls]
Expand Down Expand Up @@ -73,7 +74,8 @@ dev-dependencies = [
"xdoctest[colors]>=1.1.3",
"myst-parser>=4.0.0",
"linkify-it-py==2.0.3",
"python-environ>=0.4.54",
"django-anymail~=12.0",
"python-environ~=0.4",
]

[tool.black]
Expand Down
10 changes: 10 additions & 0 deletions src/templated_email_md/apps.py
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"
Loading

0 comments on commit 0857add

Please sign in to comment.