Skip to content

Commit

Permalink
0.7.2 - Fix for #23 (#24)
Browse files Browse the repository at this point in the history
* Fix for #23

* Updating tests to get 100% coverage

* 0.7.2 release prep
  • Loading branch information
marksweb committed Jul 27, 2021
1 parent a4a295e commit 42e92f6
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 0.7.2
=============
###### 27-07-2021
* Fix for [#23](https://github.com/marksweb/django-bleach/issues/23): `kwargs` being lost in the default form field.

Version 0.7.1
=============
###### 23-07-2021
Expand Down
2 changes: 1 addition & 1 deletion django_bleach/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
__author__ = "Tim Heap & Mark Walker"
__version__ = "0.7.1"
__version__ = "0.7.2"

VERSION = __version__.split(".")
22 changes: 11 additions & 11 deletions django_bleach/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ def formfield(self, **kwargs):

# If field doesn't have any choice return BleachField
if not self.choices:
return forms.BleachField(
label=self.verbose_name,
max_length=self.max_length,
allowed_tags=self.bleach_kwargs.get("tags"),
allowed_attributes=self.bleach_kwargs.get("attributes"),
allowed_styles=self.bleach_kwargs.get("styles"),
allowed_protocols=self.bleach_kwargs.get("protocols"),
strip_tags=self.bleach_kwargs.get("strip"),
strip_comments=self.bleach_kwargs.get("strip_comments"),
required=not self.blank,
)
kwargs.update({
"max_length": self.max_length,
"allowed_tags": self.bleach_kwargs.get("tags"),
"allowed_attributes": self.bleach_kwargs.get("attributes"),
"allowed_styles": self.bleach_kwargs.get("styles"),
"allowed_protocols": self.bleach_kwargs.get("protocols"),
"strip_tags": self.bleach_kwargs.get("strip"),
"strip_comments": self.bleach_kwargs.get("strip_comments"),
"required": not self.blank,
})
return forms.BleachField(**kwargs)

return super(BleachField, self).formfield(**kwargs)

Expand Down
3 changes: 1 addition & 2 deletions django_bleach/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ def test_custom_widget(self, settings):
test_data['bleach_styles']
)

@patch('django_bleach.forms.settings',
BLEACH_DEFAULT_WIDGET='testproject.forms.CustomBleachWidget')
@patch('django_bleach.forms.settings', BLEACH_DEFAULT_WIDGET='testproject.forms.CustomBleachWidget')
def test_custom_widget2(self, settings):
self.assertEqual(
settings.BLEACH_DEFAULT_WIDGET,
Expand Down
3 changes: 2 additions & 1 deletion django_bleach/tests/test_modelformfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Meta:


class TestModelFormField(TestCase):
@override_settings(BLEACH_DEFAULT_WIDGET='testproject.forms.CustomBleachWidget')

def setUp(self):
model_form = BleachContentModelForm()
self.form_field = model_form.fields['content']
Expand All @@ -29,6 +29,7 @@ def test_formfield_type(self):
"""
self.assertIsInstance(self.form_field, bleach_forms.BleachField)

@override_settings(BLEACH_DEFAULT_WIDGET='testproject.forms.CustomBleachWidget')
def test_custom_widget(self):
"""
Check content form field's widget is instance of default widget
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def find_variable(variable, *parts):
os.system('python setup.py sdist bdist_wheel')
sys.exit()

if sys.argv[-1] == 'release':
os.system('twine upload -r django-bleach --skip-existing dist/*')
sys.exit()

if sys.argv[-1] == 'tag':
print("Tagging the version on github:")
Expand Down
2 changes: 1 addition & 1 deletion testproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@
'django.contrib.messages.middleware.MessageMiddleware'
)

BLEACH_DEFAULT_WIDGET = 'testproject.forms.CustomBleachWidget'
# BLEACH_DEFAULT_WIDGET = 'testproject.forms.CustomBleachWidget'

0 comments on commit 42e92f6

Please sign in to comment.