From 405a471fbe24a4f7a084a7e072965d66dd0a45d4 Mon Sep 17 00:00:00 2001 From: Christoph Krybus Date: Wed, 6 Apr 2022 15:01:32 +0200 Subject: [PATCH 1/4] Copy bootstrap4/ to bulma/ so that we have a base for editing --- bulma/__init__.py | 0 bulma/admin.py | 3 + bulma/forms.py | 331 +++++++++++++++++++++++++++++++ bulma/migrations/__init__.py | 0 bulma/models.py | 6 + bulma/templates/bulma/base.html | 23 +++ bulma/templates/bulma/index.html | 53 +++++ bulma/tests.py | 3 + bulma/views.py | 53 +++++ 9 files changed, 472 insertions(+) create mode 100644 bulma/__init__.py create mode 100644 bulma/admin.py create mode 100644 bulma/forms.py create mode 100644 bulma/migrations/__init__.py create mode 100644 bulma/models.py create mode 100644 bulma/templates/bulma/base.html create mode 100644 bulma/templates/bulma/index.html create mode 100644 bulma/tests.py create mode 100644 bulma/views.py diff --git a/bulma/__init__.py b/bulma/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/bulma/admin.py b/bulma/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/bulma/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/bulma/forms.py b/bulma/forms.py new file mode 100644 index 00000000..b6c1b95b --- /dev/null +++ b/bulma/forms.py @@ -0,0 +1,331 @@ +# -*- coding: utf-8 -*- +import datetime + +from django import forms +from django.forms import widgets, modelform_factory +from crispy_forms.helper import FormHelper +from crispy_forms.layout import Layout, Div, Submit, HTML, Button, Row, Field, Column +from crispy_forms.bootstrap import AppendedText, PrependedText, PrependedAppendedText, FormActions, InlineCheckboxes, \ + InlineRadios +from django.utils import timezone + +from bootstrap4 import models + + +class MessageForm(forms.Form): + text_input = forms.CharField( + help_text="help on a text_input", + ) + text_input_a = forms.CharField() + text_input_b = forms.CharField() + text_input_c = forms.CharField() + + textarea = forms.CharField( + widget=forms.Textarea(), + help_text="help on a textarea", + ) + + radio_buttons = forms.ChoiceField( + choices=( + ('option_one', + "Option one is this and that be sure to include why it's great"), + ('option_two', + "Option two can is something else and selecting it will deselect option one") + ), + widget=forms.RadioSelect, + initial='option_two', + help_text="help on a radio_buttons", + ) + + inline_radio_buttons = forms.ChoiceField( + choices=( + ('option_one', 'option_one'), + ('option_two', 'option_two') + ), + widget=forms.RadioSelect, + initial='option_two', + help_text="help on a inline_radio_buttons", + ) + + checkboxes = forms.MultipleChoiceField( + choices=( + ('option_one', + "Option one is this and that be sure to include why it's great"), + ('option_two', + 'Option two can also be checked and included in form results'), + ('option_three', + 'Option three can yes, you guessed it also be checked and included in form results') + ), + initial='option_one', + widget=forms.CheckboxSelectMultiple, + help_text="Note: Labels surround all the options for much larger click areas and a more usable form.", + ) + + inline_checkboxes = forms.MultipleChoiceField( + choices=( + ('bird', + "it's a bird"), + ('plane', + "it's a plane"), + ('dunno', + "it's something else !") + ), + initial='option_one', + widget=forms.CheckboxSelectMultiple, + help_text="help on a inline_checkboxes", + ) + + grouped_checkboxes = forms.MultipleChoiceField( + choices=( + ('Group 1', + ((1, "Option one"), + (2, "Option two"), + (3, "Option three"))), + ('Group 2', + ((4, "Option four"), + (5, "Option five"), + (6, "Option six"))), + ), + initial=(1,), + widget=forms.CheckboxSelectMultiple, + help_text="help on a grouped_checkboxes", + ) + + appended_text = forms.CharField( + help_text="Here's more help text" + ) + + appended_text2 = forms.CharField( + help_text="And a bigger appended text field" + ) + + appended_select = forms.ChoiceField( + label="Select field with appended text", + choices=[(1, "Choice 1"), (2, "Choice 2")], + help_text="Some help text" + ) + + prepended_appended_select = forms.ChoiceField( + label="Select field with both preprended and appended text", + choices=[(1, "Choice 1"), (2, "Choice 2")], + help_text="Some help text" + ) + + prepended_select = forms.ChoiceField( + label="Select field with prepended text", + choices=[(1, "Choice 1"), (2, "Choice 2")], + help_text="Some help text" + ) + + prepended_text = forms.CharField() + + prepended_text_two = forms.CharField() + + select = forms.ChoiceField( + choices=(('1', 'North'), ('2', 'South'), ('3', 'East'), ('4', 'West')), + help_text='Direction to go' + ) + + multicolon_select = forms.MultipleChoiceField( + choices=(('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5')), + help_text=( + 'This strange option climbing out of the box is in the examples too ' + 'Only without Flexbox ' + 'https://v4-alpha.getbootstrap.com/components/forms/#form-controls'), + ) + + datetime_field = forms.SplitDateTimeField( + initial=timezone.now() + ) + boolean_field = forms.BooleanField() + + file_field = forms.FileField( + label="file_field", + widget=widgets.FileInput(), + help_text='with widgets.FileInput()' + ) + + file_field_raw = forms.FileField( + label="file_field_raw", + help_text='with default widget' + ) + + # Bootstrap4 + helper = FormHelper() + helper.layout = Layout( + Field('text_input', css_class='form-control-lg'), + Field('textarea', rows="3", css_class='form-control-lg'), + 'radio_buttons', + InlineRadios('inline_radio_buttons'), + Field('checkboxes', style="background: #FAFAFA"), + InlineCheckboxes('inline_checkboxes'), + AppendedText('appended_text', '.00'), + AppendedText('appended_text2', '.00', css_class='form-control-lg'), + AppendedText('appended_select', '.00'), + PrependedAppendedText('prepended_appended_select', '$', '.00'), + PrependedText('prepended_select', '$'), + PrependedText('prepended_text', + '', + active=True), + PrependedText('prepended_text_two', '@'), + 'select', + 'multicolon_select', + 'boolean_field', + 'file_field', + 'file_field_raw', + 'grouped_checkboxes', + Row( + Column('text_input_a','text_input_b'), + Column('text_input_c'), + ), + 'datetime_field', + FormActions( + Submit('save_changes', 'Save changes', css_class="btn-primary"), + Submit('cancel', 'Cancel'), + ) + ) + helper.use_custom_control = True + +class HorizontalMessageForm(forms.Form): + text_input = forms.CharField() + text_input_a = forms.CharField() + text_input_b = forms.CharField() + text_input_c = forms.CharField() + + textarea = forms.CharField( + widget=forms.Textarea(), + ) + + radio_buttons = forms.ChoiceField( + choices=( + ('option_one', + "Option one is this and that be sure to include why it's great"), + ('option_two', + "Option two can is something else and selecting it will deselect option one") + ), + widget=forms.RadioSelect, + initial='option_two', + help_text="help on a radio_buttons", + ) + + inline_radio_buttons = forms.ChoiceField( + choices=( + ('option_one', 'option_one'), + ('option_two', 'option_two') + ), + widget=forms.RadioSelect, + initial='option_two', + help_text="help on a inline_radio_buttons", + ) + + checkboxes = forms.MultipleChoiceField( + choices=( + ('option_one', + "Option one is this and that be sure to include why it's great"), + ('option_two', + 'Option two can also be checked and included in form results'), + ('option_three', + 'Option three can yes, you guessed it also be checked and included in form results') + ), + initial='option_one', + widget=forms.CheckboxSelectMultiple, + help_text="Note: Labels surround all the options for much larger click areas and a more usable form.", + ) + + inline_checkboxes = forms.MultipleChoiceField( + choices=( + ('bird', + "it's a bird"), + ('plane', + "it's a plane"), + ('dunno', + "it's something else !") + ), + initial='option_one', + widget=forms.CheckboxSelectMultiple, + help_text="help on a inline_checkboxes", + ) + + appended_text = forms.CharField( + help_text="Here's more help text" + ) + + appended_text2 = forms.CharField( + help_text="And a bigger appended text field" + ) + + prepended_text = forms.CharField() + + prepended_text_two = forms.CharField() + + select = forms.ChoiceField( + choices=(('1', 'North'), ('2', 'South'), ('3', 'East'), ('4', 'West')), + help_text='Direction to go' + ) + + multicolon_select = forms.MultipleChoiceField( + choices=(('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5')), + help_text=( + 'This strange option climbing out of the box is in the examples too ' + 'Only without Flexbox ' + 'https://v4-alpha.getbootstrap.com/components/forms/#form-controls'), + ) + + boolean_field = forms.BooleanField() + file_field = forms.FileField( + widget=widgets.FileInput(), + help_text='with FileInput widget', + required=True, + ) + + file_field_raw = forms.FileField( + help_text='with default widget', + required=True, + ) + + + # Bootstrap4 + helper = FormHelper() + helper.layout = Layout( + Field('text_input', css_class='form-control-lg'), + Field('textarea', rows="3", css_class='form-control-lg'), + Field('radio_buttons'), + InlineRadios('inline_radio_buttons'), + Field('checkboxes', style="background: #FAFAFA"), + InlineCheckboxes('inline_checkboxes'), + AppendedText('appended_text', '.00'), + AppendedText('appended_text2', '.00', css_class='form-control-lg'), + PrependedText('prepended_text', + '', + active=True), + PrependedText('prepended_text_two', '@'), + Field('select'), + Field('multicolon_select'), + Field('boolean_field'), + Field('file_field'), + Field('file_field_raw'), + FormActions( + Submit('save_changes', 'Save changes', css_class="btn-primary"), + Submit('cancel', 'Cancel'), + ), + Row( + Column('text_input_a','text_input_b'), + Column('text_input_c'), + ), + ) + helper.form_class = 'form-horizontal' + + helper.use_custom_control = False + helper.label_class = 'col-4' + helper.field_class = 'col-8' + +FormWithFileField = modelform_factory(models.WithFileField, fields="__all__") + +class HorizontalModelForm(forms.ModelForm): + class Meta: + model = models.WithFileField + fields = '__all__' + helper = FormHelper() + helper.label_class = 'col-4' + helper.field_class = 'col-8' + helper.form_class = 'form-horizontal' \ No newline at end of file diff --git a/bulma/migrations/__init__.py b/bulma/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/bulma/models.py b/bulma/models.py new file mode 100644 index 00000000..a435b0d3 --- /dev/null +++ b/bulma/models.py @@ -0,0 +1,6 @@ +from django.db import models + +# Create your models here. +class WithFileField(models.Model): + my_file = models.FileField(null=True, blank=True, help_text="help") + my_char = models.CharField(null=True, blank=True, help_text="help", max_length=32) diff --git a/bulma/templates/bulma/base.html b/bulma/templates/bulma/base.html new file mode 100644 index 00000000..6381ddf9 --- /dev/null +++ b/bulma/templates/bulma/base.html @@ -0,0 +1,23 @@ + + + + + + Bootstrap 4 | Crispy Forms Test Project + + + + + + + +
+ {% block content %} + {% endblock %} +
+ + + + + + diff --git a/bulma/templates/bulma/index.html b/bulma/templates/bulma/index.html new file mode 100644 index 00000000..883f0799 --- /dev/null +++ b/bulma/templates/bulma/index.html @@ -0,0 +1,53 @@ +{% extends 'bootstrap4/base.html' %} +{% load crispy_forms_tags %} + +{% block content %} + + +

Bootstrap 4

+
+
+ {% csrf_token %} +
+

Default form

+ {% crispy default_form %} +
+
+

Default form with failing validation #

+ {% crispy default_form_failing %} +
+
+

Model form #

+ {% crispy model_form %} +
+
+

Horizontal Model form #

+ {% crispy horizontal_model_form %} +
+
+

Horizontal form #

+ {% crispy horizontal_form %} +
+
+

Horizontal form with failing validation #

+ {% crispy horizontal_form_failing %} +
+
+
+{% endblock %} diff --git a/bulma/tests.py b/bulma/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/bulma/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/bulma/views.py b/bulma/views.py new file mode 100644 index 00000000..d26989e0 --- /dev/null +++ b/bulma/views.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +import os + +import errno +from django.conf import settings +from django.shortcuts import render + +from bootstrap4.forms import FormWithFileField, HorizontalModelForm +from bootstrap4.models import WithFileField + + +def index(request): + settings.CRISPY_TEMPLATE_PACK = 'bootstrap4' + from bootstrap4.forms import HorizontalMessageForm, MessageForm + + filename = '.' + ("/somedire" * 10) + try: + os.makedirs(filename) + except FileExistsError as e: + assert e.errno is errno.EEXIST + filename += "/" + ("myfile-" * 10) + ".txt" + with open(filename, "w") as f: + f.write('Hello world') + instance = WithFileField(my_file=filename) + + # This view is missing all form handling logic for simplicity of the example + return render(request, 'bootstrap4/index.html', + { + 'model_form': FormWithFileField( + instance=instance, + prefix='model_form', + ), + 'horizontal_model_form': HorizontalModelForm( + instance=instance, + prefix='horizontal_model_form', + ), + 'default_form': MessageForm( + data=request.POST if request.method == "POST" else None, + prefix='default_form', + ), + 'horizontal_form': HorizontalMessageForm( + data=request.POST if request.method == "POST" else None, + prefix='horizontal_form', + ), + 'default_form_failing': MessageForm( + data={}, + prefix='default_form_failing', + ), + 'horizontal_form_failing': HorizontalMessageForm( + data={}, + prefix='horizontal_form_failing', + ), + }) From d763ac5dfd61e6ab8ad115dfbe5b7264682bb9d8 Mon Sep 17 00:00:00 2001 From: Christoph Krybus Date: Tue, 10 May 2022 16:28:41 +0200 Subject: [PATCH 2/4] Fix topbar menu - only the link to the current tab should be marked as "active" - each tab should link to all other tabs --- bootstrap3/templates/bootstrap3/index.html | 5 +++-- bootstrap4/templates/bootstrap4/index.html | 4 ++-- django_rendering/templates/django_rendering/index.html | 6 +++--- semantic/templates/semantic/index.html | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bootstrap3/templates/bootstrap3/index.html b/bootstrap3/templates/bootstrap3/index.html index 085f1850..0ce1b236 100644 --- a/bootstrap3/templates/bootstrap3/index.html +++ b/bootstrap3/templates/bootstrap3/index.html @@ -15,9 +15,10 @@ diff --git a/bootstrap4/templates/bootstrap4/index.html b/bootstrap4/templates/bootstrap4/index.html index 883f0799..733c5047 100644 --- a/bootstrap4/templates/bootstrap4/index.html +++ b/bootstrap4/templates/bootstrap4/index.html @@ -14,8 +14,8 @@ - diff --git a/django_rendering/templates/django_rendering/index.html b/django_rendering/templates/django_rendering/index.html index 75b7cdcb..85ae9330 100644 --- a/django_rendering/templates/django_rendering/index.html +++ b/django_rendering/templates/django_rendering/index.html @@ -12,10 +12,10 @@ Bootstrap 3 - diff --git a/semantic/templates/semantic/index.html b/semantic/templates/semantic/index.html index 7f516d9a..3d4f3499 100644 --- a/semantic/templates/semantic/index.html +++ b/semantic/templates/semantic/index.html @@ -5,6 +5,7 @@
diff --git a/bootstrap4/templates/bootstrap4/index.html b/bootstrap4/templates/bootstrap4/index.html index 733c5047..d7ebfa37 100644 --- a/bootstrap4/templates/bootstrap4/index.html +++ b/bootstrap4/templates/bootstrap4/index.html @@ -14,6 +14,9 @@ + diff --git a/bulma/forms.py b/bulma/forms.py index b6c1b95b..47e7a6a1 100644 --- a/bulma/forms.py +++ b/bulma/forms.py @@ -4,11 +4,12 @@ from django import forms from django.forms import widgets, modelform_factory from crispy_forms.helper import FormHelper -from crispy_forms.layout import Layout, Div, Submit, HTML, Button, Row, Field, Column -from crispy_forms.bootstrap import AppendedText, PrependedText, PrependedAppendedText, FormActions, InlineCheckboxes, \ - InlineRadios +from crispy_forms.layout import Layout, Div, HTML, Field from django.utils import timezone +from crispy_bulma.bulma import InlineCheckboxes, InlineRadios +from crispy_bulma.layout import Button, Column, IconField, FormGroup, Row, Submit + from bootstrap4 import models @@ -91,6 +92,10 @@ class MessageForm(forms.Form): help_text="help on a grouped_checkboxes", ) + icon_field = forms.CharField( + help_text="Here's more help text this time on an icon field" + ) + appended_text = forms.CharField( help_text="Here's more help text" ) @@ -150,41 +155,35 @@ class MessageForm(forms.Form): help_text='with default widget' ) - # Bootstrap4 + # Bulma helper = FormHelper() helper.layout = Layout( Field('text_input', css_class='form-control-lg'), - Field('textarea', rows="3", css_class='form-control-lg'), + Field('textarea', rows="3", css_class='is-primary is-large'), 'radio_buttons', InlineRadios('inline_radio_buttons'), Field('checkboxes', style="background: #FAFAFA"), InlineCheckboxes('inline_checkboxes'), - AppendedText('appended_text', '.00'), - AppendedText('appended_text2', '.00', css_class='form-control-lg'), - AppendedText('appended_select', '.00'), - PrependedAppendedText('prepended_appended_select', '$', '.00'), - PrependedText('prepended_select', '$'), - PrependedText('prepended_text', - '', - active=True), - PrependedText('prepended_text_two', '@'), + IconField("icon_field", icon_prepend="fa fa-user"), 'select', - 'multicolon_select', + Field('multicolon_select', size="5"), 'boolean_field', 'file_field', 'file_field_raw', - 'grouped_checkboxes', + # TODO + # 'grouped_checkboxes', Row( Column('text_input_a','text_input_b'), Column('text_input_c'), ), - 'datetime_field', - FormActions( - Submit('save_changes', 'Save changes', css_class="btn-primary"), - Submit('cancel', 'Cancel'), + # TODO + # 'datetime_field', + FormGroup( + Submit('save_changes', 'Save changes', css_class="is-primary"), + Button('Cancel'), ) ) - helper.use_custom_control = True + class HorizontalMessageForm(forms.Form): text_input = forms.CharField() @@ -283,8 +282,7 @@ class HorizontalMessageForm(forms.Form): required=True, ) - - # Bootstrap4 + # Bulma helper = FormHelper() helper.layout = Layout( Field('text_input', css_class='form-control-lg'), @@ -293,31 +291,18 @@ class HorizontalMessageForm(forms.Form): InlineRadios('inline_radio_buttons'), Field('checkboxes', style="background: #FAFAFA"), InlineCheckboxes('inline_checkboxes'), - AppendedText('appended_text', '.00'), - AppendedText('appended_text2', '.00', css_class='form-control-lg'), - PrependedText('prepended_text', - '', - active=True), - PrependedText('prepended_text_two', '@'), Field('select'), Field('multicolon_select'), Field('boolean_field'), Field('file_field'), Field('file_field_raw'), - FormActions( - Submit('save_changes', 'Save changes', css_class="btn-primary"), - Submit('cancel', 'Cancel'), - ), - Row( - Column('text_input_a','text_input_b'), - Column('text_input_c'), + FormGroup( + Submit('save_changes', 'Save changes', css_class="is-primary"), + Button('Cancel'), ), ) - helper.form_class = 'form-horizontal' + helper.form_horizontal = True - helper.use_custom_control = False - helper.label_class = 'col-4' - helper.field_class = 'col-8' FormWithFileField = modelform_factory(models.WithFileField, fields="__all__") @@ -326,6 +311,4 @@ class Meta: model = models.WithFileField fields = '__all__' helper = FormHelper() - helper.label_class = 'col-4' - helper.field_class = 'col-8' - helper.form_class = 'form-horizontal' \ No newline at end of file + helper.form_horizontal = True diff --git a/bulma/templates/bulma/base.html b/bulma/templates/bulma/base.html index 6381ddf9..e119d023 100644 --- a/bulma/templates/bulma/base.html +++ b/bulma/templates/bulma/base.html @@ -1,23 +1,16 @@ - - - - - Bootstrap 4 | Crispy Forms Test Project - + + + Bulma | Crispy Forms Test Project - - - - -
- {% block content %} - {% endblock %} -
- - - - - + + + + +
+ {% block content %} + {% endblock %} +
+ diff --git a/bulma/templates/bulma/index.html b/bulma/templates/bulma/index.html index 883f0799..3cc92220 100644 --- a/bulma/templates/bulma/index.html +++ b/bulma/templates/bulma/index.html @@ -1,53 +1,69 @@ -{% extends 'bootstrap4/base.html' %} +{% extends 'bulma/base.html' %} {% load crispy_forms_tags %} {% block content %} -
diff --git a/test_project/settings.py b/test_project/settings.py index bca6eb8f..5ef47eb1 100644 --- a/test_project/settings.py +++ b/test_project/settings.py @@ -43,10 +43,12 @@ # dependencies 'crispy_forms', 'crispy_forms_semantic_ui', + 'crispy_bulma', # internal apps 'bootstrap3', 'bootstrap4', 'semantic', + 'bulma', 'django_rendering', ) @@ -78,7 +80,7 @@ }, ] -CRISPY_ALLOWED_TEMPLATE_PACKS = ('bootstrap', 'uni_form', 'bootstrap3', 'bootstrap4', 'semantic-ui',) +CRISPY_ALLOWED_TEMPLATE_PACKS = ('bootstrap', 'uni_form', 'bootstrap3', 'bootstrap4', 'bulma', 'semantic-ui',) WSGI_APPLICATION = 'test_project.wsgi.application' diff --git a/test_project/urls.py b/test_project/urls.py index 2081a646..347519dc 100644 --- a/test_project/urls.py +++ b/test_project/urls.py @@ -17,6 +17,7 @@ from bootstrap3.views import index as bootstrap_3_preview from bootstrap4.views import index as bootstrap_4_preview +from bulma.views import index as bulma_preview from semantic.views import index as semantic_preview from django_rendering.views import index as django_rendering_preview @@ -25,5 +26,6 @@ path('django', django_rendering_preview, name='django_rendering.views.index'), path('bootstrap3', bootstrap_3_preview, name='bootstrap3.views.index'), path('bootstrap4', bootstrap_4_preview, name='bootstrap4.views.index'), + path('bulma', bulma_preview, name='bulma.views.index'), path('semantic', semantic_preview, name='semantic.views.index'), ] From 0ecc30122a9afa0fbc1c6fb9e3e45d9481eea87d Mon Sep 17 00:00:00 2001 From: Christoph Krybus Date: Fri, 4 Aug 2023 16:18:24 +0200 Subject: [PATCH 4/4] Add more bulma fields --- bulma/forms.py | 55 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/bulma/forms.py b/bulma/forms.py index 47e7a6a1..32f85c40 100644 --- a/bulma/forms.py +++ b/bulma/forms.py @@ -2,15 +2,17 @@ import datetime from django import forms -from django.forms import widgets, modelform_factory +from django.forms import modelform_factory from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout, Div, HTML, Field +from crispy_forms.bootstrap import AppendedText, PrependedText, PrependedAppendedText from django.utils import timezone from crispy_bulma.bulma import InlineCheckboxes, InlineRadios from crispy_bulma.layout import Button, Column, IconField, FormGroup, Row, Submit +from crispy_bulma.widgets import FileUploadInput -from bootstrap4 import models +from bulma.models import WithFileField class MessageForm(forms.Form): @@ -21,6 +23,14 @@ class MessageForm(forms.Form): text_input_b = forms.CharField() text_input_c = forms.CharField() + integer_input = forms.IntegerField() + decimal_input = forms.DecimalField() + url_input = forms.URLField() + time_input = forms.TimeField() + date_input = forms.DateField() + datetime_input = forms.DateTimeField() + password_input = forms.CharField(widget=forms.PasswordInput, label="Password") + textarea = forms.CharField( widget=forms.Textarea(), help_text="help on a textarea", @@ -139,20 +149,20 @@ class MessageForm(forms.Form): 'https://v4-alpha.getbootstrap.com/components/forms/#form-controls'), ) - datetime_field = forms.SplitDateTimeField( + split_datetime_field = forms.SplitDateTimeField( initial=timezone.now() ) boolean_field = forms.BooleanField() file_field = forms.FileField( label="file_field", - widget=widgets.FileInput(), + widget=FileUploadInput(), help_text='with widgets.FileInput()' ) file_field_raw = forms.FileField( label="file_field_raw", - help_text='with default widget' + help_text='with default widget', ) # Bulma @@ -168,7 +178,7 @@ class MessageForm(forms.Form): 'select', Field('multicolon_select', size="5"), 'boolean_field', - 'file_field', + Field('file_field', css_class='is-primary is-large'), 'file_field_raw', # TODO # 'grouped_checkboxes', @@ -176,12 +186,26 @@ class MessageForm(forms.Form): Column('text_input_a','text_input_b'), Column('text_input_c'), ), + "integer_input", + "decimal_input", + "url_input", + "time_input", + "date_input", + # TODO - # 'datetime_field', + #'split_datetime_field', + FormGroup( + Submit('save_changes', 'Save changes', css_class="is-primary is-large"), + Button('Cancel'), + ), + "datetime_input", + "password_input", + FormGroup( Submit('save_changes', 'Save changes', css_class="is-primary"), Button('Cancel'), - ) + ), + ) @@ -272,7 +296,7 @@ class HorizontalMessageForm(forms.Form): boolean_field = forms.BooleanField() file_field = forms.FileField( - widget=widgets.FileInput(), + widget=FileUploadInput(), help_text='with FileInput widget', required=True, ) @@ -304,11 +328,20 @@ class HorizontalMessageForm(forms.Form): helper.form_horizontal = True -FormWithFileField = modelform_factory(models.WithFileField, fields="__all__") + +class WithFileForm(forms.ModelForm): + class Meta: + fields = ['my_file', 'my_char'] + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['my_file'].widget = FileUploadInput() + + +FormWithFileField = modelform_factory(WithFileField, form=WithFileForm) class HorizontalModelForm(forms.ModelForm): class Meta: - model = models.WithFileField + model = WithFileField fields = '__all__' helper = FormHelper() helper.form_horizontal = True