Package aquarium :: Package util :: Module Context :: Class Context
[show private | hide private]
[frames | no frames]

Class Context


Each request will have a new context.

This class defines a container for all of the information that gets passed around to all of the various screens, layouts, etc. Not everything in the context will have request scope. However, access to almost everything is provided via the context. The context is normally named ctx. Most classes subclass aquarium.util.AquariumClass and thus have self._ctx. All templates subclass aquarium.util.AquariumTemplate which puts ctx in the _searchList. Hence:

In Python                   In Cheetah
=========                   ==========

self._ctx.foo       =       $foo

Here is a list of things to expect in the context:

wsa
This wsadaptor object abstracts our interface to the Web server. See aquarium.wsadaptor.WebServerAdaptor.
iLib
This object contains a bunch of internal Aquarium functions. See aquarium.util.InternalLibrary.
form
This is an instance of aquarium.util.FormDict. It is a dict-like object representing the form.
request.cookie, response.cookie
This are instances of Cookie.SimpleCookie. See the Cookie module in the Python standard library.
cookiesVerified
If True, then we can safely use cookies.
db
This is a reference to a Python database module. Use dba instead. See the Python documentation.
dba
This is an adaptor for db. See aquarium.database.DatabaseAssistant.
session
This is a dict-like instance containing session data. See aquarium.session.SessionContainer.Session.
url
This is an urlscheme. urlscheme classes dictate how the screen parameter is positioned in URL's. See aquarium.urlscheme.UrlSchemeAPI.
screen
This is the module name (relative to the screen directory) of the currently active or requested screen.
screenInstance
This is an instance of the above screen. See aquarium.screen.ScreenAPI.
screenList
aquarium.util.Aquarium.screenLoop will add the name of the screen it is about to execute to this list before attempting to execute it.
controller
If you use aquarium.screen.Controller as the super class for your controllers, it will save a reference to the controller in the rare case you need to access the controller from the view.
actionResults
Messages that must be shown to the user can be set here by controller screens to be shown later by view screens. It is usually the layout's responsibility to output the message. You may choose to store actionResults in the session instead of ctx if you wish for it to survive redirects. See aquarium.screen.ScreenAPI and aquarium.layout.LayoutAPI. Also, see aquarium.util.ActionResults if you want more than just a simple string.

The following are for working with gettext:

translation
This is gettext.translation(...). See gettext.translation from the Python standard library.
_
This is ctx.translation.gettext. It also serves to mark the string for translation. Always use a a local variable to reference this (i.e. _("foo") instead of self._ctx._("foo")) or gettext will not be able to successfully note that the string is marked for translation.
gettext
This is the same as _, but does not mark the string for translation. This is useful if the string is a variable instead of a literal.
ngettext
This is ctx.translation.ngettext. It is like _, but for plurals.
N_
This is the identity function. It doesn't do anything other than mark the string for translation.

The following are for convenience:

properties
I.e. aquarium.conf.AquariumProperties.
cell0
The string cellspacing="0" cellpadding="0" border="0"
clearGif
An instance of aquarium.widget.ClearGif.
htmlent
A shortcut for self._ctx.iLib.htmlEntities.
jsEsc
A shortcut for self._ctx.iLib.javaScriptEscape.
jsQuote
A shortcut for self._ctx.iLib.javaScriptQuote.

Method Summary
  __init__(self)
Initialize all the convenience attributes.
  __getattr__(self, attr)
Some of the convenience attributes can't be set in __init__.
  __repr__(self)
Return a string representation of the ctx.
  _dictRepr(self, dict, indentation)
This is a repr for dicts used by __repr__ above.
  _indent(self, indentation, s, includingFirstLine)
Return s with indentation at the beginning of each line.
  _N(self, s)
This is the identity function.
  N_(self, s)
This is the identity function.

Method Details

__init__(self)
(Constructor)

Initialize all the convenience attributes.

__getattr__(self, attr)
(Qualification operator)

Some of the convenience attributes can't be set in __init__.

Some of them are only available after self.iLib is set which is sometime later.

__repr__(self)
(Representation operator)

Return a string representation of the ctx.

No HTML formatting will be used. This is so that you can use it from the shell. Use <pre> and htmlent if you need to use this on an HTML page.

The code below is funky. I did it this way so that:

  • Everything in the ctx gets printed.
  • Stuff that isn't in the ctx yet doesn't get printed.
  • Certain fields need to be printed in certain ways.

_dictRepr(self, dict, indentation='    ')

This is a repr for dicts used by __repr__ above.

_indent(self, indentation, s, includingFirstLine=True)

Return s with indentation at the beginning of each line.

_N(self, s)

This is the identity function.

It serves to tell gettext to mark the string for translation.

N_(self, s)

This is the identity function.

It serves to tell gettext to mark the string for translation.


Generated by Epydoc 2.1 on Mon Jan 1 16:34:19 2007 http://epydoc.sf.net