Skip to content

Commit

Permalink
Improve example app
Browse files Browse the repository at this point in the history
  • Loading branch information
dyve committed Apr 25, 2021
1 parent 78d9062 commit 270a817
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
3 changes: 3 additions & 0 deletions example/app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class TestForm(forms.Form):
category5 = forms.ChoiceField(widget=RadioSelectButtonGroup, choices=MEDIA_CHOICES)
color = forms.CharField(widget=TextInput(attrs={"type": "color"}))
range = forms.IntegerField(widget=TextInput(attrs={"type": "range"}))
date5 = forms.DateField(widget=TextInput(attrs={"type": "date"}))
time5 = forms.TimeField(widget=TextInput(attrs={"type": "time"}))
url5 = forms.CharField(widget=TextInput(attrs={"type": "url"}))
addon = forms.CharField(widget=forms.TextInput(attrs={"addon_before": "before", "addon_after": "after"}))

required_css_class = "django_bootstrap5-req"
Expand Down
24 changes: 13 additions & 11 deletions example/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,42 @@ def get_context_data(self, **kwargs):
return context


class DefaultFormsetView(FormView):
class LayoutMixin:
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["layout"] = self.request.GET.get("layout", "vertical")
return context


class DefaultFormsetView(LayoutMixin, FormView):
template_name = "app/formset.html"
form_class = ContactFormSet


class DefaultFormView(FormView):
class DefaultFormView(LayoutMixin, FormView):
template_name = "app/form.html"
form_class = ContactForm


class DefaultFormByFieldView(FormView):
class DefaultFormByFieldView(LayoutMixin, FormView):
template_name = "app/form_by_field.html"
form_class = ContactForm


class FormHorizontalView(FormView):
class FormHorizontalView(LayoutMixin, FormView):
template_name = "app/form_horizontal.html"
form_class = ContactForm


class FormInlineView(FormView):
class FormInlineView(LayoutMixin, FormView):
template_name = "app/form_inline.html"
form_class = ContactForm


class FormWithFilesView(FormView):
class FormWithFilesView(LayoutMixin, FormView):
template_name = "app/form_with_files.html"
form_class = FilesForm

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["layout"] = self.request.GET.get("layout", "vertical")
return context

def get_initial(self):
return {"file4": fieldfile}

Expand Down
3 changes: 2 additions & 1 deletion example/templates/app/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

<form method="post">
{% csrf_token %}
{% bootstrap_form form %}

{% bootstrap_form form layout=layout %}

{% bootstrap_button button_type="submit" content="OK" %}
{% bootstrap_button button_type="reset" content="Cancel" %}
Expand Down
2 changes: 1 addition & 1 deletion example/templates/app/formset.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<form role="form" method="post">
{% csrf_token %}

{% bootstrap_formset form %}
{% bootstrap_formset form layout=layout %}

{% bootstrap_button button_type="submit" content="OK" %}
{% bootstrap_button button_type="reset" content="Cancel" %}
Expand Down

0 comments on commit 270a817

Please sign in to comment.