Best practices for manipulating template context (based on initial context)

10 views
Skip to first unread message

Geoffrey Hing

unread,
Aug 27, 2015, 3:01:51 PM8/27/15
to tarbell...@googlegroups.com
I've found for many of my Tarbell projects that I want to manipulate the context after it's been retrieved from the Google sheet.

Right now, we handle this using custom filters in the Blueprint, but this adds more cruft and {% set %} in the templates than I'd like.   I suppose another option would be to do some of these calculations in the spreadsheet itself, but I'd much rather write logic in Python, under version control.

Ideally there would be some API hook like Django's context processors that would let you alter the context after it's been loaded from DEFAULT_CONTEXT, the filesystem, or the Google sheet but before it hits the template.  

How are others handling this?

Best,
Geoff

--

David Eads

unread,
Sep 1, 2015, 12:55:55 PM9/1/15
to tarbell-project
Hey Geoff, I haven't forgotten about this, but haven't had time to respond. At the moment, there is no hook to do this -- the preview hook runs before the context is built, which was probably a mistake. But we could add one in the next release. There's probably also a more Flask-y way -- using after_request or something. I'll check it out and let you know.

David

--
Learn more about Tarbell at http://tarbell.tribapps.com
---
You received this message because you are subscribed to the Google Groups "Tarbell project discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tarbell-proje...@googlegroups.com.
To post to this group, send email to tarbell...@googlegroups.com.
Visit this group at http://groups.google.com/group/tarbell-project.
To view this discussion on the web visit https://groups.google.com/d/msgid/tarbell-project/CAMTySv6ZuK-aHdkqGQrMm-B5svXPg%3Dh9nEnd8mWLc7rP_eZ8Cg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
David Eads | http://recoveredfactory.net

"Medical statistics will be our standard of measurement: we will weigh life for life and see where the dead lie thicker, among the workers or among the privileged." -- Rudolf Virchow

Geoffrey Hing

unread,
Sep 12, 2015, 2:24:57 PM9/12/15
to tarbell...@googlegroups.com
Looked into this a bit more.  Flask has context processors, but they only allow you to add items to the context, not alter existing values.

The use case for this is to transform data in the spreadsheet, usually to add calculated values or to join data in multiple sheets.  Right now I use filters defined in the blueprint and the {% set %} template tag.

-Geoff


For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages