.. include:: ==================================================== Rapide développement avec FormAlchemy ==================================================== :Authors: Gael Pasgrimaud :Date: $Date: 2009-05-25$ .. Cette présentation et les éléments de contenus associés sont placés dans le .. domaine public. .. class:: small * Concept * Utilisation * Extensions .. container:: handout Ce tutoriel présente FormAlchemy .. contents:: :class: handout .. |bullet| unicode:: U+02022 .. |mode| unicode:: U+00D8 .. capital o with stroke .. footer:: Pycon FR |bullet| 2009-05-31 Concept ======= * Génération simple de formulaire web * Éviter la duplication de code * Bas niveaux * Hautement configurable * Extensible * Indépendant !!! Une table ========= :: >>> from sqlalchemy import * >>> metadata = MetaData() >>> users_table = Table('users', metadata, ... Column('id', Integer, primary_key=True), ... Column('name', String), ... Column('fullname', String), ... Column('password', String) ... ) Un mapper ========= :: >>> from sqlalchemy.orm import mapper >>> class User(object): pass >>> m = mapper(User, users_table) Un formulaire ============= :: >>> from formalchemy import FieldSet >>> html = FieldSet(User()).render() >>> print html.strip() #doctest: +ELLIPSIS
... Configuration ============= * Template globale * Formulaire * Field Formulaire =========== :: >>> fs = Field(User()) ... fs.configure(include=[], ... exclude=[fs.password], ... options=[]) Field ====== :: >>> class LinkFieldRenderer(FieldRenderer): ... def render(self, **kwargs): ... """render html for edit mode""" ... import helpers as h ... return h.text_field(self.name, value=self._value, **kwargs) ... def render_readonly(self, **kwargs): ... """render html for read only mode""" ... kwargs = {'value':self.field.raw_value} ... return '%(value)s' % kwargs Extensions ========== * CouchDB * zope.interface * Interface d'administration pour Pylons En savoir plus ============== * SQLAlchemy - http://sqlachemy.org * FormAlchemy - http://formalchemy.org - http://docs.formalchemy.org * Mako - http://www.makotemplates.org/ Remerciements ============= * Alexandre Conrad * AFPy - http://www.afpy.org Questions ? ===========