From 41736848a61a32c2726118e1ac33d1492a87cf72 Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Tue, 19 Dec 2023 23:05:13 +0000 Subject: [PATCH] release: 0.1.0 (#17) --- .pre-commit-config.yaml | 2 +- CHANGELOG.rst | 8 ++++++++ setup.cfg | 5 +++-- src/django_nh3/models.py | 2 +- src/django_nh3/templatetags/nh3_tags.py | 10 ++++------ 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 034fd8e..0366e9a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ ci: autoupdate_schedule: monthly default_language_version: - python: python3.11 + python: python3.12 repos: - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3314495..ce5aa06 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,14 @@ Changelog unreleased ---------- +0.1.0 - 2023-12-19 +------------------ + +- Add templatetags to clean HTML within django templates by `@wes-otf`_ in `PR 16`_. + +.. _@wes-otf: https://github.com/wes-otf +.. _PR 16: https://github.com/marksweb/django-nh3/pull/16 + 0.0.3 - 2023-11-15 ------------------ diff --git a/setup.cfg b/setup.cfg index f354db9..c4098fd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = django_nh3 -version = 0.0.3 +version = 0.1.0 description = Django integration with for nh3, Python binding to Ammonia HTML sanitizer Rust crate. long_description = file: README.rst long_description_content_type = text/x-rst @@ -10,11 +10,12 @@ author_email = theshow@gmail.com license = MIT license_files = LICENSE classifiers = - Development Status :: 3 - Alpha + Development Status :: 4 - Beta Framework :: Django :: 3.2 Framework :: Django :: 4.0 Framework :: Django :: 4.1 Framework :: Django :: 4.2 + Framework :: Django :: 5.0 Intended Audience :: Developers License :: OSI Approved :: MIT License Natural Language :: English diff --git a/src/django_nh3/models.py b/src/django_nh3/models.py index ff17862..7583652 100644 --- a/src/django_nh3/models.py +++ b/src/django_nh3/models.py @@ -41,7 +41,7 @@ def formfield( ) -> FormField: """Makes the field for a ModelForm""" - # If field doesn't have any choices add kwargs expected by BleachField. + # If field doesn't have any choices add kwargs expected by Nh3Field. if not self.choices: kwargs.update( { diff --git a/src/django_nh3/templatetags/nh3_tags.py b/src/django_nh3/templatetags/nh3_tags.py index 71c3d85..b5e982d 100644 --- a/src/django_nh3/templatetags/nh3_tags.py +++ b/src/django_nh3/templatetags/nh3_tags.py @@ -8,19 +8,17 @@ @register.filter(name="nh3") -def nh3_value(value: str | None, tags: str | None = None) -> SafeText: +def nh3_value(value: str | None, tags: str | None = None) -> SafeText | None: """ Takes an input HTML value and sanitizes it utilizing nh3, returning a SafeText object that can be rendered by Django. Accepts an optional argument of allowed tags. Should be a comma delimited - string (ie. "img,span" or "img") + string (i.e. "img,span" or "img") """ if value is None: return None - args = {} - nh3_args = get_nh3_default_options() if tags is not None: args = nh3_args.copy() @@ -28,5 +26,5 @@ def nh3_value(value: str | None, tags: str | None = None) -> SafeText: else: args = nh3_args - nh3_value = nh3.clean(value, **args) - return mark_safe(nh3_value) + clean_value = nh3.clean(value, **args) + return mark_safe(clean_value)