refactor: make djc compatible with django-template-partials v23.3 and later (#1458)

This commit is contained in:
Juro Oravec 2025-10-17 11:06:13 +02:00 committed by GitHub
parent a5ebb59059
commit c15e91cb6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 26 additions and 2 deletions

View file

@ -2,6 +2,10 @@
## v0.142.3 ## v0.142.3
#### Fix
- Fixed compatibility with older versions of django-template-partials. django-components now works with django-template-partials v23.3 and later. (See [#1455](https://github.com/django-components/django-components/issues/1455))
#### Refactor #### Refactor
- `Component.View.public = True` is now optional. - `Component.View.public = True` is now optional.

View file

@ -23,3 +23,13 @@ django-components is tested against Ubuntu and Windows, and should work on any o
This should cover most of the cases. This should cover most of the cases.
However, if your environment is not supported, you will need to install Rust and Cargo to build the sub-packages from source. However, if your environment is not supported, you will need to install Rust and Cargo to build the sub-packages from source.
### Other packages
Here we track which other packages from the Django ecosystem we try to be compatible with.
How to read this table - E.g. in case of `django-template-partials`, you should use at least version `0.142.3` of `django-components` and at least version `23.3` of django-template-partials.
| Package | django-components version | Package version |
| -------------- | -------------- | --- |
[`django-template-partials`](https://github.com/carltongibson/django-template-partials) | >=0.142.3 | >=23.3 |

View file

@ -12,8 +12,6 @@ asv==0.6.5
# via -r requirements-dev.in # via -r requirements-dev.in
asv-runner==0.2.1 asv-runner==0.2.1
# via asv # via asv
backports-asyncio-runner==1.2.0
# via pytest-asyncio
build==1.3.0 build==1.3.0
# via asv # via asv
cachetools==6.2.0 cachetools==6.2.0

View file

@ -353,6 +353,17 @@ def monkeypatch_template_proxy_render(template_proxy_cls: Type[Any]) -> None:
template_proxy_cls.render = _template_proxy_render template_proxy_cls.render = _template_proxy_render
# TemplateProxy from django-template-partials replicates Template.render().
# However, the older versions (e.g. 24.1) didn't define `_render()` method.
# So we define it to support the older versions of django-template-partials.
# With this, we support django-template-partials as old as v23.3.
if not hasattr(template_proxy_cls, "_render"):
def _render(self: Any, context: Context, *args: Any, **kwargs: Any) -> str:
return self.nodelist.render(context, *args, **kwargs)
template_proxy_cls._render = _render
def is_cls_patched(cls: Type[Any]) -> bool: def is_cls_patched(cls: Type[Any]) -> bool:
return getattr(cls, "_djc_patched", False) return getattr(cls, "_djc_patched", False)

View file

@ -28,6 +28,7 @@ except ImportError:
setup_test_config() setup_test_config()
# Test compatibility with django-template-partials.
# See https://github.com/django-components/django-components/issues/1323#issuecomment-3156654329 # See https://github.com/django-components/django-components/issues/1323#issuecomment-3156654329
@djc_test(django_settings={"INSTALLED_APPS": ("template_partials", "django_components", "tests.test_app")}) @djc_test(django_settings={"INSTALLED_APPS": ("template_partials", "django_components", "tests.test_app")})
class TestTemplatePartialsIntegration: class TestTemplatePartialsIntegration: