This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!
Project Description

Introduction

collective.wtforms is plone integration with the WTForms form library.

Basic Complete Form Example

The basic form is constructed like so:

from wtforms import Form, TextField
from wtforms import validators
class MyForm(Form):
    one = TextField("Field One", [validators.required()])
    two = TextField("Field Two")
    three = TextField("Field Three")

from collective.wtforms.views import WTFormView
class MyFormView(WTFormView):
    formClass = MyForm
    buttons = ('Create', 'Cancel')

    def submit(self, button):
        if button == 'Create' and self.validate():
            # do fun stuff here
            self.context.value = self.form.one.data

Then wire up the form with zcml:

<browser:page
    name="my-form"
    for="*"
    class=".pathto.MyFormView"
    permission="zope2.View"
/>

You can also override the template used and then do:

<form tal:replace="structure view/renderForm" />

To render the form anywhere in your view.

Fieldsets

You can specific which fields go with which fieldsets easily also:

class MyFormView(WTFormView):
    formClass = MyForm
    buttons = ('Create', 'Cancel')
    fieldsets = (
        ('Fieldset One', ('one', 'two')),
        ('Fieldset Two', ('three',))
    )

    def submit(self, button):
        if button == 'Create' and self.validate():
            # do fun stuff here
            self.context.value = self.form.one.data

This will render the form in the standard plone feildsets.

Control Panel

It’s also possible to easily construct a control panel form:

from collective.wtforms.views import WTFormControlPanelView
class MyFormView(WTFormControlPanelView):
    formClass = MyForm
    buttons = ('Save', 'Cancel')

    def submit(self, button):
        if button == 'Save' and self.validate():
            # do fun stuff here
            self.context.value = self.form.one.data

WTFormView Class Properties

formClass
The WTForm class used. Required
label
The form label that shows up in the h1 tag
description
form description
prefix
The prefix of the form input name values. Defaults to wtform
buttonPrefix
The prefix of the button names. Defaults to form.actions.
wrapWithFieldset
A boolean that decides if it should wrap the fields in a fieldset. Defaults to True
csrfProtect
Protect the form against csrf attacks. Defaults to True
buttons
An iterable of button names. Defaults to (‘Save’, ‘Cancel’)
fieldsets
An iterable of (fieldset name, (field names, …)). Defaults to empty
form
The instance of the WTForm form that is created on rendering the form.
data
Override this property to specify default values to populate the form with. This must return a dictionary.
submitted
Boolean if the form was submitted or not.
renderField(field)
Method to render a specific field.
renderForm()
Method to render the entire form.
validate()
Check csrf protection and validates the form.
submit(button)

The method you must override to handle the form sumission and run validation. Return a value to override rendering the template(self.index()). For instance, if you do a redirect, there is no need to render the page also:

def submit(self, button):
    if button == 'Save' and self.validate():
        self.context.value = self.form.one.data
        self.request.response.redirect(self.context.absolute_url())
        return 1
mungeForm(form)
A method to mess with the form after it is created. This is what can be used to apply dynamic choices.

Changelog

1.0a6 (2012-11-26)

  • handle spaces in button names [vangheem]

1.0a5 (2012-11-26)

  • handle unicode data [vangheem]
  • do not use and display dummy default form title and description
  • moved the field description after label, where commonly is
  • added locales directory, for being able to translate basic default buttons
  • provided italian translation
  • enabled the Plone form tabbing feature

1.0a4 (2012-08-29)

  • provide some bootstrap class hints

1.0a3 (2011-10-11)

  • fix issue where initial form data wouldn’t work in some instances.

1.0a2 (2011-10-06)

  • Fixed control panel template used.
  • add ability to easily mess with form after creation
  • add ability to provide initial data to form values

1.0a1 (2011-09-29)

  • Initial release
Release History

Release History

1.0a6

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0a5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0a4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0a3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0a2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0a1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
collective.wtforms-1.0a6.zip (30.7 kB) Copy SHA256 Checksum SHA256 Source Nov 26, 2012

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting