mirror of
https://github.com/django-components/django-components.git
synced 2025-08-15 11:40:14 +00:00
Resolve media and template files relative to component class dir (#395), thanks @JuroOravec
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Emil Stenström <emil@emilstenstrom.se>
This commit is contained in:
parent
1de859bd34
commit
37fd901908
21 changed files with 477 additions and 43 deletions
|
@ -1,14 +1,12 @@
|
|||
import glob
|
||||
import importlib
|
||||
import importlib.util
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import django
|
||||
from django.template.engine import Engine
|
||||
from django.utils.module_loading import autodiscover_modules
|
||||
|
||||
from django_components.template_loader import Loader
|
||||
from django_components.utils.autodiscover import search
|
||||
|
||||
if django.VERSION < (3, 2):
|
||||
default_app_config = "django_components.apps.ComponentsConfig"
|
||||
|
@ -22,12 +20,9 @@ def autodiscover():
|
|||
autodiscover_modules("components")
|
||||
|
||||
# Autodetect a <component>.py file in a components dir
|
||||
current_engine = Engine.get_default()
|
||||
loader = Loader(current_engine)
|
||||
dirs = loader.get_dirs()
|
||||
for directory in dirs:
|
||||
for path in glob.iglob(str(directory / "**/*.py"), recursive=True):
|
||||
import_file(path)
|
||||
component_filepaths = search(search_glob="**/*.py")
|
||||
for path in component_filepaths:
|
||||
import_file(path)
|
||||
|
||||
for path in app_settings.LIBRARIES:
|
||||
importlib.import_module(path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue