refactor: fix link in docs + call django.setup() in @djc_test if not done so (#1098)

This commit is contained in:
Juro Oravec 2025-04-07 15:07:46 +02:00 committed by GitHub
parent bb5de86b69
commit 9f9b1f7232
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 1 deletions

View file

@ -35,6 +35,8 @@
Read more on [Component views and URLs](https://django-components.github.io/django-components/0.135/concepts/fundamentals/component_views_urls/). Read more on [Component views and URLs](https://django-components.github.io/django-components/0.135/concepts/fundamentals/component_views_urls/).
- `@djc_test` can now be called without first calling `django.setup()`, in which case it does it for you.
#### Deprecation #### Deprecation
- Currently, view request handlers such as `get()` and `post()` methods can be defined - Currently, view request handlers such as `get()` and `post()` methods can be defined

View file

@ -1,6 +1,6 @@
<img src="https://raw.githubusercontent.com/django-components/django-components/master/logo/logo-black-on-white.svg" alt="django-components" style="max-width: 100%; background: white; color: black;"> <img src="https://raw.githubusercontent.com/django-components/django-components/master/logo/logo-black-on-white.svg" alt="django-components" style="max-width: 100%; background: white; color: black;">
[![PyPI - Version](https://img.shields.io/pypi/v/django-components)](https://pypi.org/project/django-components/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-components)](https://pypi.org/project/django-components/) [![PyPI - License](https://img.shields.io/pypi/l/django-components)](https://github.com/django-components/django-components/blob/master/LICENSE/) [![PyPI - Downloads](https://img.shields.io/pypi/dm/django-components)](https://pypistats.org/packages/django-components) [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/django-components/django-components/tests.yml)](https://github.com/django-components/django-components/actions/workflows/tests.yml) [![asv](https://img.shields.io/badge/benchmarked%20by-asv-blue.svg?style=flat)](/django-components/benchmarks/) [![PyPI - Version](https://img.shields.io/pypi/v/django-components)](https://pypi.org/project/django-components/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-components)](https://pypi.org/project/django-components/) [![PyPI - License](https://img.shields.io/pypi/l/django-components)](https://github.com/django-components/django-components/blob/master/LICENSE/) [![PyPI - Downloads](https://img.shields.io/pypi/dm/django-components)](https://pypistats.org/packages/django-components) [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/django-components/django-components/tests.yml)](https://github.com/django-components/django-components/actions/workflows/tests.yml) [![asv](https://img.shields.io/badge/benchmarked%20by-asv-blue.svg?style=flat)](/django-components/latest/benchmarks/)
`django-components` combines Django's templating system with the modularity seen `django-components` combines Django's templating system with the modularity seen
in modern frontend frameworks like Vue or React. in modern frontend frameworks like Vue or React.

View file

@ -6,6 +6,7 @@ from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Set,
from unittest.mock import patch from unittest.mock import patch
from weakref import ReferenceType from weakref import ReferenceType
import django
from django.conf import settings as _django_settings from django.conf import settings as _django_settings
from django.template import engines from django.template import engines
from django.test import override_settings from django.test import override_settings
@ -296,6 +297,11 @@ def djc_test(
# Contents of this function will run as the test # Contents of this function will run as the test
def _wrapper_impl(*args: Any, **kwargs: Any) -> Any: def _wrapper_impl(*args: Any, **kwargs: Any) -> Any:
# If Django is not yet configured, do so now, because we'll need to access
# Django's settings when merging the given settings.
if not _django_settings.configured:
django.setup()
# Merge the settings # Merge the settings
current_django_settings = django_settings if not callable(django_settings) else None current_django_settings = django_settings if not callable(django_settings) else None
current_django_settings = current_django_settings.copy() if current_django_settings else {} current_django_settings = current_django_settings.copy() if current_django_settings else {}