What is PylonsGenshi?

PylonsGenshi is a paster template based on the Pylons one but addressing Genshi as it's templating engine.

It basicly provides Markup wrapped webhelpers and a Formencode validate decorator designed to work with Genshi.

For an up-to-date read of the documentation, please Read the Documentation page on site.

Instalation

It's as easy as:

sudo easy_install PylonsGenshi

Or if you wish to install current trunk:

sudo easy_install http://pastie.ufsoft.org/svn/sandbox/PylonsGenshi/trunk

PylonsGenshi can optionally install the MinificationWebHelpers which would already be wrapped in Markup objects. To install that extra:

sudo easy_install PylonsGenshi[minification]

Documentation

pylonsgenshi.decorators

Genshi related decorators ported from pylons.

validate(template=None, schema=None, validators=None, form=None, variable_decode=False, dict_char='.', list_char='-', state=None, post_only=True, on_get=False)

Validate input either for a FormEncode schema, or individual validators

Given a form schema or dict of validators, validate will attempt to validate the schema or validator list.

If validation was successful, the valid result dict will be saved as self.form_result. Otherwise, the action will be re-run as if it was a GET, and the output will be filled by FormEncode's htmlfill to fill in the form field errors.

template
Refers to the Genshi template to use in case errors need to be shown.
schema
Refers to a FormEncode Schema object to use during validation.
form
Method used to display the form, which will be used to get the HTML representation of the form for error filling.
variable_decode
Boolean to indicate whether FormEncode's variable decode function should be run on the form input before validation.
dict_char
Passed through to FormEncode. Toggles the form field naming scheme used to determine what is used to represent a dict. This option is only applicable when used with variable_decode=True.
list_char
Passed through to FormEncode. Toggles the form field naming scheme used to determine what is used to represent a list. This option is only applicable when used with variable_decode=True.
post_only

Boolean that indicates whether or not GET (query) variables should be included during validation.

Warning

post_only applies to where the arguments to be validated come from. It does not restrict the form to only working with post, merely only checking POST vars.

state
Passed through to FormEncode for use in validators that utilize a state object.
on_get
Whether to validate on GET requests. By default only POST requests are validated.

Example:

class SomeController(BaseController):
    def create(self, id):
        return render('myform.html')
    @validate(template='myform.html', schema=model.forms.myshema(),
              form='create')
    def update(self, id):
        # Do something with self.form_result
        pass