django-components 0.62__tar.gz → 0.64__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 (43) hide show
  1. {django_components-0.62/src/django_components.egg-info → django_components-0.64}/PKG-INFO +37 -28
  2. {django_components-0.62 → django_components-0.64}/README.md +26 -15
  3. django_components-0.64/pyproject.toml +102 -0
  4. {django_components-0.62 → django_components-0.64}/src/django_components/app_settings.py +1 -1
  5. {django_components-0.62 → django_components-0.64}/src/django_components/component.py +91 -139
  6. {django_components-0.62 → django_components-0.64}/src/django_components/middleware.py +4 -0
  7. django_components-0.64/src/django_components/slots.py +467 -0
  8. django_components-0.64/src/django_components/templatetags/component_tags.py +393 -0
  9. {django_components-0.62 → django_components-0.64/src/django_components.egg-info}/PKG-INFO +37 -28
  10. {django_components-0.62 → django_components-0.64}/src/django_components.egg-info/SOURCES.txt +1 -1
  11. {django_components-0.62 → django_components-0.64}/tests/test_settings.py +16 -1
  12. django_components-0.62/pyproject.toml +0 -57
  13. django_components-0.62/setup.py +0 -43
  14. django_components-0.62/src/django_components/templatetags/component_tags.py +0 -768
  15. {django_components-0.62 → django_components-0.64}/LICENSE +0 -0
  16. {django_components-0.62 → django_components-0.64}/setup.cfg +0 -0
  17. {django_components-0.62 → django_components-0.64}/src/django_components/__init__.py +0 -0
  18. {django_components-0.62 → django_components-0.64}/src/django_components/apps.py +0 -0
  19. {django_components-0.62 → django_components-0.64}/src/django_components/component_registry.py +0 -0
  20. {django_components-0.62 → django_components-0.64}/src/django_components/logger.py +0 -0
  21. {django_components-0.62 → django_components-0.64}/src/django_components/management/__init__.py +0 -0
  22. {django_components-0.62 → django_components-0.64}/src/django_components/management/commands/__init__.py +0 -0
  23. {django_components-0.62 → django_components-0.64}/src/django_components/management/commands/startcomponent.py +0 -0
  24. {django_components-0.62 → django_components-0.64}/src/django_components/management/commands/upgradecomponent.py +0 -0
  25. {django_components-0.62 → django_components-0.64}/src/django_components/py.typed +0 -0
  26. {django_components-0.62 → django_components-0.64}/src/django_components/safer_staticfiles/__init__.py +0 -0
  27. {django_components-0.62 → django_components-0.64}/src/django_components/safer_staticfiles/apps.py +0 -0
  28. {django_components-0.62 → django_components-0.64}/src/django_components/template_loader.py +0 -0
  29. {django_components-0.62 → django_components-0.64}/src/django_components/templatetags/__init__.py +0 -0
  30. {django_components-0.62 → django_components-0.64}/src/django_components/types.py +0 -0
  31. {django_components-0.62 → django_components-0.64}/src/django_components/utils.py +0 -0
  32. {django_components-0.62 → django_components-0.64}/src/django_components.egg-info/dependency_links.txt +0 -0
  33. {django_components-0.62 → django_components-0.64}/src/django_components.egg-info/requires.txt +0 -0
  34. {django_components-0.62 → django_components-0.64}/src/django_components.egg-info/top_level.txt +0 -0
  35. {django_components-0.62 → django_components-0.64}/tests/test_autodiscover.py +0 -0
  36. {django_components-0.62 → django_components-0.64}/tests/test_component.py +0 -0
  37. {django_components-0.62 → django_components-0.64}/tests/test_component_as_view.py +0 -0
  38. {django_components-0.62 → django_components-0.64}/tests/test_context.py +0 -0
  39. {django_components-0.62 → django_components-0.64}/tests/test_dependency_rendering.py +0 -0
  40. {django_components-0.62 → django_components-0.64}/tests/test_registry.py +0 -0
  41. {django_components-0.62 → django_components-0.64}/tests/test_startcomponent_command.py +0 -0
  42. {django_components-0.62 → django_components-0.64}/tests/test_templatetags.py +0 -0
  43. {django_components-0.62 → django_components-0.64}/tests/testutils.py +0 -0
@@ -1,28 +1,26 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: django_components
3
- Version: 0.62
3
+ Version: 0.64
4
4
  Summary: A way to create simple reusable template components in Django.
5
- Home-page: https://github.com/EmilStenstrom/django-components/
6
- Author: Emil Stenström
7
- Author-email: emil@emilstenstrom.se
5
+ Author-email: Emil Stenström <emil@emilstenstrom.se>
8
6
  License: MIT
7
+ Project-URL: Homepage, https://github.com/EmilStenstrom/django-components/
9
8
  Keywords: django,components,css,js,html
10
- Classifier: Programming Language :: Python :: 3.6
11
- Classifier: Programming Language :: Python :: 3.7
12
- Classifier: Programming Language :: Python :: 3.8
13
- Classifier: Programming Language :: Python :: 3.9
14
- Classifier: Programming Language :: Python :: 3.10
15
- Classifier: Programming Language :: Python :: 3.11
16
- Classifier: Programming Language :: Python :: 3.12
9
+ Classifier: Framework :: Django
17
10
  Classifier: Framework :: Django :: 3.2
18
11
  Classifier: Framework :: Django :: 4.0
19
12
  Classifier: Framework :: Django :: 4.1
20
13
  Classifier: Framework :: Django :: 4.2
21
14
  Classifier: Framework :: Django :: 5.0
15
+ Classifier: Operating System :: OS Independent
22
16
  Classifier: Programming Language :: Python
23
17
  Classifier: Programming Language :: Python :: 3
24
- Classifier: Operating System :: OS Independent
25
- Classifier: Framework :: Django
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Requires-Python: <4.0,>=3.8
26
24
  Description-Content-Type: text/markdown
27
25
  License-File: LICENSE
28
26
  Requires-Dist: Django>=3.2
@@ -167,12 +165,10 @@ Read on to find out how to build your first component!
167
165
 
168
166
  ## Compatiblity
169
167
 
170
- Django-components supports all <a href="https://docs.djangoproject.com/en/dev/faq/install/#what-python-version-can-i-use-with-django">officially supported versions</a> of Django and Python.
168
+ Django-components supports all supported combinations versions of [Django](https://docs.djangoproject.com/en/dev/faq/install/#what-python-version-can-i-use-with-django) and [Python](https://devguide.python.org/versions/#versions).
171
169
 
172
170
  | Python version | Django version |
173
171
  |----------------|--------------------------|
174
- | 3.6 | 3.2 |
175
- | 3.7 | 3.2 |
176
172
  | 3.8 | 3.2, 4.0, 4.1, 4.2 |
177
173
  | 3.9 | 3.2, 4.0, 4.1, 4.2 |
178
174
  | 3.10 | 3.2, 4.0, 4.1, 4.2, 5.0 |
@@ -284,7 +280,7 @@ Components can also be defined in a single file, which is useful for small compo
284
280
  ```python
285
281
  # In a file called [project root]/components/calendar.py
286
282
  from django_components import component
287
- from django_components import types as t
283
+ from django_components import types as t
288
284
 
289
285
  @component.register("calendar")
290
286
  class Calendar(component.Component):
@@ -292,16 +288,16 @@ class Calendar(component.Component):
292
288
  return {
293
289
  "date": date,
294
290
  }
295
-
291
+
296
292
  template: t.django_html = """
297
293
  <div class="calendar-component">Today's date is <span>{{ date }}</span></div>
298
294
  """
299
-
295
+
300
296
  css: t.css = """
301
297
  .calendar-component { width: 200px; background: pink; }
302
298
  .calendar-component span { font-weight: bold; }
303
299
  """
304
-
300
+
305
301
  js: t.js = """
306
302
  (function(){
307
303
  if (document.querySelector(".calendar-component")) {
@@ -313,7 +309,7 @@ class Calendar(component.Component):
313
309
 
314
310
  This makes it easy to create small components without having to create a separate template, CSS, and JS file.
315
311
 
316
- Note that the `t.django_html`, `t.css`, and `t.js` types are used to specify the type of the template, CSS, and JS files, respectively. This is not necessary, but if you're using VSCode with the [Python Inline Source Syntax Highlighting](https://marketplace.visualstudio.com/items?itemName=samwillis.python-inline-source) extension, it will give you syntax highlighting for the template, CSS, and JS.
312
+ Note that the `t.django_html`, `t.css`, and `t.js` types are used to specify the type of the template, CSS, and JS files, respectively. This is not necessary, but if you're using VSCode with the [Python Inline Source Syntax Highlighting](https://marketplace.visualstudio.com/items?itemName=samwillis.python-inline-source) extension, it will give you syntax highlighting for the template, CSS, and JS.
317
313
 
318
314
  ## Using slots in templates
319
315
 
@@ -445,7 +441,7 @@ This is fine too:
445
441
 
446
442
  _New in version 0.34_
447
443
 
448
- Components can now be used as views. To do this, `Component` subclasses Django's `View` class. This means that you can use all of the [methods](https://docs.djangoproject.com/en/5.0/ref/class-based-views/base/#view) of `View` in your component. For example, you can override `get` and `post` to handle GET and POST requests, respectively.
444
+ Components can now be used as views. To do this, `Component` subclasses Django's `View` class. This means that you can use all of the [methods](https://docs.djangoproject.com/en/5.0/ref/class-based-views/base/#view) of `View` in your component. For example, you can override `get` and `post` to handle GET and POST requests, respectively.
449
445
 
450
446
  In addition, `Component` now has a `render_to_response` method that renders the component template based on the provided context and slots' data and returns an `HttpResponse` object.
451
447
 
@@ -457,7 +453,7 @@ from django_components import component
457
453
 
458
454
  @component.register("calendar")
459
455
  class Calendar(component.Component):
460
-
456
+
461
457
  template = """
462
458
  <div class="calendar-component">
463
459
  <div class="header">
@@ -468,7 +464,7 @@ class Calendar(component.Component):
468
464
  </div>
469
465
  </div>
470
466
  """
471
-
467
+
472
468
  def get(self, request, *args, **kwargs):
473
469
  context = {
474
470
  "date": request.GET.get("date", "2020-06-06"),
@@ -484,7 +480,7 @@ Then, to use this component as a view, you should create a `urls.py` file in you
484
480
  ```python
485
481
  # In a file called [project root]/components/urls.py
486
482
  from django.urls import path
487
- from calendar import Calendar
483
+ from calendar import Calendar
488
484
 
489
485
  urlpatterns = [
490
486
  path("calendar/", Calendar.as_view()),
@@ -846,14 +842,12 @@ pytest
846
842
  The library is also tested across many versions of Python and Django. To run tests that way:
847
843
 
848
844
  ```sh
849
- pyenv install -s 3.6
850
- pyenv install -s 3.7
851
845
  pyenv install -s 3.8
852
846
  pyenv install -s 3.9
853
847
  pyenv install -s 3.10
854
848
  pyenv install -s 3.11
855
849
  pyenv install -s 3.12
856
- pyenv local 3.6 3.7 3.8 3.9 3.10 3.11 3.12
850
+ pyenv local 3.8 3.9 3.10 3.11 3.12
857
851
  tox -p
858
852
  ```
859
853
 
@@ -887,3 +881,18 @@ Use the [sampleproject](./sampleproject/) demo project to validate the changes:
887
881
  Once the server is up, it should be available at <http://127.0.0.1:8000>.
888
882
 
889
883
  To display individual components, add them to the `urls.py`, like in the case of <http://127.0.0.1:8000/greeting>
884
+
885
+ ## Development guides
886
+
887
+ ### Slot rendering flow
888
+
889
+ 1. Flow starts when a template string is being parsed into Django Template instance.
890
+
891
+ 2. When a `{% component %}` template tag is encountered, its body is searched for all `{% fill %}` nodes (explicit or implicit). and this is attached to the created `ComponentNode`.
892
+
893
+ See the implementation of `component` template tag for details.
894
+
895
+ 3. Template rendering is a separate action from template parsing. When the template is being rendered, the `ComponentNode` creates an instance of the `Component` class and passes it the slot fills.
896
+
897
+ It's at this point when `Component.render` is called, and the slots are
898
+ rendered.
@@ -138,12 +138,10 @@ Read on to find out how to build your first component!
138
138
 
139
139
  ## Compatiblity
140
140
 
141
- Django-components supports all <a href="https://docs.djangoproject.com/en/dev/faq/install/#what-python-version-can-i-use-with-django">officially supported versions</a> of Django and Python.
141
+ Django-components supports all supported combinations versions of [Django](https://docs.djangoproject.com/en/dev/faq/install/#what-python-version-can-i-use-with-django) and [Python](https://devguide.python.org/versions/#versions).
142
142
 
143
143
  | Python version | Django version |
144
144
  |----------------|--------------------------|
145
- | 3.6 | 3.2 |
146
- | 3.7 | 3.2 |
147
145
  | 3.8 | 3.2, 4.0, 4.1, 4.2 |
148
146
  | 3.9 | 3.2, 4.0, 4.1, 4.2 |
149
147
  | 3.10 | 3.2, 4.0, 4.1, 4.2, 5.0 |
@@ -255,7 +253,7 @@ Components can also be defined in a single file, which is useful for small compo
255
253
  ```python
256
254
  # In a file called [project root]/components/calendar.py
257
255
  from django_components import component
258
- from django_components import types as t
256
+ from django_components import types as t
259
257
 
260
258
  @component.register("calendar")
261
259
  class Calendar(component.Component):
@@ -263,16 +261,16 @@ class Calendar(component.Component):
263
261
  return {
264
262
  "date": date,
265
263
  }
266
-
264
+
267
265
  template: t.django_html = """
268
266
  <div class="calendar-component">Today's date is <span>{{ date }}</span></div>
269
267
  """
270
-
268
+
271
269
  css: t.css = """
272
270
  .calendar-component { width: 200px; background: pink; }
273
271
  .calendar-component span { font-weight: bold; }
274
272
  """
275
-
273
+
276
274
  js: t.js = """
277
275
  (function(){
278
276
  if (document.querySelector(".calendar-component")) {
@@ -284,7 +282,7 @@ class Calendar(component.Component):
284
282
 
285
283
  This makes it easy to create small components without having to create a separate template, CSS, and JS file.
286
284
 
287
- Note that the `t.django_html`, `t.css`, and `t.js` types are used to specify the type of the template, CSS, and JS files, respectively. This is not necessary, but if you're using VSCode with the [Python Inline Source Syntax Highlighting](https://marketplace.visualstudio.com/items?itemName=samwillis.python-inline-source) extension, it will give you syntax highlighting for the template, CSS, and JS.
285
+ Note that the `t.django_html`, `t.css`, and `t.js` types are used to specify the type of the template, CSS, and JS files, respectively. This is not necessary, but if you're using VSCode with the [Python Inline Source Syntax Highlighting](https://marketplace.visualstudio.com/items?itemName=samwillis.python-inline-source) extension, it will give you syntax highlighting for the template, CSS, and JS.
288
286
 
289
287
  ## Using slots in templates
290
288
 
@@ -416,7 +414,7 @@ This is fine too:
416
414
 
417
415
  _New in version 0.34_
418
416
 
419
- Components can now be used as views. To do this, `Component` subclasses Django's `View` class. This means that you can use all of the [methods](https://docs.djangoproject.com/en/5.0/ref/class-based-views/base/#view) of `View` in your component. For example, you can override `get` and `post` to handle GET and POST requests, respectively.
417
+ Components can now be used as views. To do this, `Component` subclasses Django's `View` class. This means that you can use all of the [methods](https://docs.djangoproject.com/en/5.0/ref/class-based-views/base/#view) of `View` in your component. For example, you can override `get` and `post` to handle GET and POST requests, respectively.
420
418
 
421
419
  In addition, `Component` now has a `render_to_response` method that renders the component template based on the provided context and slots' data and returns an `HttpResponse` object.
422
420
 
@@ -428,7 +426,7 @@ from django_components import component
428
426
 
429
427
  @component.register("calendar")
430
428
  class Calendar(component.Component):
431
-
429
+
432
430
  template = """
433
431
  <div class="calendar-component">
434
432
  <div class="header">
@@ -439,7 +437,7 @@ class Calendar(component.Component):
439
437
  </div>
440
438
  </div>
441
439
  """
442
-
440
+
443
441
  def get(self, request, *args, **kwargs):
444
442
  context = {
445
443
  "date": request.GET.get("date", "2020-06-06"),
@@ -455,7 +453,7 @@ Then, to use this component as a view, you should create a `urls.py` file in you
455
453
  ```python
456
454
  # In a file called [project root]/components/urls.py
457
455
  from django.urls import path
458
- from calendar import Calendar
456
+ from calendar import Calendar
459
457
 
460
458
  urlpatterns = [
461
459
  path("calendar/", Calendar.as_view()),
@@ -817,14 +815,12 @@ pytest
817
815
  The library is also tested across many versions of Python and Django. To run tests that way:
818
816
 
819
817
  ```sh
820
- pyenv install -s 3.6
821
- pyenv install -s 3.7
822
818
  pyenv install -s 3.8
823
819
  pyenv install -s 3.9
824
820
  pyenv install -s 3.10
825
821
  pyenv install -s 3.11
826
822
  pyenv install -s 3.12
827
- pyenv local 3.6 3.7 3.8 3.9 3.10 3.11 3.12
823
+ pyenv local 3.8 3.9 3.10 3.11 3.12
828
824
  tox -p
829
825
  ```
830
826
 
@@ -858,3 +854,18 @@ Use the [sampleproject](./sampleproject/) demo project to validate the changes:
858
854
  Once the server is up, it should be available at <http://127.0.0.1:8000>.
859
855
 
860
856
  To display individual components, add them to the `urls.py`, like in the case of <http://127.0.0.1:8000/greeting>
857
+
858
+ ## Development guides
859
+
860
+ ### Slot rendering flow
861
+
862
+ 1. Flow starts when a template string is being parsed into Django Template instance.
863
+
864
+ 2. When a `{% component %}` template tag is encountered, its body is searched for all `{% fill %}` nodes (explicit or implicit). and this is attached to the created `ComponentNode`.
865
+
866
+ See the implementation of `component` template tag for details.
867
+
868
+ 3. Template rendering is a separate action from template parsing. When the template is being rendered, the `ComponentNode` creates an instance of the `Component` class and passes it the slot fills.
869
+
870
+ It's at this point when `Component.render` is called, and the slots are
871
+ rendered.
@@ -0,0 +1,102 @@
1
+ [build-system]
2
+ requires = ["setuptools"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "django_components"
7
+ version = "0.64"
8
+ requires-python = ">=3.8, <4.0"
9
+ description = "A way to create simple reusable template components in Django."
10
+ keywords = ["django", "components", "css", "js", "html"]
11
+ readme = "README.md"
12
+ authors = [
13
+ {name = "Emil Stenström", email = "emil@emilstenstrom.se"},
14
+ ]
15
+ classifiers = [
16
+ "Framework :: Django",
17
+ "Framework :: Django :: 3.2",
18
+ "Framework :: Django :: 4.0",
19
+ "Framework :: Django :: 4.1",
20
+ "Framework :: Django :: 4.2",
21
+ "Framework :: Django :: 5.0",
22
+ "Operating System :: OS Independent",
23
+ "Programming Language :: Python",
24
+ "Programming Language :: Python :: 3",
25
+ "Programming Language :: Python :: 3.8",
26
+ "Programming Language :: Python :: 3.9",
27
+ "Programming Language :: Python :: 3.10",
28
+ "Programming Language :: Python :: 3.11",
29
+ "Programming Language :: Python :: 3.12",
30
+ ]
31
+ dependencies = [
32
+ 'Django>=3.2',
33
+ ]
34
+ license = {text = "MIT"}
35
+
36
+ [project.urls]
37
+ Homepage = "https://github.com/EmilStenstrom/django-components/"
38
+
39
+
40
+ [tool.setuptools.packages.find]
41
+ where = ["src"]
42
+ include = ["django_components*"]
43
+ exclude = ["django_components.tests*"]
44
+ namespaces = false
45
+
46
+ [tool.black]
47
+ line-length = 119
48
+ include = '\.pyi?$'
49
+ exclude = '''
50
+ /(
51
+ \.git
52
+ | \.hg
53
+ | \.mypy_cache
54
+ | \.tox
55
+ | \.venv
56
+ | activate
57
+ | _build
58
+ | buck-out
59
+ | build
60
+ | dist
61
+ )/
62
+ '''
63
+
64
+ [tool.isort]
65
+ profile = "black"
66
+ line_length = 119
67
+ multi_line_output = 3
68
+ include_trailing_comma = "True"
69
+ known_first_party = "django_components"
70
+
71
+ [tool.flake8]
72
+ ignore = ['E302', 'W503']
73
+ max-line-length = 119
74
+ exclude = [
75
+ 'migrations',
76
+ '__pycache__',
77
+ 'manage.py',
78
+ 'settings.py',
79
+ 'env',
80
+ '.env',
81
+ '.venv',
82
+ '.tox',
83
+ 'build',
84
+ ]
85
+
86
+ [tool.mypy]
87
+ check_untyped_defs = true
88
+ ignore_missing_imports = true
89
+ exclude = [
90
+ 'test_structures',
91
+ 'build',
92
+ ]
93
+
94
+ [[tool.mypy.overrides]]
95
+ module = "django_components.*"
96
+ disallow_untyped_defs = true
97
+
98
+
99
+ [tool.pytest.ini_options]
100
+ testpaths = [
101
+ "tests"
102
+ ]
@@ -4,7 +4,7 @@ from typing import List
4
4
  from django.conf import settings
5
5
 
6
6
 
7
- class ContextBehavior(Enum):
7
+ class ContextBehavior(str, Enum):
8
8
  GLOBAL = "global"
9
9
  ISOLATED = "isolated"
10
10