Cleanup of example
)
from examples.models import (
Artist,
+ Album,
Track,
)
from examples.views import (
@@ -324,8 +325,9 @@ class MyForm(Form):
# attr='' => instance.first_day, instance.last_day instead of instance.when.first_day, instance.when.last_day
when = DateRangeField(attr='')
- def submit(form, **_):
- print("submit handler")
+ class Meta:
+ @staticmethod
+ def actions__submit__post_handler(form, **_):
if not form.is_valid():
return
return html.pre(f"You posted {form.apply(Struct())}").bind(request=request)
@@ -333,10 +335,9 @@ def submit(form, **_):
today = datetime.date.today()
return Page(
parts__title1=Header("Without instance"),
- parts__form1=MyForm(actions__submit__post_handler=submit),
+ parts__form1=MyForm(),
parts__title2=Header("With instance"),
- parts__form2=MyForm(actions__submit__post_handler=submit,
- instance=Struct(first_day=today, last_day=today, event="Party"))
+ parts__form2=MyForm(instance=Struct(first_day=today, last_day=today, event="Party"))
)
