Asset defined

In the TurtolCMS, an Asset is a single unit of data, which may contain many fields. This is somewhat like saying it's a row from a database, but that's not quite true, because a single Asset may easily be stored in more than one row of a database (handled by the Storage layer). Exactly which fields an Asset contains is defined by the AssetType's which the Asset belongs to or is an instance of, if you prefer that terminology. In general, you will not create any sub-classes from Asset but rather use it as is.

Most functions in Asset do very little beyond delegating to the corresponding functions in the AssetType's listed under the types key.

Asset Instance Data

An Asset is basically a fancy dictionary. There are several mandatory keys, and then a bunch of AssetType-defined keys, which fall into the namespace of the AssetType's themselves. For example, if an Asset has types TurtolCMS.Types.Widget and TurtolCMS.Types.HtmlWidget?, the dictionary will look like this:

  { id : blah
  , ...
  , TurtolCMS : {
                  Types: {
                           Widget: { ... Widget keys/values here ... }
                         , HtmlWidget: { ... HtmlWidget keys/values here ...}
                         }
                }
  }

Special sections

The '$' section (top-level key) is reserved for data calculated at Setup time. All pertinent Setup routines must honor the rules of this section, which could be subject to some pretty spectacular collisions if care is not taken to understand how various AssetType's may interact.

The '#' section is reserved for data calculated or loaded during the LoadRuntime stage. Same caveat against collision as for the '$' section.

General Functions

init

The init function sets up the basic data containers, naturally.

  __init__ (id, uri, parent=None, expires=None, lastmod=None, types=[])

Allow Access

Called before anything else to determine if the Asset may be accessed by the current user.

Setup

Setup gets called after an Asset is created. This first invokes each AssetType's Setup function, then caches the results for future use. Note that Setup should NOT load any data (or other Assets) which may change before the cache expires. Asset uses a flag in the cached data to indicate not to re-run the Setup on a loaded-from-cache Asset.

Load Runtime

LoadRuntime is called just prior to rendering, and is when dynamic data may be loaded.

Page-like Asset Functions

Context calls these functions in the order listed here on page-like Assets (HtmlPage, MediaPage?, etc). This allows an Asset to be "displayed" as the results of an HTTP request.

Post

Post handles the POST request. In most cases, Post should return a redirect, success or failure code. However, if Post returns None, the normal Head/Get? sequence will run.

Head is responsible for setting the response headers for a request. It is called for both HEAD and GET requests.

Get

Get is responsible for generating the response to a request.

Widget-like Asset Functions

For Widget-like Assets (which may also be Page-like under certain circumstances), Context or some Asset will call one or more of these as appropriate.

Render

Render spits out the data associated with the Asset. This may be an HTML fragment, image data, etc.

Render Editor

Renders the "editor" HTML for the Asset.