Top Banner
AutoForms A custom form engine for Django @jeff_kit http://jeffkit.info 10年12月19日星期日
40

Autoforms

May 31, 2015

Download

Technology

jeff kit

A custome form engine for django
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Autoforms

AutoFormsA custom form engine for Django

@jeff_kithttp://jeffkit.info

10年12月19日星期日

Page 2: Autoforms

AutoForms is ...

• A custom form engine for django

• Django Form ++

• Declare form at runtime

• Form serialization

• http://autoforms.sandbox.jeffkit.info

10年12月19日星期日

Page 3: Autoforms

Who needs AutoForms

• Polling

• information collecting

• custom form in workflow

• a dynamic form in your Django app

• PAAS made in china

10年12月19日星期日

Page 4: Autoforms

You may seen her before

10年12月19日星期日

Page 5: Autoforms

How to ...

10年12月19日星期日

Page 6: Autoforms

installation

• git clone git://github.com/jeffkit/autoforms

• cd autoforms

• python setup.py install

10年12月19日星期日

Page 7: Autoforms

config ur Django project

• Append ‘autoforms’ to INSTALL_APPS in settings.py

• Append “(r'^form/', include('autoforms.urls'))” to urlpatterns in urls.py

• python manage.py syncdb

• And ....... Rock n’ Roll it !

10年12月19日星期日

Page 8: Autoforms

Form Administration

10年12月19日星期日

Page 9: Autoforms

Create a Form

10年12月19日星期日

Page 10: Autoforms

10年12月19日星期日

Page 11: Autoforms

Supported field types

10年12月19日星期日

Page 12: Autoforms

Preview the form

10年12月19日星期日

Page 13: Autoforms

Preview the form

How?

10年12月19日星期日

Page 14: Autoforms

ADV Field setting

• default value,datasource,validator......

• Custom Field Widget

• Custom Error message

10年12月19日星期日

Page 15: Autoforms

Advantage setting

10年12月19日星期日

Page 16: Autoforms

Advantage

Text

10年12月19日星期日

Page 17: Autoforms

Advantage

Text

Supported Widget types

10年12月19日星期日

Page 18: Autoforms

Widget Parameters

10年12月19日星期日

Page 19: Autoforms

Widget Parameters

json string

10年12月19日星期日

Page 20: Autoforms

Widget Parameters

json string

Ugly!!

10年12月19日星期日

Page 21: Autoforms

Widget Parameters

json string

Ugly!!

to be change ......

10年12月19日星期日

Page 22: Autoforms

Custom error message

10年12月19日星期日

Page 23: Autoforms

Custom error message

10年12月19日星期日

Page 24: Autoforms

Custom error message

10年12月19日星期日

Page 25: Autoforms

Custom error message

10年12月19日星期日

Page 26: Autoforms

Collecting form data

• fill a form @ form/fill/{form-id}/

• overview data @ form/overview/{form-id}/

10年12月19日星期日

Page 27: Autoforms

Code!Code!Code

• OK,here comes the high level API !

• First of all:

• from autoforms.models import Form

10年12月19日星期日

Page 28: Autoforms

Get a Form

• Empty Form

• form = Form.objects.get(pk=id).as_form()

• Form with data

• data = request.POST

• form = Form.objects.get(pk=id).as_form(data)

• ‘form’ could be a django.forms.Form object!

10年12月19日星期日

Page 29: Autoforms

render a form

• form.as_p()

• form.as_table()

• form.as_ul()

• That’s the regular Django Form api!

10年12月19日星期日

Page 30: Autoforms

Save form data

• data = request.POST

• form.persist(data)

10年12月19日星期日

Page 31: Autoforms

Load stored form datas

• datas = form.search(page,size,fields,*args,**kw)

10年12月19日星期日

Page 32: Autoforms

Play with datas

• for data in datas:

• print data.name,data.email,data.message

• ‘data’ is an instance of autoforms.models.FormInstance

10年12月19日星期日

Page 33: Autoforms

A fancy tag

• {% datalist page=1 pagesize=10 fields=name,email template=your-app/your-template.html %}

• Diaplay your form data in a table.

• All parameters are optional !

10年12月19日星期日

Page 34: Autoforms

Sth u can do with autoforms

10年12月19日星期日

Page 35: Autoforms

Poll/Collecting service

• TODOs:

• A nice form style

• An Embedable (iframe ) form page

• Simple statis logic and charts

10年12月19日星期日

Page 36: Autoforms

Form storage service

• TODOs:

• A better form data storage backend

• A Pice of javascript code

10年12月19日星期日

Page 37: Autoforms

PAAS made in China?!

• a Form is a model

• develop on line with “form + script”

• ok,it’s just a joke :P

10年12月19日星期日

Page 38: Autoforms

TODO

• i18N

• custom widget

• save the files

• a MongoDB form data storage backend

• custom validator

10年12月19日星期日

Page 39: Autoforms

Questions?

10年12月19日星期日

Page 40: Autoforms

Thank you!

10年12月19日星期日