From ad171a82a871e8ad8b5683dd51e6db00da951e08 Mon Sep 17 00:00:00 2001 From: Raylan Date: Sat, 23 Oct 2021 15:20:57 -0300 Subject: [PATCH 1/8] Revert "Bump coverage from 5.5 to 6.0.2 (#352)" This reverts commit 41c59d6f1707af82c5eda6573abb35d3b2934e55. --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 4cd62683..700421e5 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,7 +5,7 @@ isort==5.9.3 flake8==4.0.1 pydocstyle==6.1.1 docformatter==1.4 -coverage==6.0.2 +coverage==5.5 autoflake==1.4 tox==3.24.4 pur==5.4.2 From 8638a5da6e631ea151a0b71f36e44ec1fa5ec818 Mon Sep 17 00:00:00 2001 From: Raylan Date: Sat, 23 Oct 2021 13:07:06 -0300 Subject: [PATCH 2/8] Added Widgets to make use of HTML5's date/time picker Widgets: * DateTimeWidget * DateWidget * TimeWidget --- docs/widgets.rst | 58 +++++++++++++++++++ .../bootstrap4/widgets/datetime_field.html | 1 + src/bootstrap4/widgets.py | 36 +++++++++++- tests/test_templates.py | 12 +++- 4 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 src/bootstrap4/templates/bootstrap4/widgets/datetime_field.html diff --git a/docs/widgets.rst b/docs/widgets.rst index d53e13b0..1b79a91a 100644 --- a/docs/widgets.rst +++ b/docs/widgets.rst @@ -23,3 +23,61 @@ This renders a form ChoiceField as a Bootstrap 4 button group in the `primary` B choices=((1, 'Vinyl'), (2, 'Compact Disc')), initial=1, ) + + + +DateTimeWidget +~~~~~~~~~~~~~~~~~~~~~~ + +This renders a form DateTimeField as a input of type datetime-local. + +.. code:: django + + from bootstrap4.widgets import DateTimeWidget + + class MyForm(forms.Form): + media_type = forms.DateTimeField( + help_text="Pick a Date and Time", + required=True, + label="Schedule:", + widget=DateTimeWidget, + initial=datetime.now(), + ) + + +DateWidget +~~~~~~~~~~~~~~~~~~~~~~ + +This renders a form DateField as a input of type date. + +.. code:: django + + from bootstrap4.widgets import DateWidget + + class MyForm(forms.Form): + media_type = forms.DateField( + help_text="Enter your bird day", + required=True, + label="Bird Day:", + widget=DateWidget, + initial=date.today(), + ) + + +TimeWidget +~~~~~~~~~~~~~~~~~~~~~~ + +This renders a form TimeField as a input of type time. + +.. code:: django + + from bootstrap4.widgets import TimeWidget + + class MyForm(forms.Form): + media_type = forms.TimeField( + help_text="Pick a time:", + required=True, + label="Time:", + widget=TimeWidget, + initial=datetime.now().time(), + ) diff --git a/src/bootstrap4/templates/bootstrap4/widgets/datetime_field.html b/src/bootstrap4/templates/bootstrap4/widgets/datetime_field.html new file mode 100644 index 00000000..a46c43ac --- /dev/null +++ b/src/bootstrap4/templates/bootstrap4/widgets/datetime_field.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/bootstrap4/widgets.py b/src/bootstrap4/widgets.py index 782d3a3e..9cb95367 100644 --- a/src/bootstrap4/widgets.py +++ b/src/bootstrap4/widgets.py @@ -1,5 +1,9 @@ -from django.forms import RadioSelect - +from django.forms import( + RadioSelect, + DateInput, + DateTimeInput, + TimeInput +) class RadioSelectButtonGroup(RadioSelect): """ @@ -9,3 +13,31 @@ class RadioSelectButtonGroup(RadioSelect): """ template_name = "bootstrap4/widgets/radio_select_button_group.html" + + +class DateWidget(DateInput): + """ + This widget renders a HML5 date field type and enables date picker. + """ + + input_type = "date" + + def format_value(self, value): + return str(value or '') + +class DateTimeWidget(DateTimeInput): + """ + This widget renders a HML5 datetime-local field type and enables date and time picker. + """ + + input_type = "datetime-local" + template_name = "bootstrap4/widgets/datetime_field.html" + def format_value(self, value): + return 'T'.join(str(value or '').split()) + +class TimeWidget(TimeInput): + """ + This widget renders a HML5 time field type and enables time picker. + """ + + input_type = "time" diff --git a/tests/test_templates.py b/tests/test_templates.py index 2cab665a..3c7f3a98 100644 --- a/tests/test_templates.py +++ b/tests/test_templates.py @@ -4,7 +4,12 @@ from django.template import engines from django.test import TestCase -from bootstrap4.widgets import RadioSelectButtonGroup +from bootstrap4.widgets import( + RadioSelectButtonGroup, + DateTimeWidget, + DateWidget, + TimeWidget +) RADIO_CHOICES = (("1", "Radio 1"), ("2", "Radio 2")) @@ -31,6 +36,11 @@ class TestForm(forms.Form): message = forms.CharField(required=False, help_text="my_help_text") sender = forms.EmailField(label="Sender © unicode", help_text='E.g., "me@example.com"') secret = forms.CharField(initial=42, widget=forms.HiddenInput) + + datetime = forms.DateTimeField(widget=DateTimeWidget, initial=datetime.now()) + date = forms.DateField(widget=DateWidget, initial=datetime.now().date()) + time = forms.TimeField(widget=TimeWidget, initial=datetime.now().time()) + cc_myself = forms.BooleanField( required=False, help_text='cc stands for "carbon copy." You will get a copy in your mailbox.' ) From e03614bbf1e4e342dc85cfbeb8a053586b6f8512 Mon Sep 17 00:00:00 2001 From: Raylan Date: Sat, 23 Oct 2021 14:54:33 -0300 Subject: [PATCH 3/8] Adjustment in datetime_field.html --- src/bootstrap4/templates/bootstrap4/widgets/datetime_field.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap4/templates/bootstrap4/widgets/datetime_field.html b/src/bootstrap4/templates/bootstrap4/widgets/datetime_field.html index a46c43ac..bcfdc06b 100644 --- a/src/bootstrap4/templates/bootstrap4/widgets/datetime_field.html +++ b/src/bootstrap4/templates/bootstrap4/widgets/datetime_field.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file From b7f99337bc58953ba4dd8536dac5b353427dfda4 Mon Sep 17 00:00:00 2001 From: Raylan Date: Sat, 23 Oct 2021 15:33:28 -0300 Subject: [PATCH 4/8] Redo "Bump coverage from 5.5 to 6.0.2 (#352)" --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 700421e5..4cd62683 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,7 +5,7 @@ isort==5.9.3 flake8==4.0.1 pydocstyle==6.1.1 docformatter==1.4 -coverage==5.5 +coverage==6.0.2 autoflake==1.4 tox==3.24.4 pur==5.4.2 From dfc1414f78a0128b094921d49203c66435d8d5ec Mon Sep 17 00:00:00 2001 From: jraylan Date: Wed, 8 Jun 2022 00:44:38 -0300 Subject: [PATCH 5/8] Code formatting fix --- src/bootstrap4/widgets.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bootstrap4/widgets.py b/src/bootstrap4/widgets.py index 9cb95367..1df8f61d 100644 --- a/src/bootstrap4/widgets.py +++ b/src/bootstrap4/widgets.py @@ -1,10 +1,11 @@ -from django.forms import( +from django.forms import ( RadioSelect, DateInput, DateTimeInput, TimeInput ) + class RadioSelectButtonGroup(RadioSelect): """ This widget renders a Bootstrap 4 set of buttons horizontally instead of typical radio buttons. @@ -25,6 +26,7 @@ class DateWidget(DateInput): def format_value(self, value): return str(value or '') + class DateTimeWidget(DateTimeInput): """ This widget renders a HML5 datetime-local field type and enables date and time picker. @@ -32,9 +34,11 @@ class DateTimeWidget(DateTimeInput): input_type = "datetime-local" template_name = "bootstrap4/widgets/datetime_field.html" + def format_value(self, value): return 'T'.join(str(value or '').split()) + class TimeWidget(TimeInput): """ This widget renders a HML5 time field type and enables time picker. From 9c7a472a203fb80463f665e400d53ff45674b90c Mon Sep 17 00:00:00 2001 From: jraylan Date: Wed, 8 Jun 2022 00:50:27 -0300 Subject: [PATCH 6/8] Code formatting fix --- src/bootstrap4/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap4/widgets.py b/src/bootstrap4/widgets.py index 1df8f61d..4cd1b9da 100644 --- a/src/bootstrap4/widgets.py +++ b/src/bootstrap4/widgets.py @@ -34,7 +34,7 @@ class DateTimeWidget(DateTimeInput): input_type = "datetime-local" template_name = "bootstrap4/widgets/datetime_field.html" - + def format_value(self, value): return 'T'.join(str(value or '').split()) From b9c4b0019a1bbf6794a53a7eb86c6c9a5b123c1b Mon Sep 17 00:00:00 2001 From: jraylan Date: Wed, 8 Jun 2022 01:02:29 -0300 Subject: [PATCH 7/8] Code formatting fix --- src/bootstrap4/widgets.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/bootstrap4/widgets.py b/src/bootstrap4/widgets.py index 4cd1b9da..da35c6e2 100644 --- a/src/bootstrap4/widgets.py +++ b/src/bootstrap4/widgets.py @@ -17,9 +17,7 @@ class RadioSelectButtonGroup(RadioSelect): class DateWidget(DateInput): - """ - This widget renders a HML5 date field type and enables date picker. - """ + """ This widget renders a HML5 date field type and enables date picker. """ input_type = "date" @@ -28,9 +26,7 @@ def format_value(self, value): class DateTimeWidget(DateTimeInput): - """ - This widget renders a HML5 datetime-local field type and enables date and time picker. - """ + """ This widget renders a HML5 datetime-local field type and enables date and time picker. """ input_type = "datetime-local" template_name = "bootstrap4/widgets/datetime_field.html" @@ -40,8 +36,6 @@ def format_value(self, value): class TimeWidget(TimeInput): - """ - This widget renders a HML5 time field type and enables time picker. - """ + """ This widget renders a HML5 time field type and enables time picker. """ input_type = "time" From 30fc82391250b4d078b3379d9cab6a9c97ac5a06 Mon Sep 17 00:00:00 2001 From: jraylan Date: Wed, 8 Jun 2022 01:07:01 -0300 Subject: [PATCH 8/8] Code formatting fix --- src/bootstrap4/widgets.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bootstrap4/widgets.py b/src/bootstrap4/widgets.py index da35c6e2..cb584839 100644 --- a/src/bootstrap4/widgets.py +++ b/src/bootstrap4/widgets.py @@ -17,7 +17,7 @@ class RadioSelectButtonGroup(RadioSelect): class DateWidget(DateInput): - """ This widget renders a HML5 date field type and enables date picker. """ + """This widget renders a HML5 date field type and enables date picker.""" input_type = "date" @@ -26,7 +26,7 @@ def format_value(self, value): class DateTimeWidget(DateTimeInput): - """ This widget renders a HML5 datetime-local field type and enables date and time picker. """ + """This widget renders a HML5 datetime-local field type and enables date and time picker.""" input_type = "datetime-local" template_name = "bootstrap4/widgets/datetime_field.html" @@ -36,6 +36,6 @@ def format_value(self, value): class TimeWidget(TimeInput): - """ This widget renders a HML5 time field type and enables time picker. """ + """This widget renders a HML5 time field type and enables time picker.""" input_type = "time"