Bplt11 form alchemy
-
Upload
atsushi-odagiri -
Category
Documents
-
view
104 -
download
1
description
Transcript of Bplt11 form alchemy
![Page 1: Bplt11 form alchemy](https://reader036.fdocuments.net/reader036/viewer/2022081907/54c5d5814a7959e2408b45ef/html5/thumbnails/1.jpg)
FormAlchemy
![Page 2: Bplt11 form alchemy](https://reader036.fdocuments.net/reader036/viewer/2022081907/54c5d5814a7959e2408b45ef/html5/thumbnails/2.jpg)
FormAlchemy
SQLAlchemyを使うときに、フォームライブラリはどうしよう?
FormAlchemySQLAlchemyのモデルからフォームを生成できる。
![Page 3: Bplt11 form alchemy](https://reader036.fdocuments.net/reader036/viewer/2022081907/54c5d5814a7959e2408b45ef/html5/thumbnails/3.jpg)
インストール
pip install formalchemy
(・∀・) It's so easy!
![Page 4: Bplt11 form alchemy](https://reader036.fdocuments.net/reader036/viewer/2022081907/54c5d5814a7959e2408b45ef/html5/thumbnails/4.jpg)
使い方
Personというマッピング済のクラス
fs = fa.FieldSet(Person, DBSession)
fs.render()
![Page 5: Bplt11 form alchemy](https://reader036.fdocuments.net/reader036/viewer/2022081907/54c5d5814a7959e2408b45ef/html5/thumbnails/5.jpg)
グリッドも使える
grid = fa.Grid(Person.query.all(), DBSession)
grid.render()
![Page 6: Bplt11 form alchemy](https://reader036.fdocuments.net/reader036/viewer/2022081907/54c5d5814a7959e2408b45ef/html5/thumbnails/6.jpg)
モデル同期(新規)
fs = fa.FieldSet(Person, DBSession, data=request.POST)if fs.validate(): fs.sync() DBSession.add(fs.model)
fs.modelに同期されたインスタンス
![Page 7: Bplt11 form alchemy](https://reader036.fdocuments.net/reader036/viewer/2022081907/54c5d5814a7959e2408b45ef/html5/thumbnails/7.jpg)
モデル同期(更新)
person = Person.query.filter_by(id=id).one()fs = fa.FieldSet(person, data=request.POST)if fs.validate(): fs.sync()
personはDBSessionに紐づいてるので、FieldSetに渡す必要なし。
![Page 8: Bplt11 form alchemy](https://reader036.fdocuments.net/reader036/viewer/2022081907/54c5d5814a7959e2408b45ef/html5/thumbnails/8.jpg)
カスタマイズ
パスワードフィールドにしたり、ラジオボタンに変更するなどfs.configure( options=[fs["password"].password()])
fs.configure( options=[fs["gender"].radio( [('male', MALE), ('female', FEMALE)])])
![Page 9: Bplt11 form alchemy](https://reader036.fdocuments.net/reader036/viewer/2022081907/54c5d5814a7959e2408b45ef/html5/thumbnails/9.jpg)
見た目を変える
fa.jqueryfa.bootstrapなど
名前に反して Pyramid 専用
![Page 10: Bplt11 form alchemy](https://reader036.fdocuments.net/reader036/viewer/2022081907/54c5d5814a7959e2408b45ef/html5/thumbnails/10.jpg)
デモ
![Page 11: Bplt11 form alchemy](https://reader036.fdocuments.net/reader036/viewer/2022081907/54c5d5814a7959e2408b45ef/html5/thumbnails/11.jpg)
● https://bitbucket.org/aodag/addressbook● http://docs.formalchemy.org/● http://docs.formalchemy.
org/pyramid_formalchemy/● http://docs.formalchemy.org/fa.jquery/