Package lamson :: Module view
[hide private]
[frames] | no frames]

Module view

source code

These are helper functions that make it easier to work with either Jinja2 or Mako templates. You MUST configure it by setting lamson.view.LOADER to one of the template loaders in your config.boot or config.testing.

After that these functions should just work.

Functions [hide private]
 
load(template)
Uses the registered loader to load the template you ask for.
source code
 
render(variables, template)
Takes the variables given and renders the template for you.
source code
 
respond(variables, Body=None, Html=None, **kwd)
Does the grunt work of cooking up a MailResponse that's based on a template.
source code
 
attach(msg, variables, template, filename=None, content_type=None, disposition=None)
Useful for rendering an attachment and then attaching it to the message given.
source code
Variables [hide private]
  LOADER = None
  __package__ = 'lamson'
Function Details [hide private]

load(template)

source code 

Uses the registered loader to load the template you ask for. It assumes that your loader works like Jinja2 or Mako in that it has a LOADER.get_template() method that returns the template.

render(variables, template)

source code 

Takes the variables given and renders the template for you. Assumes the template returned by load() will have a .render() method that takes the variables as a dict.

Use this if you just want to render a single template and don't want it to be a message. Use render_message if the contents of the template are to be interpreted as a message with headers and a body.

respond(variables, Body=None, Html=None, **kwd)

source code 

Does the grunt work of cooking up a MailResponse that's based
on a template.  The only difference from the lamson.mail.MailResponse
class and this (apart from variables passed to a template) are that
instead of giving actual Body or Html parameters with contents,
you give the name of a template to render.  The kwd variables are
the remaining keyword arguments to MailResponse of From/To/Subject.

For example, to render a template for the body and a .html for the Html
attachment, and to indicate the From/To/Subject do this:

    msg = view.respond(locals(), Body='template.txt', 
                      Html='template.html',
                      From='test@test.com',
                      To='receiver@test.com',
                      Subject='Test body from "%(dude)s".')

In this case you're using locals() to gather the variables needed for
the 'template.txt' and 'template.html' templates.  Each template is
setup to be a text/plain or text/html attachment.  The From/To/Subject
are setup as needed.  Finally, the locals() are also available as
simple Python keyword templates in the From/To/Subject so you can pass
in variables to modify those when needed (as in the %(dude)s in Subject).

attach(msg, variables, template, filename=None, content_type=None, disposition=None)

source code 

Useful for rendering an attachment and then attaching it to the message given. All the parameters that are in lamson.mail.MailResponse.attach are there as usual.


Variables Details [hide private]

LOADER

Value:
None

__package__

Value:
'lamson'