django-components 0.113__tar.gz → 0.115__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.
Files changed (54) hide show
  1. {django_components-0.113/src/django_components.egg-info → django_components-0.115}/PKG-INFO +3 -1
  2. {django_components-0.113 → django_components-0.115}/pyproject.toml +3 -1
  3. {django_components-0.113 → django_components-0.115}/src/django_components/component.py +35 -1
  4. {django_components-0.113 → django_components-0.115}/src/django_components/component_media.py +9 -6
  5. {django_components-0.113 → django_components-0.115}/src/django_components/components/dynamic.py +10 -0
  6. {django_components-0.113 → django_components-0.115}/src/django_components/slots.py +6 -0
  7. {django_components-0.113 → django_components-0.115}/src/django_components/util/loader.py +5 -7
  8. {django_components-0.113 → django_components-0.115/src/django_components.egg-info}/PKG-INFO +3 -1
  9. {django_components-0.113 → django_components-0.115}/LICENSE +0 -0
  10. {django_components-0.113 → django_components-0.115}/MANIFEST.in +0 -0
  11. {django_components-0.113 → django_components-0.115}/README.md +0 -0
  12. {django_components-0.113 → django_components-0.115}/setup.cfg +0 -0
  13. {django_components-0.113 → django_components-0.115}/src/django_components/__init__.py +0 -0
  14. {django_components-0.113 → django_components-0.115}/src/django_components/app_settings.py +0 -0
  15. {django_components-0.113 → django_components-0.115}/src/django_components/apps.py +0 -0
  16. {django_components-0.113 → django_components-0.115}/src/django_components/attributes.py +0 -0
  17. {django_components-0.113 → django_components-0.115}/src/django_components/autodiscovery.py +0 -0
  18. {django_components-0.113 → django_components-0.115}/src/django_components/component_registry.py +0 -0
  19. {django_components-0.113 → django_components-0.115}/src/django_components/components/__init__.py +0 -0
  20. {django_components-0.113 → django_components-0.115}/src/django_components/context.py +0 -0
  21. {django_components-0.113 → django_components-0.115}/src/django_components/dependencies.py +0 -0
  22. {django_components-0.113 → django_components-0.115}/src/django_components/expression.py +0 -0
  23. {django_components-0.113 → django_components-0.115}/src/django_components/finders.py +0 -0
  24. {django_components-0.113 → django_components-0.115}/src/django_components/library.py +0 -0
  25. {django_components-0.113 → django_components-0.115}/src/django_components/management/__init__.py +0 -0
  26. {django_components-0.113 → django_components-0.115}/src/django_components/management/commands/__init__.py +0 -0
  27. {django_components-0.113 → django_components-0.115}/src/django_components/management/commands/startcomponent.py +0 -0
  28. {django_components-0.113 → django_components-0.115}/src/django_components/management/commands/upgradecomponent.py +0 -0
  29. {django_components-0.113 → django_components-0.115}/src/django_components/middleware.py +0 -0
  30. {django_components-0.113 → django_components-0.115}/src/django_components/node.py +0 -0
  31. {django_components-0.113 → django_components-0.115}/src/django_components/provide.py +0 -0
  32. {django_components-0.113 → django_components-0.115}/src/django_components/py.typed +0 -0
  33. {django_components-0.113 → django_components-0.115}/src/django_components/static/django_components/django_components.min.js +0 -0
  34. {django_components-0.113 → django_components-0.115}/src/django_components/tag_formatter.py +0 -0
  35. {django_components-0.113 → django_components-0.115}/src/django_components/template.py +0 -0
  36. {django_components-0.113 → django_components-0.115}/src/django_components/template_loader.py +0 -0
  37. {django_components-0.113 → django_components-0.115}/src/django_components/template_parser.py +0 -0
  38. {django_components-0.113 → django_components-0.115}/src/django_components/templatetags/__init__.py +0 -0
  39. {django_components-0.113 → django_components-0.115}/src/django_components/templatetags/component_tags.py +0 -0
  40. {django_components-0.113 → django_components-0.115}/src/django_components/types.py +0 -0
  41. {django_components-0.113 → django_components-0.115}/src/django_components/urls.py +0 -0
  42. {django_components-0.113 → django_components-0.115}/src/django_components/util/__init__.py +0 -0
  43. {django_components-0.113 → django_components-0.115}/src/django_components/util/cache.py +0 -0
  44. {django_components-0.113 → django_components-0.115}/src/django_components/util/html.py +0 -0
  45. {django_components-0.113 → django_components-0.115}/src/django_components/util/logger.py +0 -0
  46. {django_components-0.113 → django_components-0.115}/src/django_components/util/misc.py +0 -0
  47. {django_components-0.113 → django_components-0.115}/src/django_components/util/nanoid.py +0 -0
  48. {django_components-0.113 → django_components-0.115}/src/django_components/util/tag_parser.py +0 -0
  49. {django_components-0.113 → django_components-0.115}/src/django_components/util/types.py +0 -0
  50. {django_components-0.113 → django_components-0.115}/src/django_components/util/validation.py +0 -0
  51. {django_components-0.113 → django_components-0.115}/src/django_components.egg-info/SOURCES.txt +0 -0
  52. {django_components-0.113 → django_components-0.115}/src/django_components.egg-info/dependency_links.txt +0 -0
  53. {django_components-0.113 → django_components-0.115}/src/django_components.egg-info/requires.txt +0 -0
  54. {django_components-0.113 → django_components-0.115}/src/django_components.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: django_components
3
- Version: 0.113
3
+ Version: 0.115
4
4
  Summary: A way to create simple reusable template components in Django.
5
5
  Author-email: Emil Stenström <emil@emilstenstrom.se>
6
6
  License: MIT
@@ -9,6 +9,7 @@ Keywords: django,components,css,js,html
9
9
  Classifier: Framework :: Django
10
10
  Classifier: Framework :: Django :: 4.2
11
11
  Classifier: Framework :: Django :: 5.0
12
+ Classifier: Framework :: Django :: 5.1
12
13
  Classifier: Operating System :: OS Independent
13
14
  Classifier: Programming Language :: Python
14
15
  Classifier: Programming Language :: Python :: 3
@@ -17,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.9
17
18
  Classifier: Programming Language :: Python :: 3.10
18
19
  Classifier: Programming Language :: Python :: 3.11
19
20
  Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
20
22
  Requires-Python: <4.0,>=3.8
21
23
  Description-Content-Type: text/markdown
22
24
  License-File: LICENSE
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "django_components"
7
- version = "0.113"
7
+ version = "0.115"
8
8
  requires-python = ">=3.8, <4.0"
9
9
  description = "A way to create simple reusable template components in Django."
10
10
  keywords = ["django", "components", "css", "js", "html"]
@@ -16,6 +16,7 @@ classifiers = [
16
16
  "Framework :: Django",
17
17
  "Framework :: Django :: 4.2",
18
18
  "Framework :: Django :: 5.0",
19
+ "Framework :: Django :: 5.1",
19
20
  "Operating System :: OS Independent",
20
21
  "Programming Language :: Python",
21
22
  "Programming Language :: Python :: 3",
@@ -24,6 +25,7 @@ classifiers = [
24
25
  "Programming Language :: Python :: 3.10",
25
26
  "Programming Language :: Python :: 3.11",
26
27
  "Programming Language :: Python :: 3.12",
28
+ "Programming Language :: Python :: 3.13",
27
29
  ]
28
30
  dependencies = [
29
31
  'Django>=4.2',
@@ -140,6 +140,16 @@ class ComponentVars(NamedTuple):
140
140
  </div>
141
141
  {% endif %}
142
142
  ```
143
+
144
+ This is equivalent to checking if a given key is among the slot fills:
145
+
146
+ ```py
147
+ class MyTable(Component):
148
+ def get_context_data(self, *args, **kwargs):
149
+ return {
150
+ "my_slot_filled": "my_slot" in self.input.slots
151
+ }
152
+ ```
143
153
  """
144
154
 
145
155
 
@@ -617,7 +627,31 @@ class Component(
617
627
  try:
618
628
  return self._render_impl(context, args, kwargs, slots, escape_slots_content, type, render_dependencies)
619
629
  except Exception as err:
620
- raise _type(err)(f"An error occured while rendering component '{self.name}':\n{repr(err)}") from err
630
+ # Nicely format the error message to include the component path.
631
+ # E.g.
632
+ # ```
633
+ # KeyError: "An error occured while rendering components ProjectPage > ProjectLayoutTabbed >
634
+ # Layout > RenderContextProvider > Base > TabItem:
635
+ # Component 'TabItem' tried to inject a variable '_tab' before it was provided.
636
+ # ```
637
+
638
+ if not hasattr(err, "_components"):
639
+ err._components = [] # type: ignore[attr-defined]
640
+
641
+ components = getattr(err, "_components", [])
642
+
643
+ # Access the exception's message, see https://stackoverflow.com/a/75549200/9788634
644
+ if not components:
645
+ orig_msg = err.args[0]
646
+ else:
647
+ orig_msg = err.args[0].split("\n", 1)[1]
648
+
649
+ components.insert(0, self.name)
650
+ comp_path = " > ".join(components)
651
+ prefix = f"An error occured while rendering components {comp_path}:\n"
652
+
653
+ err.args = (prefix + orig_msg,) # tuple of one
654
+ raise err
621
655
 
622
656
  def _render_impl(
623
657
  self,
@@ -226,7 +226,8 @@ def _normalize_media_filepath(filepath: Any) -> Union[str, SafeData]:
226
226
  return filepath
227
227
 
228
228
  if isinstance(filepath, (Path, os.PathLike)) or hasattr(filepath, "__fspath__"):
229
- filepath = filepath.__fspath__()
229
+ # In case of Windows OS, convert to forward slashes
230
+ filepath = Path(filepath.__fspath__()).as_posix()
230
231
 
231
232
  if isinstance(filepath, bytes):
232
233
  filepath = filepath.decode("utf-8")
@@ -293,19 +294,21 @@ def _resolve_component_relative_files(attrs: MutableMapping) -> None:
293
294
  # If not, don't modify anything.
294
295
  def resolve_file(filepath: Union[str, SafeData]) -> Union[str, SafeData]:
295
296
  if isinstance(filepath, str):
296
- maybe_resolved_filepath = os.path.join(comp_dir_abs, filepath)
297
- component_import_filepath = os.path.join(comp_dir_rel, filepath)
297
+ filepath_abs = os.path.join(comp_dir_abs, filepath)
298
+ # NOTE: The paths to resources need to use POSIX (forward slashes) for Django to wor
299
+ # See https://github.com/EmilStenstrom/django-components/issues/796
300
+ filepath_rel_to_comp_dir = Path(os.path.join(comp_dir_rel, filepath)).as_posix()
298
301
 
299
- if os.path.isfile(maybe_resolved_filepath):
302
+ if os.path.isfile(filepath_abs):
300
303
  # NOTE: It's important to use `repr`, so we don't trigger __str__ on SafeStrings
301
304
  logger.debug(
302
305
  f"Interpreting template '{repr(filepath)}' of component '{module_name}'"
303
306
  " relatively to component file"
304
307
  )
305
308
 
306
- return component_import_filepath
307
- return filepath
309
+ return filepath_rel_to_comp_dir
308
310
 
311
+ # If resolved absolute path does NOT exist or filepath is NOT a string, then return as is
309
312
  logger.debug(
310
313
  f"Interpreting template '{repr(filepath)}' of component '{module_name}'"
311
314
  " relatively to components directory"
@@ -35,6 +35,16 @@ class DynamicComponent(Component):
35
35
  {% endcomponent %}
36
36
  ```
37
37
 
38
+ Or in case you use the `django_components.component_shorthand_formatter` tag formatter:
39
+
40
+ ```django
41
+ {% dynamic is=table_comp data=table_data headers=table_headers %}
42
+ {% fill "pagination" %}
43
+ {% component "pagination" / %}
44
+ {% endfill %}
45
+ {% enddynamic %}
46
+ ```
47
+
38
48
  Python
39
49
  ```py
40
50
  from django_components import DynamicComponent
@@ -203,6 +203,12 @@ class SlotNode(BaseNode):
203
203
  def render(self, context: Context) -> SafeString:
204
204
  trace_msg("RENDR", "SLOT", self.trace_id, self.node_id)
205
205
 
206
+ # Do not render `{% slot %}` tags within the `{% component %} .. {% endcomponent %}` tags
207
+ # at the fill discovery stage (when we render the component's body to determine if the body
208
+ # is a default slot, or contains named slots).
209
+ if _is_extracting_fill(context):
210
+ return ""
211
+
206
212
  if _COMPONENT_SLOT_CTX_CONTEXT_KEY not in context or not context[_COMPONENT_SLOT_CTX_CONTEXT_KEY]:
207
213
  raise TemplateSyntaxError(
208
214
  "Encountered a SlotNode outside of a ComponentNode context. "
@@ -1,6 +1,6 @@
1
1
  import glob
2
2
  import os
3
- from pathlib import Path
3
+ from pathlib import Path, PurePosixPath, PureWindowsPath
4
4
  from typing import List, NamedTuple, Optional, Set, Union
5
5
 
6
6
  from django.apps import apps
@@ -211,13 +211,11 @@ def _filepath_to_python_module(
211
211
  - Then the path relative to project root is `app/components/mycomp.py`
212
212
  - Which we then turn into python import path `app.components.mycomp`
213
213
  """
214
- rel_path = os.path.relpath(file_path, start=root_fs_path)
215
- rel_path_without_suffix = str(Path(rel_path).with_suffix(""))
214
+ path_cls = PureWindowsPath if os.name == "nt" else PurePosixPath
216
215
 
217
- # NOTE: `Path` normalizes paths to use `/` as separator, while `os.path`
218
- # uses `os.path.sep`.
219
- sep = os.path.sep if os.path.sep in rel_path_without_suffix else "/"
220
- module_name = rel_path_without_suffix.replace(sep, ".")
216
+ rel_path = path_cls(file_path).relative_to(path_cls(root_fs_path))
217
+ rel_path_parts = rel_path.with_suffix("").parts
218
+ module_name = ".".join(rel_path_parts)
221
219
 
222
220
  # Combine with the base module path
223
221
  full_module_name = f"{root_module_path}.{module_name}" if root_module_path else module_name
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: django_components
3
- Version: 0.113
3
+ Version: 0.115
4
4
  Summary: A way to create simple reusable template components in Django.
5
5
  Author-email: Emil Stenström <emil@emilstenstrom.se>
6
6
  License: MIT
@@ -9,6 +9,7 @@ Keywords: django,components,css,js,html
9
9
  Classifier: Framework :: Django
10
10
  Classifier: Framework :: Django :: 4.2
11
11
  Classifier: Framework :: Django :: 5.0
12
+ Classifier: Framework :: Django :: 5.1
12
13
  Classifier: Operating System :: OS Independent
13
14
  Classifier: Programming Language :: Python
14
15
  Classifier: Programming Language :: Python :: 3
@@ -17,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.9
17
18
  Classifier: Programming Language :: Python :: 3.10
18
19
  Classifier: Programming Language :: Python :: 3.11
19
20
  Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
20
22
  Requires-Python: <4.0,>=3.8
21
23
  Description-Content-Type: text/markdown
22
24
  License-File: LICENSE