diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c6e78c0..c92b88c 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -6,6 +6,9 @@ on: - main pull_request: +permissions: + contents: read + jobs: tests: name: Python ${{ matrix.python-version }} @@ -51,3 +54,43 @@ jobs: flags: unittests name: codecov-umbrella fail_ci_if_error: false + + + deploy: + name: Deploy + needs: [tests] + runs-on: ubuntu-latest + if: github.ref=='refs/heads/main' && github.event_name!='pull_request' + + permissions: + contents: write + id-token: write + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + + - name: Check release + id: check_release + run: | + python -m pip install autopub + python -m pip install https://github.com/j0057/github-release/archive/master.zip + autopub check + + - name: Publish + if: ${{ steps.check_release.outputs.autopub_release=='true' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + autopub prepare + autopub commit + autopub build + autopub githubrelease + + - name: Upload package to PyPI + if: ${{ steps.check_release.outputs.autopub_release=='true' }} + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 08fd69d..8ff32a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ -# CHANGELOG for crispy-tailwind +CHANGELOG +========= -## Next Release (tbc) +1.0.0 - 2024-01-09 +------------------ -## 1.0 (2024-01-09) * Added support for Django 5.0 (#142) * Added support for Python 3.11 and 3.12 (#142) * Added support for Python 3.10 (#116) @@ -15,7 +16,9 @@ * Added docs about Tailwind CLI template discovery management command (#144) * Fixed bug with select template and disabled property (#118) -## 0.5 (2021-04-21) +0.5.0 - 2021-04-21 +------------------ + * Added support for custom widgets (#92) * Confirmed support for Django 3.2 (#91) * Dropped support for Django 3.1 (#91) @@ -23,14 +26,18 @@ See [Release Notes](https://github.com/django-crispy-forms/crispy-tailwind/milestone/5?closed=1) for full change log. -## 0.4 (2021-03-22) +0.4.0 - 2021-03-22 +------------------ + * Fixed compatibility with django-crispy-forms 1.11.2 (#86) * Fixed field names when using formsets (#84) See [Release Notes](https://github.com/django-crispy-forms/crispy-tailwind/milestone/4?closed=1) for full change log. -## 0.3 (2021-02-14) +0.3.0 - 2021-02-14 +------------------ + * Fixed non form errors (#77) * Various documentation improvements * Python 3.9 (#60) and Django 3.1 (#56) support @@ -38,7 +45,8 @@ for full change log. See [Release Notes](https://github.com/django-crispy-forms/crispy-tailwind/milestone/3?closed=1) for full change log. -## 0.2 (2020-07-11) +0.2.0 - 2020-07-11 +------------------ * Support for Formsets * Prepended and Appended inputs @@ -50,7 +58,8 @@ for full change log. See [Release Notes](https://github.com/django-crispy-forms/crispy-tailwind/milestone/2?closed=1) for full change log. -## 0.1 (2020-06-09) +0.1.0 - 2020-06-09 +------------------ * First Release, please do come and test! * Opinionated forms can be rendered with crispy filter diff --git a/crispy_tailwind/templates/tailwind/layout/attrs.html b/crispy_tailwind/templates/tailwind/layout/attrs.html new file mode 100644 index 0000000..c52de9e --- /dev/null +++ b/crispy_tailwind/templates/tailwind/layout/attrs.html @@ -0,0 +1 @@ +{% for name, value in widget.attrs.items %}{% if value is not False %} {{ name }}{% if value is not True %}="{{ value|stringformat:'s' }}"{% endif %}{% endif %}{% endfor %} diff --git a/crispy_tailwind/templates/tailwind/layout/select.html b/crispy_tailwind/templates/tailwind/layout/select.html index 6feb33e..fedda40 100644 --- a/crispy_tailwind/templates/tailwind/layout/select.html +++ b/crispy_tailwind/templates/tailwind/layout/select.html @@ -1,15 +1,21 @@ {% load crispy_forms_filters %} +{% load tailwind_filters %} {% load l10n %}
- -
- + + {% if not field.field.widget.allow_multiple_selected %} +
+ +
+ {% endif %}
diff --git a/crispy_tailwind/templates/tailwind/layout/select_option.html b/crispy_tailwind/templates/tailwind/layout/select_option.html index cfe73c6..d639609 100644 --- a/crispy_tailwind/templates/tailwind/layout/select_option.html +++ b/crispy_tailwind/templates/tailwind/layout/select_option.html @@ -1,4 +1,4 @@ {% load crispy_forms_filters %} {% load l10n %} - + diff --git a/crispy_tailwind/templatetags/tailwind_filters.py b/crispy_tailwind/templatetags/tailwind_filters.py index 4412b85..6d3c80c 100644 --- a/crispy_tailwind/templatetags/tailwind_filters.py +++ b/crispy_tailwind/templatetags/tailwind_filters.py @@ -127,3 +127,28 @@ def as_crispy_field(field, template_pack=TEMPLATE_PACK, label_class="", field_cl @register.filter(name="flatatt") def flatatt_filter(attrs): return mark_safe(flatatt(attrs)) + + +@register.filter +def build_attrs(field): + """ + Build HTML attributes for a form field, also checking for a + ``widget.allow_multiple_selected`` attribute and adding ``multiple`` to the + attributes if it is set to ``True``. + """ + attrs = field.field.widget.attrs + attrs.setdefault("id", field.auto_id) + + field_built_widget_attrs = field.build_widget_attrs(attrs) + attrs.update(field_built_widget_attrs) + + # Some custom widgets (e.g. Select2) may add additional attributes to the + # widget attrs dict. We need to add those to the attrs dict as well calling + # the widget's build_attrs method. + + built_widget_attrs = field.field.widget.build_attrs(attrs) + attrs.update(built_widget_attrs) + + if hasattr(field.field.widget, "allow_multiple_selected"): + attrs["multiple"] = attrs.get("multiple", field.field.widget.allow_multiple_selected) + return mark_safe(flatatt(attrs)) diff --git a/pyproject.toml b/pyproject.toml index 4e37c18..8d629ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,12 @@ version = {attr = "crispy_tailwind.__version__"} "Issues" = "https://github.com/django-crispy-forms/crispy-tailwind/issues" "Changelog" = "https://github.com/django-crispy-forms/crispy-tailwind/releases" +[tool.autopub] +project-name = "Crispy-Tailwind" +git-username = "botpub" +git-email = "52496925+botpub@users.noreply.github.com" +append-github-contributor = true + [tool.black] line-length = 119 target-version = ['py38'] diff --git a/tests/forms.py b/tests/forms.py index a87d443..583c485 100644 --- a/tests/forms.py +++ b/tests/forms.py @@ -16,6 +16,31 @@ class SampleForm(forms.Form): widget=forms.Select(), choices=(("accepted", "Accepted"), ("not_accepted", "Not accepted")), ) + select_multiple = forms.MultipleChoiceField(choices=[("1", "one"), ("2", "two"), ("3", "three")]) + select_required = forms.ChoiceField( + choices=[("", "Select and option"), ("1", "one"), ("2", "two"), ("3", "three")], + initial="2", + ) + grouped_select = forms.TypedChoiceField( + choices=[ + ( + "Group 1", + [ + ("1", "one"), + ("2", "two"), + ], + ), + ( + "Group 2", + [ + ("3", "three"), + ("4", "four"), + ], + ), + ], + coerce=str, + widget=forms.Select(attrs={"class": "custom-class"}), + ) def clean(self): super().clean() diff --git a/tests/results/filter/crispy_filter.html b/tests/results/filter/crispy_filter.html index b3a6027..b9e9bfa 100644 --- a/tests/results/filter/crispy_filter.html +++ b/tests/results/filter/crispy_filter.html @@ -63,7 +63,7 @@
@@ -75,3 +75,98 @@
+ +
+ +
+
+ +
+
+
+ +
+ +
+
+ +
+ + + +
+
+
+
+ +
+ +
+
+ +
+ + + +
+
+
+
diff --git a/tests/results/filter/crispy_filter_lt50.html b/tests/results/filter/crispy_filter_lt50.html index 8b5e28e..e25e265 100644 --- a/tests/results/filter/crispy_filter_lt50.html +++ b/tests/results/filter/crispy_filter_lt50.html @@ -63,7 +63,7 @@
@@ -75,3 +75,98 @@
+ +
+ +
+
+ +
+
+
+ +
+ +
+
+ +
+ + + +
+
+
+
+ +
+ +
+
+ +
+ + + +
+
+
+
diff --git a/tests/results/helper/select.html b/tests/results/helper/select.html index 1153d4d..f432751 100644 --- a/tests/results/helper/select.html +++ b/tests/results/helper/select.html @@ -2,7 +2,7 @@
- diff --git a/tests/results/table_inline_formset/table_inline_formset.html b/tests/results/table_inline_formset/table_inline_formset.html index fec3594..f064098 100644 --- a/tests/results/table_inline_formset/table_inline_formset.html +++ b/tests/results/table_inline_formset/table_inline_formset.html @@ -15,6 +15,9 @@ last name* date time* terms of service* + Select multiple* + Select required* + Grouped select* @@ -84,7 +87,7 @@
- @@ -94,6 +97,85 @@
+ +
+
+ +
+
+ + +
+
+ +
+ + + +
+
+
+ + +
+
+ +
+ + + +
+
+
+ @@ -161,7 +243,7 @@
- @@ -171,6 +253,85 @@
+ +
+
+ +
+
+ + +
+
+ +
+ + + +
+
+
+ + +
+
+ +
+ + + +
+
+
+ diff --git a/tests/results/table_inline_formset/table_inline_formset_lt50.html b/tests/results/table_inline_formset/table_inline_formset_lt50.html index 20ed633..8d24b48 100644 --- a/tests/results/table_inline_formset/table_inline_formset_lt50.html +++ b/tests/results/table_inline_formset/table_inline_formset_lt50.html @@ -15,6 +15,9 @@ last name* date time* terms of service* + Select multiple* + Select required* + Grouped select* @@ -83,7 +86,7 @@
- @@ -93,6 +96,85 @@
+ +
+
+ +
+
+ + +
+
+ +
+ + + +
+
+
+ + +
+
+ +
+ + + +
+
+
+ @@ -159,7 +241,7 @@
- @@ -169,6 +251,85 @@
+ +
+
+ +
+
+ + +
+
+ +
+ + + +
+
+
+ + +
+
+ +
+ + + +
+
+
+