django-components 0.51__tar.gz → 0.52__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_components-0.51 → django_components-0.52}/PKG-INFO +1 -1
- {django_components-0.51 → django_components-0.52}/django_components/__init__.py +3 -1
- {django_components-0.51 → django_components-0.52}/django_components/component.py +13 -13
- {django_components-0.51 → django_components-0.52}/django_components/templatetags/component_tags.py +24 -13
- {django_components-0.51 → django_components-0.52}/django_components/types.py +3 -3
- {django_components-0.51 → django_components-0.52}/django_components.egg-info/PKG-INFO +1 -1
- {django_components-0.51 → django_components-0.52}/pyproject.toml +7 -0
- {django_components-0.51 → django_components-0.52}/setup.py +4 -1
- {django_components-0.51 → django_components-0.52}/tests/test_context.py +4 -0
- {django_components-0.51 → django_components-0.52}/tests/test_templatetags.py +2 -2
- {django_components-0.51 → django_components-0.52}/LICENSE +0 -0
- {django_components-0.51 → django_components-0.52}/README.md +0 -0
- {django_components-0.51 → django_components-0.52}/django_components/app_settings.py +0 -0
- {django_components-0.51 → django_components-0.52}/django_components/apps.py +0 -0
- {django_components-0.51 → django_components-0.52}/django_components/component_registry.py +0 -0
- {django_components-0.51 → django_components-0.52}/django_components/management/__init__.py +0 -0
- {django_components-0.51 → django_components-0.52}/django_components/management/commands/__init__.py +0 -0
- {django_components-0.51 → django_components-0.52}/django_components/management/commands/startcomponent.py +0 -0
- {django_components-0.51 → django_components-0.52}/django_components/management/commands/upgradecomponent.py +0 -0
- {django_components-0.51 → django_components-0.52}/django_components/middleware.py +0 -0
- {django_components-0.51 → django_components-0.52}/django_components/safer_staticfiles/__init__.py +0 -0
- {django_components-0.51 → django_components-0.52}/django_components/safer_staticfiles/apps.py +0 -0
- {django_components-0.51 → django_components-0.52}/django_components/template_loader.py +0 -0
- {django_components-0.51 → django_components-0.52}/django_components/templatetags/__init__.py +0 -0
- {django_components-0.51 → django_components-0.52}/django_components.egg-info/SOURCES.txt +0 -0
- {django_components-0.51 → django_components-0.52}/django_components.egg-info/dependency_links.txt +0 -0
- {django_components-0.51 → django_components-0.52}/django_components.egg-info/requires.txt +0 -0
- {django_components-0.51 → django_components-0.52}/django_components.egg-info/top_level.txt +0 -0
- {django_components-0.51 → django_components-0.52}/setup.cfg +0 -0
- {django_components-0.51 → django_components-0.52}/tests/components/__init__.py +0 -0
- {django_components-0.51 → django_components-0.52}/tests/components/single_file.py +0 -0
- {django_components-0.51 → django_components-0.52}/tests/components/urls.py +0 -0
- {django_components-0.51 → django_components-0.52}/tests/test_autodiscover.py +0 -0
- {django_components-0.51 → django_components-0.52}/tests/test_component.py +0 -0
- {django_components-0.51 → django_components-0.52}/tests/test_component_as_view.py +0 -0
- {django_components-0.51 → django_components-0.52}/tests/test_dependency_rendering.py +0 -0
- {django_components-0.51 → django_components-0.52}/tests/test_registry.py +0 -0
- {django_components-0.51 → django_components-0.52}/tests/test_settings.py +0 -0
- {django_components-0.51 → django_components-0.52}/tests/test_startcomponent_command.py +0 -0
- {django_components-0.51 → django_components-0.52}/tests/testutils.py +0 -0
|
@@ -37,6 +37,8 @@ def import_file(path):
|
|
|
37
37
|
MODULE_PATH = path
|
|
38
38
|
MODULE_NAME = Path(path).stem
|
|
39
39
|
spec = importlib.util.spec_from_file_location(MODULE_NAME, MODULE_PATH)
|
|
40
|
+
if spec is None:
|
|
41
|
+
raise ValueError(f"Cannot import file '{path}' - invalid path")
|
|
40
42
|
module = importlib.util.module_from_spec(spec)
|
|
41
43
|
sys.modules[spec.name] = module
|
|
42
|
-
spec.loader.exec_module(module)
|
|
44
|
+
spec.loader.exec_module(module) # type: ignore
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import difflib
|
|
2
2
|
import inspect
|
|
3
3
|
from collections import ChainMap
|
|
4
|
-
from typing import Any, ClassVar, Dict, Iterable, Optional, Set, Tuple, Union
|
|
4
|
+
from typing import Any, ClassVar, Dict, Iterable, List, Optional, Set, Tuple, Union
|
|
5
5
|
|
|
6
6
|
from django.core.exceptions import ImproperlyConfigured
|
|
7
7
|
from django.forms.widgets import Media, MediaDefiningClass
|
|
@@ -40,7 +40,7 @@ from django_components.templatetags.component_tags import (
|
|
|
40
40
|
class SimplifiedInterfaceMediaDefiningClass(MediaDefiningClass):
|
|
41
41
|
def __new__(mcs, name, bases, attrs):
|
|
42
42
|
if "Media" in attrs:
|
|
43
|
-
media = attrs["Media"]
|
|
43
|
+
media: Component.Media = attrs["Media"]
|
|
44
44
|
|
|
45
45
|
# Allow: class Media: css = "style.css"
|
|
46
46
|
if hasattr(media, "css") and isinstance(media.css, str):
|
|
@@ -54,7 +54,7 @@ class SimplifiedInterfaceMediaDefiningClass(MediaDefiningClass):
|
|
|
54
54
|
if hasattr(media, "css") and isinstance(media.css, dict):
|
|
55
55
|
for media_type, path_list in media.css.items():
|
|
56
56
|
if isinstance(path_list, str):
|
|
57
|
-
media.css[media_type] = [path_list]
|
|
57
|
+
media.css[media_type] = [path_list] # type: ignore
|
|
58
58
|
|
|
59
59
|
# Allow: class Media: js = "script.js"
|
|
60
60
|
if hasattr(media, "js") and isinstance(media.js, str):
|
|
@@ -67,20 +67,20 @@ class Component(View, metaclass=SimplifiedInterfaceMediaDefiningClass):
|
|
|
67
67
|
# Either template_name or template must be set on subclass OR subclass must implement get_template() with
|
|
68
68
|
# non-null return.
|
|
69
69
|
template_name: ClassVar[Optional[str]] = None
|
|
70
|
-
template:
|
|
71
|
-
js:
|
|
72
|
-
css:
|
|
70
|
+
template: Optional[str] = None
|
|
71
|
+
js: Optional[str] = None
|
|
72
|
+
css: Optional[str] = None
|
|
73
73
|
media: Media
|
|
74
74
|
|
|
75
75
|
class Media:
|
|
76
|
-
css =
|
|
77
|
-
js
|
|
76
|
+
css: Optional[Union[str, List[str], Dict[str, str], Dict[str, List[str]]]] = None
|
|
77
|
+
js: Optional[Union[str, List[str]]] = None
|
|
78
78
|
|
|
79
79
|
def __init__(
|
|
80
80
|
self,
|
|
81
81
|
registered_name: Optional[str] = None,
|
|
82
82
|
outer_context: Optional[Context] = None,
|
|
83
|
-
fill_content: Union[DefaultFillContent, Iterable[NamedFillContent]] = (),
|
|
83
|
+
fill_content: Union[DefaultFillContent, Iterable[NamedFillContent]] = (), # type: ignore
|
|
84
84
|
):
|
|
85
85
|
self.registered_name: Optional[str] = registered_name
|
|
86
86
|
self.outer_context: Context = outer_context or Context()
|
|
@@ -142,7 +142,7 @@ class Component(View, metaclass=SimplifiedInterfaceMediaDefiningClass):
|
|
|
142
142
|
self,
|
|
143
143
|
context_data: Dict[str, Any],
|
|
144
144
|
slots_data: Optional[Dict[SlotName, str]] = None,
|
|
145
|
-
escape_slots_content:
|
|
145
|
+
escape_slots_content: bool = True,
|
|
146
146
|
) -> str:
|
|
147
147
|
context = Context(context_data)
|
|
148
148
|
template = self.get_template(context)
|
|
@@ -160,7 +160,7 @@ class Component(View, metaclass=SimplifiedInterfaceMediaDefiningClass):
|
|
|
160
160
|
self,
|
|
161
161
|
context_data: Dict[str, Any],
|
|
162
162
|
slots_data: Optional[Dict[SlotName, str]] = None,
|
|
163
|
-
escape_slots_content:
|
|
163
|
+
escape_slots_content: bool = True,
|
|
164
164
|
*args,
|
|
165
165
|
**kwargs,
|
|
166
166
|
):
|
|
@@ -173,7 +173,7 @@ class Component(View, metaclass=SimplifiedInterfaceMediaDefiningClass):
|
|
|
173
173
|
def _fill_slots(
|
|
174
174
|
self,
|
|
175
175
|
slots_data: Dict[SlotName, str],
|
|
176
|
-
escape_content: bool,
|
|
176
|
+
escape_content: bool = True,
|
|
177
177
|
):
|
|
178
178
|
"""Fill component slots outside of template rendering."""
|
|
179
179
|
self.fill_content = [
|
|
@@ -195,7 +195,7 @@ class Component(View, metaclass=SimplifiedInterfaceMediaDefiningClass):
|
|
|
195
195
|
named_fills_content = {}
|
|
196
196
|
else:
|
|
197
197
|
default_fill_content = None
|
|
198
|
-
named_fills_content = {name: (nodelist, alias) for name, nodelist, alias in self.fill_content}
|
|
198
|
+
named_fills_content = {name: (nodelist, alias) for name, nodelist, alias in list(self.fill_content)}
|
|
199
199
|
|
|
200
200
|
# If value is `None`, then slot is unfilled.
|
|
201
201
|
slot_name2fill_content: Dict[SlotName, Optional[FillContent]] = {}
|
{django_components-0.51 → django_components-0.52}/django_components/templatetags/component_tags.py
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import sys
|
|
2
|
-
from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple, Type, Union
|
|
2
|
+
from typing import TYPE_CHECKING, Iterable, List, Optional, Set, Tuple, Type, Union
|
|
3
3
|
|
|
4
4
|
if sys.version_info[:2] < (3, 9):
|
|
5
5
|
from typing import ChainMap
|
|
@@ -194,7 +194,7 @@ class SlotNode(Node, TemplateAwareNodeMixin):
|
|
|
194
194
|
|
|
195
195
|
extra_context = {}
|
|
196
196
|
try:
|
|
197
|
-
slot_fill_content:
|
|
197
|
+
slot_fill_content: FillContent = filled_slots_map[(self.name, self.template)]
|
|
198
198
|
except KeyError:
|
|
199
199
|
if self.is_required:
|
|
200
200
|
raise TemplateSyntaxError(
|
|
@@ -375,16 +375,17 @@ class ComponentNode(Node):
|
|
|
375
375
|
# Note that outer component context is used to resolve variables in
|
|
376
376
|
# fill tag.
|
|
377
377
|
resolved_name = fill_node.name_fexp.resolve(context)
|
|
378
|
+
resolved_alias: Optional[str]
|
|
378
379
|
if fill_node.alias_fexp:
|
|
379
|
-
resolved_alias
|
|
380
|
-
if not resolved_alias.isidentifier():
|
|
380
|
+
resolved_alias = fill_node.alias_fexp.resolve(context)
|
|
381
|
+
if resolved_alias and not resolved_alias.isidentifier():
|
|
381
382
|
raise TemplateSyntaxError(
|
|
382
383
|
f"Fill tag alias '{fill_node.alias_fexp.var}' in component "
|
|
383
384
|
f"{resolved_component_name} does not resolve to "
|
|
384
385
|
f"a valid Python identifier. Got: '{resolved_alias}'."
|
|
385
386
|
)
|
|
386
387
|
else:
|
|
387
|
-
resolved_alias
|
|
388
|
+
resolved_alias = None
|
|
388
389
|
fill_content.append((resolved_name, fill_node.nodelist, resolved_alias))
|
|
389
390
|
|
|
390
391
|
component: Component = component_cls(
|
|
@@ -426,14 +427,15 @@ def do_component(parser, token):
|
|
|
426
427
|
component_name, context_args, context_kwargs = parse_component_with_args(parser, bits, "component")
|
|
427
428
|
body: NodeList = parser.parse(parse_until=["endcomponent"])
|
|
428
429
|
parser.delete_first_token()
|
|
429
|
-
fill_nodes =
|
|
430
|
+
fill_nodes: Union[Iterable[NamedFillNode], ImplicitFillNode] = []
|
|
430
431
|
if block_has_content(body):
|
|
431
432
|
for parse_fn in (
|
|
432
433
|
try_parse_as_default_fill,
|
|
433
434
|
try_parse_as_named_fill_tag_set,
|
|
434
435
|
):
|
|
435
|
-
|
|
436
|
-
if
|
|
436
|
+
curr_fill_nodes = parse_fn(body)
|
|
437
|
+
if curr_fill_nodes:
|
|
438
|
+
fill_nodes = curr_fill_nodes
|
|
437
439
|
break
|
|
438
440
|
else:
|
|
439
441
|
raise TemplateSyntaxError(
|
|
@@ -457,7 +459,7 @@ def try_parse_as_named_fill_tag_set(
|
|
|
457
459
|
nodelist: NodeList,
|
|
458
460
|
) -> Optional[Iterable[NamedFillNode]]:
|
|
459
461
|
result = []
|
|
460
|
-
seen_name_fexps = set()
|
|
462
|
+
seen_name_fexps: Set[FilterExpression] = set()
|
|
461
463
|
for node in nodelist:
|
|
462
464
|
if isinstance(node, NamedFillNode):
|
|
463
465
|
if node.name_fexp in seen_name_fexps:
|
|
@@ -465,6 +467,7 @@ def try_parse_as_named_fill_tag_set(
|
|
|
465
467
|
f"Multiple fill tags cannot target the same slot name: "
|
|
466
468
|
f"Detected duplicate fill tag name '{node.name_fexp}'."
|
|
467
469
|
)
|
|
470
|
+
seen_name_fexps.add(node.name_fexp)
|
|
468
471
|
result.append(node)
|
|
469
472
|
elif isinstance(node, CommentNode):
|
|
470
473
|
pass
|
|
@@ -544,9 +547,13 @@ def do_if_filled_block(parser, token):
|
|
|
544
547
|
bits = token.split_contents()
|
|
545
548
|
starting_tag = bits[0]
|
|
546
549
|
slot_name, is_positive = parse_if_filled_bits(bits)
|
|
547
|
-
nodelist = parser.parse(("elif_filled", "else_filled", "endif_filled"))
|
|
550
|
+
nodelist: NodeList = parser.parse(("elif_filled", "else_filled", "endif_filled"))
|
|
548
551
|
branches: List[_IfSlotFilledBranchNode] = [
|
|
549
|
-
IfSlotFilledConditionBranchNode(
|
|
552
|
+
IfSlotFilledConditionBranchNode(
|
|
553
|
+
slot_name=slot_name, # type: ignore
|
|
554
|
+
nodelist=nodelist,
|
|
555
|
+
is_positive=is_positive,
|
|
556
|
+
)
|
|
550
557
|
]
|
|
551
558
|
|
|
552
559
|
token = parser.next_token()
|
|
@@ -555,9 +562,13 @@ def do_if_filled_block(parser, token):
|
|
|
555
562
|
while token.contents.startswith("elif_filled"):
|
|
556
563
|
bits = token.split_contents()
|
|
557
564
|
slot_name, is_positive = parse_if_filled_bits(bits)
|
|
558
|
-
nodelist
|
|
565
|
+
nodelist = parser.parse(("elif_filled", "else_filled", "endif_filled"))
|
|
559
566
|
branches.append(
|
|
560
|
-
IfSlotFilledConditionBranchNode(
|
|
567
|
+
IfSlotFilledConditionBranchNode(
|
|
568
|
+
slot_name=slot_name, # type: ignore
|
|
569
|
+
nodelist=nodelist,
|
|
570
|
+
is_positive=is_positive,
|
|
571
|
+
)
|
|
561
572
|
)
|
|
562
573
|
|
|
563
574
|
token = parser.next_token()
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
try:
|
|
2
|
-
from typing import Annotated
|
|
2
|
+
from typing import Annotated # type: ignore
|
|
3
3
|
except ImportError:
|
|
4
4
|
|
|
5
|
-
class Annotated:
|
|
5
|
+
class Annotated: # type: ignore
|
|
6
6
|
def __init__(self, type_, *args, **kwargs):
|
|
7
7
|
self.type_ = type_
|
|
8
8
|
self.metadata = args, kwargs
|
|
@@ -13,7 +13,7 @@ except ImportError:
|
|
|
13
13
|
def __getitem__(self, params):
|
|
14
14
|
if not isinstance(params, tuple):
|
|
15
15
|
params = (params,)
|
|
16
|
-
return Annotated(self.type_, *params, **self.metadata[1])
|
|
16
|
+
return Annotated(self.type_, *params, **self.metadata[1]) # type: ignore
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
css = Annotated[str, "css"]
|
|
@@ -3,11 +3,14 @@ import os
|
|
|
3
3
|
|
|
4
4
|
from setuptools import find_packages, setup
|
|
5
5
|
|
|
6
|
-
VERSION = "0.
|
|
6
|
+
VERSION = "0.52"
|
|
7
7
|
|
|
8
8
|
setup(
|
|
9
9
|
name="django_components",
|
|
10
10
|
packages=find_packages(exclude=["tests"]),
|
|
11
|
+
package_data={
|
|
12
|
+
"django_components": ["py.typed"],
|
|
13
|
+
},
|
|
11
14
|
version=VERSION,
|
|
12
15
|
description="A way to create simple reusable template components in Django.",
|
|
13
16
|
long_description=open(os.path.join(os.path.dirname(__file__), "README.md"), encoding="utf8").read(),
|
|
@@ -48,6 +48,10 @@ class VariableDisplay(component.Component):
|
|
|
48
48
|
class IncrementerComponent(component.Component):
|
|
49
49
|
template_name = "incrementer.html"
|
|
50
50
|
|
|
51
|
+
def __init__(self, *args, **kwargs):
|
|
52
|
+
super().__init__(*args, **kwargs)
|
|
53
|
+
self.call_count = 0
|
|
54
|
+
|
|
51
55
|
def get_context_data(self, value=0):
|
|
52
56
|
value = int(value)
|
|
53
57
|
if hasattr(self, "call_count"):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import re
|
|
2
2
|
import textwrap
|
|
3
|
-
from typing import Callable,
|
|
3
|
+
from typing import Callable, Optional
|
|
4
4
|
|
|
5
5
|
from django.template import Context, Template, TemplateSyntaxError
|
|
6
6
|
|
|
@@ -1250,7 +1250,7 @@ class IterationFillTest(SimpleTestCase):
|
|
|
1250
1250
|
class ComponentSimpleSlotInALoop(django_components.component.Component):
|
|
1251
1251
|
template_name = "template_with_slot_in_a_loop.html"
|
|
1252
1252
|
|
|
1253
|
-
def get_context_data(self, objects
|
|
1253
|
+
def get_context_data(self, objects, *args, **kwargs) -> dict:
|
|
1254
1254
|
return {
|
|
1255
1255
|
"objects": objects,
|
|
1256
1256
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.51 → django_components-0.52}/django_components/management/commands/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.51 → django_components-0.52}/django_components/safer_staticfiles/__init__.py
RENAMED
|
File without changes
|
{django_components-0.51 → django_components-0.52}/django_components/safer_staticfiles/apps.py
RENAMED
|
File without changes
|
|
File without changes
|
{django_components-0.51 → django_components-0.52}/django_components/templatetags/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{django_components-0.51 → django_components-0.52}/django_components.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|