Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.13'
architecture: 'x64'

- name: Install dependencies
Expand Down
34 changes: 16 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,38 @@ jobs:
fail-fast: false
matrix:
python-version:
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
- '3.13'
django-version:
- '3.2'
- '4.0'
- '4.1'
- '4.2'
- '5.0'
- '5.1'
exclude:
- python-version: '3.7'
django-version: '4.0'
- python-version: '3.7'
django-version: '4.1'
- python-version: '3.9'
django-version: '5.0'
- python-version: '3.9'
django-version: '5.1'

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies and package
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install black isort
pip install django~=${{ matrix.django-version }}.0

- name: Lint with black
run: black ./django_cleanhtmlfield ./tests --check

- name: Lint package sorting
run: isort ./django_cleanhtmlfield ./tests --check
- name: Run linters and format checks
run: |
pre-commit run --all-files

- name: Run tests with coverage
run: |
Expand All @@ -58,4 +56,4 @@ jobs:
coverage xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ django_cleanhtmlfield.egg-info/**
.idea/**
venv/
build/
db.sqlite3
db.sqlite3
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
- id: requirements-txt-fixer
- id: trailing-whitespace
args: ["--markdown-linebreak-ext=md"]

- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
args: ["--py39-plus"]

- repo: https://github.com/asottile/add-trailing-comma
rev: v3.1.0
hooks:
- id: add-trailing-comma

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.4.0]
### Removed
- Dropped support for Django 3.2, 4.0, 4.1
- Dropped support for Python 3.7 and 3.8
### Added
- Added support for Django 4.2, 5.0, and 5.1
- Added support for Python 3.11, 3.12, and 3.13

## [1.3.0]
### Removed
- Dropped support for Django 2.2
Expand Down Expand Up @@ -37,7 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial Release

[Unreleased]: https://github.com/anexia/django-cleanhtmlfield/compare/v1.3.0...HEAD
[Unreleased]: https://github.com/anexia/django-cleanhtmlfield/compare/v1.4.0...HEAD
[1.4.0]: https://pypi.org/project/django-cleanhtmlfield/1.4.0/
[1.3.0]: https://pypi.org/project/django-cleanhtmlfield/1.3.0/
[1.2.0]: https://pypi.org/project/django-cleanhtmlfield/1.2.0/
[1.1.0]: https://pypi.org/project/django-cleanhtmlfield/1.1.0/
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ and patterns in the existing code-base.

### Contribution guidelines
- Your code should follow PEP 8 -- Style Guide for Python Code
- Your changes should be covered by unit-tests
- Your changes should be covered by unit-tests
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include LICENSE
include README.md
recursive-include docs *
recursive-include docs *
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,12 @@ ModelSerializer.serializer_field_mapping[HTMLField] = RestHtmlField
This library should be compatible with the latest Django. For reference, here is a matrix showing
the guaranteed and tested compatibility.

django-cleanhtmlfield Version | Django Versions | Python
----------------------------- | --------------- | ------
1.1 | 2.2, 3.0, 3.1 | 3.5 - 3.8
1.2 | 2.2, 3.1, 3.2 | 3.7 - 3.10
1.3 | 3.2, 4.0, 4.1 | 3.7 - 3.10
| django-cleanhtmlfield Version | Django Versions | Python |
|-------------------------------|-----------------|------------|
| 1.1 | 2.2, 3.0, 3.1 | 3.5 - 3.8 |
| 1.2 | 2.2, 3.1, 3.2 | 3.7 - 3.10 |
| 1.3 | 3.2, 4.0, 4.1 | 3.7 - 3.10 |
| 1.4 | 4.2, 5.0, 5.1 | 3.9 - 3.13 |

# License

Expand Down
8 changes: 4 additions & 4 deletions django_cleanhtmlfield/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def __init__(self, strip_unsafe=False, widget_form_class=None, *args, **kwargs):
for arg in ("primary_key", "unique", "max_length"):
if arg in kwargs:
raise TypeError(
"'%s' is not a valid argument for %s." % (arg, self.__class__)
f"'{arg}' is not a valid argument for {self.__class__}.",
)

super(HTMLField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def get_internal_type(self):
"""
Expand Down Expand Up @@ -64,8 +64,8 @@ def formfield(self, *args, **kwargs):
defaults["widget"] = forms.Textarea(
attrs={
"class": css_class,
}
},
)

defaults.update(kwargs)
return super(HTMLField, self).formfield(*args, **defaults)
return super().formfield(*args, **defaults)
27 changes: 14 additions & 13 deletions django_cleanhtmlfield/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def clean_styles(styles_string):
if ":" not in style_string:
logger.warning(
"Removing style string '{}' as it does not contain a :".format(
style_string
)
style_string,
),
)
continue

Expand All @@ -87,18 +87,19 @@ def clean_styles(styles_string):
cleaned_styles.append({"name": style_name, "value": style_value})
elif style_name_stripped in getattr(settings, "ACCEPTABLE_STYLES", tuple()):
cleaned_styles.append(
{"name": style_name_stripped, "value": style_value_stripped}
{"name": style_name_stripped, "value": style_value_stripped},
)
else:
logger.warning(
"Removing style string '{}' as the style name '{}' is not "
"listed in the ACCEPTABLE_STYLES setting".format(
style_string, style_name
)
style_string,
style_name,
),
)

for style in cleaned_styles:
cleaned_styles_string += "%s:%s;" % (style["name"], style["value"])
cleaned_styles_string += "{}:{};".format(style["name"], style["value"])

return cleaned_styles_string

Expand All @@ -112,8 +113,8 @@ def clean_hrefs(href_string):
if href_string.startswith("javascript:"):
logger.warning(
"Removing href string '{}' as it contains dangerous code".format(
href_string
)
href_string,
),
)
return None

Expand Down Expand Up @@ -142,8 +143,8 @@ def clean_html(html, strip_unsafe=False):
if tag.name not in getattr(settings, "ACCEPTABLE_ELEMENTS", tuple()):
logger.warning(
"Found tag {} which is not in the ACCEPTABLE_ELEMENTS setting".format(
tag.name
)
tag.name,
),
)
if tag.name in getattr(settings, "REMOVE_WITH_CONTENT", tuple()):
tag.decompose()
Expand All @@ -156,7 +157,7 @@ def clean_html(html, strip_unsafe=False):
if attr not in getattr(settings, "ACCEPTABLE_ATTRIBUTES", tuple()):
logger.warning(
"Removing attribute {} of tag {} as it is not listed in the "
"ACCEPTABLE_ATTRIBUTES settings".format(attr, tag.name)
"ACCEPTABLE_ATTRIBUTES settings".format(attr, tag.name),
)
del tag[attr]
continue
Expand All @@ -167,7 +168,7 @@ def clean_html(html, strip_unsafe=False):
elif attr == "href":
tag[attr] = clean_hrefs(tag[attr])

except:
pass
except Exception as e:
logger.debug(e, exc_info=True)

return doc.encode_contents(formatter="html").decode()
7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Development dependencies
codecov>=2.1
setuptools>=42
wheel>=0.37
twine>=3.4
pre-commit>=4.0
setuptools>=75
twine>=5.1
wheel>=0.44
57 changes: 29 additions & 28 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,46 @@

from setuptools import find_packages, setup

with open(os.path.join(os.path.dirname(__file__), 'README.md')) as readme:
with open(os.path.join(os.path.dirname(__file__), "README.md")) as readme:
README = readme.read()

# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

setup(
name='django-cleanhtmlfield',
version=os.getenv('PACKAGE_VERSION', '0.0.0').replace('refs/tags/', ''),
name="django-cleanhtmlfield",
version=os.getenv("PACKAGE_VERSION", "0.0.0").replace("refs/tags/", ""),
packages=find_packages(),
include_package_data=True,
license='MIT',
description='A simple Django app that will give you a cleaned HTML field.',
license="MIT",
description="A simple Django app that will give you a cleaned HTML field.",
long_description=README,
long_description_content_type='text/markdown', # This is important for markdown to work
url='https://github.com/anexia/django-cleanhtmlfield',
author='Andreas Stocker',
author_email='AStocker@anexia-it.com',
long_description_content_type="text/markdown", # This is important for markdown to work
url="https://github.com/anexia/django-cleanhtmlfield",
author="Andreas Stocker",
author_email="AStocker@anexia-it.com",
install_requires=[
'django',
'beautifulsoup4>=4.6,<5',
"django",
"beautifulsoup4>=4.12,<4.13",
],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 2.2',
'Framework :: Django :: 3.1',
'Framework :: Django :: 3.2',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Framework :: Django",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Framework :: Django :: 5.1",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
],
)
Loading