Package: pform
pformSimple form exampleForm contains three different subsystems, basic form attributes, fields and actions.importpformfrompyramid.httpexceptionsimportHTTPFoundclassEditForm(pform.Form):label='Edit form'fields=pform.Fieldset(pform.TextField('name',title='Name'))@pform.button('Save')defsafe_handler(self):data,errors=self.extract()iferrors:self.add_error_message(errors)self.context.name=data['name']@pform.button('Cancel')defcancel_handler(self):returnHTTPFound(location='.')This form renders one fieldnameand two actionssafeandcancel(submit buttons). Now we can render this form:frompyramid.viewimportview_config@view_config(route_name='....',renderer='myview.jinja2')defmy_view(request):form=EditForm(some_context,request)returnform()also it is possible to use form class as view:@view_config(route_name='....')classEditForm(pform.Form):fields=...To do additional custom form initialization just overrideupdatemethod, also
ifupdatemethod returns dictionary this values bypasses to form template:classEditForm(pform.Form):defupdate(self):# custom form initializationreturn{some_data:some_value}To get form values useextractmethod, this method returndataanderrors.datais a form result,errorsis a list of errors:classEditForm(pform.Form):@pform.button('Save')defsave_handler(self):data,errors=self.extract()iferrors:self.add_error_message(errors)# save data...CustomizationThere are two ways for field and form customization:Global customizationpformlibrary usesplayer::https://github.com/fafhrd91/pform/tree/master/exampleslibrary for customization.pformlibriary defines layer categoryformfor all templates.Field/form customizationAlso it is possible to customize widget of input template for each field. You can passtmpl_widgetargument to to field constructor for widget customization andtmpl_inputargument for input generation. Both arguments should be valid pyramid renderer path.
Form accepts three different templates,tmpl_view,tmpl_actionsandtmpl_widget.tmpl_viewis form renderer,tmpl_actionsif form buttons renderer,tmpl_widgetis custom field widget renderer. If field does not use customtmpl_widgetthen form automatically setstmpl_widgetfor each of this fields.ExamplesThere are several example.  You can find them in theexamplesdirectory at github.https://github.com/fafhrd91/pform/tree/master/examplesRequirementsPython 2.6+ or Python 3.2+virtualenvLicensepform is offered under the BSD license.CHANGES0.6.2 (01-16-2013)Fixed composite and options templates for Chrome0.6.1 (01-09-2012)Allow return additional data from action handlerPass different context to vocabulary factory
(depends on factory argument name: request, content, context)0.6 (01-07-2013)AddedOptionsFieldBaseMultiChoiceField.missing value is [] by defaultCopy field missing value during fieldset data extractionFixed form csrf supportFixed ‘checked’ value for radio fieldDo not use missing value if value is not validation0.5 (12-21-2012)Addedflatattribute to field and fieldset,
with flat fieldset and composite field uses primary data
dictionary instead of sub dict0.4.1 (12-20-2012)Fixed FileField validation0.4 (12-12-2012)AddedCompositefieldRender str inform:errormessageRemoveddisplaymodeSimpleTerm and SimpleVocabulary renamed to Term and VocabularyRemovedfrom_itemsandfrom_valueSimpleVocabulary methods,
use Vocabulary constructor insteadUseformlayer category for form and field templatesButton class now inherits from InputField0.3 (11-27-2012)Allow to addstras error inForm.validatemethodBetter button handlingBetter tanslations forInvalidmessagesChanged arguments order forInvalidclass contrustorAdded sub errors support toInvalidclassAddedextractparameter toButtonclass, if extract is set then action
extract values from form, adds errors to message and pass data to handlerAddedpform.button2decorator,extractparameter is trueAddedmax_sizeandallowed_typesparameters to FileFieldDo not override widget’s custom tmpl_widget0.2 (11-13-2012)Fixed submit button templateAllow to return http response from form update or action handlerAdded support forplayer.layout()0.1 (11-07-2012)Initial release