formtags

Python library to generate forms and validate them
Download

formtags Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Michael van Tellingen
  • Publisher web site:
  • http://code.google.com/u/michaelvantellingen/

formtags Tags


formtags Description

Python library to generate forms and validate them formtags is a Python library to generate forms and validate them using formencode and sqlalchemy.Combines formencode and sqlalchemy to quickly generate forms.Example (controller)class Controller(BaseController): def create(self): instance = model.MyObject() # Create a formtags instance and pass the sqlalchemy orm object and # the formencode schema as arguments c.formtags = formtags.FormTags(instance, schema.MyObjectSchema) # For select elements or radio buttons we can bind the options # in the controller c.formtags.bind_options('job_id', itertools.chain(, ((job.id, job.label) for job in model.meta.Session.query(model.Job))) if request.POST: try: # Merge the POST data to the instance (model.MyObject) c.formtags.merge(request.POST) model.meta.Session.add(instance) model.meta.Session.commit() redirect_to(action='succes') # Validation failed. The formencode errors are in # c.formtags.form_errors and the result in .form_result except formtags.ValidationError: content = render('/my_form.mako') return formencode.htmlfill.render( content, c.formtags.form_result, c.formtags.form_errors, auto_insert_errors=True) return render('/my_form.mako') def edit(self, id): instance = model.meta.Session.query(model.MyObject).get(id) assert instance # Create a formtags instance and pass the sqlalchemy orm object and # the formencode schema as arguments c.formtags = formtags.FormTags(instance, schema.MyObjectSchema) # For select elements or radio buttons we can bind the options # in the controller c.formtags.bind_options('job_id', itertools.chain(, ((job.id, job.label) for job in model.meta.Session.query(model.Job))) if request.POST: try: # Merge the POST data to the instance (model.MyObject) c.formtags.merge(request.POST) model.meta.Session.commit() redirect_to(action='succes') # Validation failed. The formencode errors are in # c.formtags.form_errors and the result in .form_result except formtags.ValidationError: content = render('/my_form.mako') return formencode.htmlfill.render( content, c.formtags.form_result, c.formtags.form_errors, auto_insert_errors=True) return render('/my_form.mako')Now in your template you can add the following code: ## regular input field ${c.formtags.label('attribute_name', 'Name')} ${c.formtags.text('attribute_name')} ## Create a dropdown box with the options we binded in the controller ${c.formtags.label('job_id', 'Job')} ${c.formtags.select('job_id')} ## Or we can create a group of checkboxes with the options % for checkboxctrl in c.formtags.checkboxgroup('job_id'): ${checkboxctrl.label(prepend=checkboxctrl.widget())} % endfor ## Or create a group of radiobuttons % for radiobuttonctrl in c.formtags.radiobuttongroup('job_id'): ${radiobuttonctrl.label(prepend=radiobuttonctrl.widget())} % endfor Requirements: · Python


formtags Related Software