Skip to content

Commit

Permalink
[release] version 1.2.2
Browse files Browse the repository at this point in the history
- Add  
  - `django_boost.forms.mixins.FieldRenameMixin`  
- Fix  
  - Fixed an issue where `*.html` and `*.mo` were not included in the distribution package
  • Loading branch information
ChanTsune authored Dec 1, 2019
2 parents e93d4a6 + 15c2d87 commit 8c12b66
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 3 deletions.
7 changes: 7 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Versions

### 1.2.3

- Add
- `django_boost.forms.mixins.FieldRenameMixin`
- Fix
- Fixed an issue where `*.html` and `*.mo` were not included in the distribution package

### 1.2.2

- Add
Expand Down
2 changes: 1 addition & 1 deletion django_boost/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.utils.version import get_version

VERSION = (1, 2, 2, 'final', 0)
VERSION = (1, 2, 3, 'final', 0)

__version__ = get_version(VERSION)
32 changes: 32 additions & 0 deletions django_boost/forms/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,38 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)


class FieldRenameMixin:
"""
``FieldRenameMixin`` that changes form field names.
Due to Python syntax, ``-`` cannot be included in form field names.
Use it when the value of ``name`` attribute of
HTML input element includes ``-`` due to restrictions of external library.
::
from django import form
from django_boost.forms.mixins import FieldRenameMixin
class MyForm(FieldRenameMixin,forms.Form):
token_id = forms.CharField()
rename_field = {"token_id": "token-id"}
MyForm().cleaned_data["token-id"]
"""

rename_fields = {}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for key, value in self.rename_fields.items():
if key != value:
self.fields[value] = self.fields[key]
del self.fields[key]


class MatchedObjectGetMixin:
"""
MatchedObjectGetMixin.
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# The short X.Y version
version = '1.2'
# The full version, including alpha/beta/rc tags
release = '1.2'
release = '1.2.3'


# -- General configuration ---------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions docs/form_mixins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ Also can inline multiple relationships.
class Meta:
model = MyModel
fields = ('name', )

.. autoclass:: django_boost.forms.mixins.FieldRenameMixin

3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def read(fname):

setup(
name='django_boost',
version='1.2.2',
version='1.2.3',
description='Django Extension library',
long_description=read('README.md'),
long_description_content_type="text/markdown",
Expand All @@ -64,6 +64,7 @@ def read(fname):
license='MIT',
keywords='django extension',
packages=packages,
package_data=package_data,
platforms=['any'],
install_requires=requires,
classifiers=[
Expand Down
16 changes: 16 additions & 0 deletions tests/tests/forms_mixins/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,19 @@ def test_reverse_many_to_many_update(self):
@classmethod
def tearDownClass(cls):
pass


class TestFieldRenameMixin(TestCase):

def test_field(self):
from django import forms
from django_boost.forms.mixins import FieldRenameMixin

class MyForm(FieldRenameMixin, forms.Form):
token_id = forms.CharField()
rename_fields = {"token_id": "token-id"}

form = MyForm()

self.assertIn("token-id", form.fields.keys())
self.assertNotIn("token_id", form.fields.keys())

0 comments on commit 8c12b66

Please sign in to comment.