class KitchenForm(Form): kitchen_foo = Field() fisk = Field.multi_choice( choices=[1, 2, 3, 4], parse=choice_parse, initial=[1, 2], editable=False ) textarea = Field.textarea(initial='initial value') radio = Field.radio(choices=['foo!!_"', 'bar', 'baz']) checkbox = Field.boolean() date = Field.date() choice = Field.choice(choices=['a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'X']) choice_with_groups = Field.choice( choices=['a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'X'], choice_to_optgroup=lambda choice, **_: choice[0] if choice[0].islower() else None )
class ChangeSubscriptionForm(Form): choices = Field.radio( choices=[subscribed, unsubscribed], initial=unsubscribed if subscription is None else subscribed, display_name='') passive = Field.boolean( display_name='Show only when unread', initial=subscription and subscription.subscription_type == 'passive') identifier = Field.hidden(initial=identifier_) class Meta: title = 'Change subscription' def actions__submit__post_handler(form, **_): subscription_type = 'passive' if form.fields.passive.value else 'active' if form.fields.choices.value == subscribed: if subscription is None: Subscription.objects.create( user=request.user, identifier=identifier_, subscription_type=subscription_type, ) else: subscription.subscription_type = subscription_type subscription.save() else: if subscription: subscription.delete() else: pass # already unsubscribed