Skip to content

Commit

Permalink
adopt tests for issue #140
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Jun 22, 2024
1 parent 46846a1 commit 86bcdd4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
14 changes: 14 additions & 0 deletions testapp/forms/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from django.core.exceptions import ValidationError
from django.forms import fields, forms, models, widgets

from formset.renderers.bootstrap import FormRenderer as BootstrapFormRenderer
from formset.utils import FormMixin
from formset.widgets import DateInput, Selectize, SelectizeMultiple, UploadedFileInput

from testapp.models import PersonModel
Expand Down Expand Up @@ -38,6 +40,18 @@ def clean(self):
return cd


class PersonFormBootstrapRenderer(FormMixin, PersonForm):
"""
This form class shows how to use a custom renderer. The form then can be rendered using ``{{ form }}``
"""
default_renderer = BootstrapFormRenderer(
field_css_classes='row mb-3',
label_css_classes='col-sm-3',
control_css_classes='col-sm-9',
)



class ButtonActionsForm(forms.Form):
"""
This is a simple Django Form with just one input field. It is used to show how to use
Expand Down
9 changes: 9 additions & 0 deletions testapp/templates/bootstrap/person-form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "bootstrap/base.html" %}
{% load render_form from formsetify %}

{% block main-content %}
<django-formset endpoint="{{ request.path }}"{% if force_submission %} force-submission{% endif %}{% if withhold_feedback %} withhold-feedback="{{ withhold_feedback }}"{% endif %} csrf-token="{{ csrf_token }}">
{% render_form form "bootstrap" field_classes="row mb-3" label_classes="col-sm-3" control_classes="col-sm-9" %}
{% include "bootstrap/buttons.html" %}
</django-formset>
{% endblock %}
18 changes: 15 additions & 3 deletions testapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
from testapp.forms.complete import CompleteForm
from testapp.forms.contact import (
SimpleContactCollection, ContactCollection, ContactCollectionList, IntermediateContactCollectionList,
SortableContactCollection, SortableContactCollectionList)
SortableContactCollection, SortableContactCollectionList
)
from testapp.forms.birthdate import BirthdateBoxForm, BirthdateCalendarForm, BirthdateInputForm, BirthdatePickerForm
from testapp.forms.booking import BookingBoxForm, BookingCalendarForm, BookingPickerForm
from testapp.forms.country import CountryForm
Expand All @@ -49,7 +50,9 @@
from testapp.forms.moment import MomentBoxForm, MomentCalendarForm, MomentInputForm, MomentPickerForm
from testapp.forms.moon import MoonForm, MoonCalendarRenderer
from testapp.forms.opinion import OpinionForm
from testapp.forms.person import ButtonActionsForm, sample_person_data, ModelPersonForm
from testapp.forms.person import (
ButtonActionsForm, sample_person_data, ModelPersonForm, PersonForm, PersonFormBootstrapRenderer,
)
from testapp.forms.phone import PhoneForm
from testapp.forms.poll import ModelPollForm, PollCollection
from testapp.forms.profile import ProfileCollection
Expand Down Expand Up @@ -173,7 +176,8 @@ def form_valid(self, form):

def get_form_class(self):
form_class = super().get_form_class()
assert not issubclass(form_class, FormMixin)
if issubclass(form_class, FormMixin):
return form_class
attrs = self.get_css_classes()
attrs.pop('button_css_classes', None)
renderer_class = import_string(f'formset.renderers.{self.framework}.FormRenderer')
Expand Down Expand Up @@ -612,6 +616,14 @@ class CompleteForm(FormMixin, forms.Form):
form_class=ModelPersonForm,
model=PersonModel,
), name='person'),
path('person-bootstrap-renderer', DemoFormView.as_view(
form_class=PersonFormBootstrapRenderer,
template_name='testapp/extended-form.html',
), name='person-bootstrap-renderer'),
path('person-bootstrap-params', DemoFormView.as_view(
form_class=PersonForm,
template_name='bootstrap/person-form.html',
), name='person-bootstrap-params'),
path('poll', DemoModelFormView.as_view(
form_class=ModelPollForm,
model=PollModel,
Expand Down

0 comments on commit 86bcdd4

Please sign in to comment.