diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2013-05-29 15:57:58 -0500 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2013-05-29 15:57:58 -0500 |
commit | baf2c1c96ec4dbcbb74518852ffdf516d670347c (patch) | |
tree | a960457c6c90b2e95064168fe1cf4f69507f64eb /docs/source/pluginwriter | |
parent | 8ae5d20f197291a1cd2e211e4e5d5ede92718f52 (diff) | |
download | mediagoblin-baf2c1c96ec4dbcbb74518852ffdf516d670347c.tar.lz mediagoblin-baf2c1c96ec4dbcbb74518852ffdf516d670347c.tar.xz mediagoblin-baf2c1c96ec4dbcbb74518852ffdf516d670347c.zip |
Additional hook tips! Documentation on how to modify a wtforms form.
This commit sponsored by Gian-Maria Daffré. Thank you!
Diffstat (limited to 'docs/source/pluginwriter')
-rw-r--r-- | docs/source/pluginwriter/api.rst | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/docs/source/pluginwriter/api.rst b/docs/source/pluginwriter/api.rst index 33bb70c4..2a7f3c2d 100644 --- a/docs/source/pluginwriter/api.rst +++ b/docs/source/pluginwriter/api.rst @@ -193,3 +193,36 @@ object, so you can access this in your templates like: <img alt="A funny bunny" src="{{ request.staticdirect('images/funnybunny.png', 'mystaticname') }}" /> + + +Additional hook tips +-------------------- + +This section aims to explain some tips in regards to adding hooks to +the MediaGoblin repository. + +WTForms hooks +============= + +We haven't totally settled on a way to tranform wtforms form objects, +but here's one way. In your view:: + + from mediagoblin.foo.forms import SomeForm + + def some_view(request) + form_class = hook_transform('some_form_transform', SomeForm) + form = form_class(request.form) + +Then to hook into this form, do something in your plugin like:: + + import wtforms + + class SomeFormAdditions(wtforms.Form): + new_datefield = wtforms.DateField() + + def transform_some_form(orig_form): + class ModifiedForm(orig_form, SomeFormAdditions) + return ModifiedForm + + hooks = { + 'some_form_transform': transform_some_form} |