YAFOWIL - Webformulare in Python ohne Kopfschmerzen

download YAFOWIL - Webformulare in Python ohne Kopfschmerzen

If you can't read please download the document

Transcript of YAFOWIL - Webformulare in Python ohne Kopfschmerzen

  • 1. Plone Konferenz Mnchen 2012 YAFOWIL (Yet Another FOrm Widget Library) Webformulare ohne Kopfschmerzen Jens W. Klein 23.02. 2012

2. Der Leidensdruck

  • I feel like a stupid beginner while doing a simple z3cform

3. Forms werden doppelt verarbeitet: Validierung und Wertumwandlung 4. Ich will keine Interfaces und Klassen schreiben mssen um Formulare zu bauen. 5. Ich will Formulare zur Laufzeit verndern knnen. 6. Ich will Formulare in Pyramid und Plone gleich erstellen knnen. 7. Designkriterien

  • Form-Widgets sind eine Datenstruktur

8. Formulare werden deklarativ erstellt. 9. Formulare sind nicht zwingend Python Code 10. Validierung und Wertumwandlung sind Eins 11. Widgets sollen flexibel zusammengebaut werden und einfach funktional erweitert weren knnen 12. Man muss kein Python Guru sein um Forms erstellen zu knnen. 13. from yafowil import factory form = factory('form', name='helloworld', props={'action': url}) form['person'] = factory('#stringfield', props={'label': 'Who?', 'value': '', 'required': True}) form['submit'] = factory('field:submit',props={'label': 'greet', 'action': 'save', 'handler':store , 'next':next }) 14. factory: form name: soundcloudsettings props: action: expr:context.action class: edit-form enableUnloadProtection widgets: - client_id: factory: field:label:error:text value: expr:context.settings.client_id props: label: Client Id required: Client Id needed. 15. - client_secret: factory: field:label:error:text value: expr:context.settings.client_secret props: label: Client Secret required: Client Secret needed. - save: factory: submit props: action: save expression: True handler: context.save next: context.next label: Save 16. import yafowil.loader defstore (widget, data): with open('storage.txt', 'a') ad f: f.write(data['person']) defnext (widget, data): return 'http://some.where.org/nextpage' 17. from yafowil import Controller controller = Controller(form, request) if not controller.next: returnredirect (controller.next) return controller.rendered 18. 19. Prinzipien

  • Runtime rules, static is subordinate,

20. Dont mess with a framework, 21. Keep it simple and pythonic, 22. No fights with storage, 23. Use chains and trees as structures. 24. Quellen

  • Software-Paket http://pypi.python.org/pypi/yafowil

25. Dokumentation http://yafowil.info 26. Beispiel: Plone Custom Searchhttp://plone.org/documentation/kb/build-a-custom-search-form-with-yafowil