mirror of
https://github.com/django-components/django-components.git
synced 2025-09-26 15:39:08 +00:00
Caching templates to allow for dynamic template generation
Co-authored-by: rbeard0330 <@dul2k3BKW6m>
This commit is contained in:
parent
3919943cbd
commit
07986c5216
9 changed files with 36 additions and 17 deletions
|
@ -10,7 +10,10 @@ if not settings.configured:
|
|||
TEMPLATES=[{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': ["tests/templates/"],
|
||||
}]
|
||||
}],
|
||||
COMPONENTS={
|
||||
'TEMPLATE_CACHE_SIZE': 128
|
||||
},
|
||||
)
|
||||
else:
|
||||
settings.configure(
|
||||
|
|
|
@ -2,11 +2,11 @@ from textwrap import dedent
|
|||
|
||||
from django.template import Context
|
||||
|
||||
from django_components import component
|
||||
|
||||
from .django_test_setup import * # NOQA
|
||||
from .testutils import Django111CompatibleSimpleTestCase as SimpleTestCase
|
||||
|
||||
from django_components import component
|
||||
|
||||
|
||||
class ComponentRegistryTest(SimpleTestCase):
|
||||
def test_empty_component(self):
|
||||
|
@ -32,7 +32,6 @@ class ComponentRegistryTest(SimpleTestCase):
|
|||
|
||||
comp = SimpleComponent("simple_component")
|
||||
context = Context(comp.context(variable="test"))
|
||||
comp.compile_instance_template({})
|
||||
|
||||
self.assertHTMLEqual(comp.render_dependencies(), dedent("""
|
||||
<link href="style.css" type="text/css" media="all" rel="stylesheet">
|
||||
|
@ -71,7 +70,6 @@ class ComponentRegistryTest(SimpleTestCase):
|
|||
|
||||
comp = FilteredComponent("filtered_component")
|
||||
context = Context(comp.context(var1="test1", var2="test2"))
|
||||
comp.compile_instance_template({})
|
||||
|
||||
self.assertHTMLEqual(comp.render(context), dedent("""
|
||||
Var1: <strong>test1</strong>
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
from django.template import Context, Template
|
||||
|
||||
from .django_test_setup import * # NOQA
|
||||
|
||||
from django_components import component
|
||||
|
||||
from .django_test_setup import * # NOQA
|
||||
from .testutils import Django111CompatibleSimpleTestCase as SimpleTestCase
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import unittest
|
||||
|
||||
from .django_test_setup import * # NOQA
|
||||
from django_components import component
|
||||
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@ from textwrap import dedent
|
|||
|
||||
from django.template import Context, Template
|
||||
|
||||
from .django_test_setup import * # NOQA
|
||||
from django_components import component
|
||||
|
||||
from .django_test_setup import * # NOQA
|
||||
from .testutils import Django111CompatibleSimpleTestCase as SimpleTestCase
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from django import setup
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
|
||||
|
@ -5,3 +6,5 @@ class Django111CompatibleSimpleTestCase(SimpleTestCase):
|
|||
def assertHTMLEqual(self, left, right):
|
||||
left = left.replace(' type="text/javascript"', '')
|
||||
super(Django111CompatibleSimpleTestCase, self).assertHTMLEqual(left, right)
|
||||
|
||||
setup()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue