refactor: fix ext URLs lookup (#1086)

* refactor: fix ext URLs lookup
This commit is contained in:
Juro Oravec 2025-04-05 09:10:04 +02:00 committed by GitHub
parent 7e74831599
commit 2499126d1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 14 additions and 3 deletions

View file

@ -12,11 +12,15 @@
# settings.py
COMPONENTS = {
"extensions": [
"djc_ext_pydantic.PydanticExtension",
"djc_pydantic.PydanticExtension",
],
}
```
#### Fix
- Make it possible to resolve URLs added by extensions by their names
## v0.135
#### Feat

View file

@ -193,7 +193,7 @@ And add the extension to your project:
```py
COMPONENTS = {
"extensions": [
"djc_ext_pydantic.PydanticExtension",
"djc_pydantic.PydanticExtension",
],
}
```

View file

@ -3,7 +3,7 @@ from typing import TYPE_CHECKING, Any, Callable, Dict, List, NamedTuple, Tuple,
import django.urls
from django.template import Context
from django.urls import URLResolver
from django.urls import URLResolver, get_resolver, get_urlconf
from django_components.app_settings import app_settings
from django_components.compat.django import routes_to_django
@ -634,6 +634,11 @@ class ExtensionManager:
ext_url_resolver.urlconf_name = urls
ext_url_resolver.url_patterns = urls
# Rebuild URL resolver cache to be able to resolve the new routes by their names.
urlconf = get_urlconf()
resolver = get_resolver(urlconf)
resolver._populate()
def get_extension(self, name: str) -> ComponentExtension:
for extension in self.extensions:
if extension.name == name:

View file

@ -75,6 +75,8 @@ COMPONENTS = {
"dirs": [Path(__file__).resolve().parent / "components"],
}
urlpatterns: list = []
class StaticFilesFinderTests(SimpleTestCase):
@djc_test(