Skip to content

Commit acf9d22

Browse files
committed
Mark Jinja as optional dependency
1 parent de1e90d commit acf9d22

File tree

6 files changed

+113
-6
lines changed

6 files changed

+113
-6
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@ To upgrade to `webstack-django-sorting` v1.0.0+, you must remove the old middlew
3030

3131
## How to use it in your project
3232

33-
The provide is available on PyPI:
33+
The package is available on PyPI:
3434

3535
```shell
36-
uv add webstack_django_sorting
36+
uv add webstack-django-sorting
37+
```
38+
39+
For Jinja2 template support, install with the optional dependency:
40+
41+
```shell
42+
uv add webstack-django-sorting[jinja2]
3743
```
3844

3945
The project provides examples of integration with Django and Jinja2 templates.

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ classifiers = [
2828
"Natural Language :: English",
2929
]
3030

31+
[project.optional-dependencies]
32+
jinja2 = ["jinja2>=3.0"]
33+
3134
[project.urls]
3235
repository = "https://github.com/webstack/webstack-django-sorting.git"
3336
changelog = "https://github.com/webstack/webstack-django-sorting/blob/master/CHANGELOG.md"
@@ -45,6 +48,7 @@ dev = [
4548
"ruff>=0.8",
4649
"mypy>=1.0",
4750
"django-stubs>=5.0",
51+
"jinja2>=3.1.6",
4852
]
4953

5054
[tool.hatch.metadata]

src/testproj/uv.lock

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/webstack_django_sorting/jinja2_globals.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33

44
from django.db.models import QuerySet
55
from django.http import HttpRequest
6-
from markupsafe import Markup
6+
7+
try:
8+
from markupsafe import Markup
9+
except ImportError as e:
10+
raise ImportError(
11+
"Jinja2 support requires the 'jinja2' package. "
12+
"Install it with: uv add webstack-django-sorting[jinja2]"
13+
) from e
714

815
from . import common
916

src/webstack_django_sorting/templatetags/sorting_tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def render(self, context: Context) -> str:
8282
raise Http404(
8383
"Invalid field sorting. If INVALID_FIELD_RAISES_404 were set to "
8484
"False, the error would have been ignored."
85-
)
85+
) from None
8686
context[key] = queryset
8787

8888
return ""

0 commit comments

Comments
 (0)