mirror of
https://github.com/wrabit/django-cotton.git
synced 2025-08-03 14:48:17 +00:00
wip
This commit is contained in:
parent
4e7e7d62b5
commit
d5651d8b9b
13 changed files with 43 additions and 1 deletions
|
@ -39,6 +39,7 @@ INSTALLED_APPS = [
|
|||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"django_cotton",
|
||||
"unspecified_app_directory",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
|
3
dev/example_project/unspecified_app_directory/admin.py
Normal file
3
dev/example_project/unspecified_app_directory/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
dev/example_project/unspecified_app_directory/apps.py
Normal file
6
dev/example_project/unspecified_app_directory/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UnspecifiedAppDirectoryConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'unspecified_app_directory'
|
3
dev/example_project/unspecified_app_directory/models.py
Normal file
3
dev/example_project/unspecified_app_directory/models.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
|
@ -0,0 +1 @@
|
|||
My template was not specified in settings!
|
|
@ -0,0 +1 @@
|
|||
<c-unspecified-component />
|
3
dev/example_project/unspecified_app_directory/tests.py
Normal file
3
dev/example_project/unspecified_app_directory/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
3
dev/example_project/unspecified_app_directory/views.py
Normal file
3
dev/example_project/unspecified_app_directory/views.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
|
@ -13,6 +13,7 @@ from django.template import Template
|
|||
from django.core.cache import cache
|
||||
from django.template import Origin
|
||||
from django.conf import settings
|
||||
from django.apps import apps
|
||||
|
||||
from bs4 import BeautifulSoup, MarkupResemblesLocatorWarning
|
||||
|
||||
|
@ -60,7 +61,15 @@ class Loader(BaseLoader):
|
|||
raise TemplateDoesNotExist(template_name)
|
||||
|
||||
def get_dirs(self):
|
||||
return self.dirs if self.dirs is not None else self.engine.dirs
|
||||
dirs = self.dirs if self.dirs is not None else self.engine.dirs
|
||||
|
||||
# Add app-specific template directories
|
||||
for app_config in apps.get_app_configs():
|
||||
template_dir = os.path.join(app_config.path, "templates")
|
||||
if os.path.isdir(template_dir):
|
||||
dirs.append(template_dir)
|
||||
|
||||
return dirs
|
||||
|
||||
def get_template_sources(self, template_name):
|
||||
"""Return an Origin object pointing to an absolute path in each directory
|
||||
|
|
|
@ -352,3 +352,11 @@ class CottonTestCase(TestCase):
|
|||
response,
|
||||
"""attrs tag is: 'normal="normal" attr1="Hello Will" attr2="world" attr3="cowabonga!"'""",
|
||||
)
|
||||
|
||||
def test_loader_scans_all_app_directories(self):
|
||||
response = self.client.get("/test/unspecified-app-directory-template")
|
||||
|
||||
self.assertContains(
|
||||
response,
|
||||
"""My template was not specified in settings!""",
|
||||
)
|
||||
|
|
|
@ -50,4 +50,8 @@ urlpatterns = [
|
|||
"test/native-tags-in-attributes",
|
||||
TemplateView.as_view(template_name="native_tags_in_attributes_view.html"),
|
||||
),
|
||||
path(
|
||||
"test/unspecified-app-directory-template",
|
||||
TemplateView.as_view(template_name="unspecified_view.html"),
|
||||
),
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue