Commit db07b0b7 authored by Amos Latteier's avatar Amos Latteier

Added first cut at some basic API docs.

parent c2f76353
class DTMLDocument:
"""
A DTML Document is a Zope object that contains and executes DTML
code. It is useful to represent web pages.
"""
__extends__=(
'OFSP.ObjectManagerItem.ObjectManagerItem',
'OFSP.PropertyManager.PropertyManager',
)
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
"""
Calling a DTMLDocument causes the Document to interpret the DTML
code that it contains. The method returns the result of the
interpretation, which can be any kind of object.
To accomplish its task, DTML Document often needs to resolve various
names into objects. For example, when the code <dtml-var
spam> is executed, the DTML engine tries to resolve the name
'spam'.
In order to resolve names, the Document must be passed a
names pace to look them up in. This can be done several ways:
By passing a 'client' object -- If the argument 'client' is
passed, then names are looked up as attributes on the
argument.
By passing a 'REQUEST' mapping -- If the argument 'REQUEST'
is passed, then names are looked up as items on the
argument. If the object is not a mapping, an TypeError
will be raised when a name lookup is attempted.
By passing keyword arguments -- names and their values can
be passed as keyword arguments to the Document.
The names pace given to a DTML Document is the composite of these
three methods. You can pass any number of them or none at
all.
Passing in a names pace to a DTML Document is often referred to
as providing the Document with a *context*.
DTML Documents are called three ways:
From DTML -- A DTML Document can be called from another DTML
Method or Document::
<dtml-var standard_html_header>
<dtml-var aDTMLDocument>
<dtml-var standard_html_footer>
In this example, the Document 'aDTMLDocument' is being called
from another DTML object by name. The calling method
passes the value 'this' as the client argument and the
current DTML names pace as the REQUEST argument. The above
is identical to this following usage in a DTML Python
expression::
<dtml-var standard_html_header>
<dtml-var "aDTMLDocument(_.None, _)">
<dtml-var standard_html_footer>
From Python -- Products, External Methods, and PythonMethods
can call a DTML Document in the same way as calling a DTML
Document from a Python expression in DTML; as shown in the
previous example.
By the Publisher -- When the URL of a DTML Document is fetched
from Zope, the DTML Document is called by the publisher.
The REQUEST object is passes as the second argument to the
Document. More information on the REQUEST can be found "on
the online Interface
documentation.":http://www.zope.org/Members/michel/Projects/Interfaces/PublisherRequest
Permission -- 'View'
"""
def manage_edit(self, data, title):
"""
Change the DTML Document, replacing its contents with 'data'
and
changing its title.
The data argument may be a file object or a string.
Permission -- 'Change DTML Documents'
"""
def document_src(self):
"""
Returns the unrendered source text of the DTML Document.
Permission -- 'View management screens'
"""
def get_size(self):
"""
Returns the size of the unrendered source text of the DTML
Document in bytes.
Permission -- XXX None XXX
"""
class DTMLMethod:
"""
A DTML Method is a Zope object that contains and executes DTML
code. It can act as a template to display other objects. It can
also hold small pieces of content which are inserted into other
DTML Documents or DTML Methods.
The DTML Method's id is available via the 'document_id'
variable and the title is available via the 'document_title'
variable.
"""
__extends__=('OFSP.ObjectManagerItem.ObjectManagerItem',)
def __call__(self, client=None, REQUEST={}, **kw):
"""
Calling a DTMLMethod causes the Method to interpret the DTML
code that it contains. The method returns the result of the
interpretation, which can be any kind of object.
To accomplish its task, DTML Method often needs to resolve various
names into objects. For example, when the code <dtml-var
spam> is executed, the DTML engine tries to resolve the name
'spam'.
In order to resolve names, the Method must be passed a
names pace to look them up in. This can be done several ways:
By passing a 'client' object -- If the argument 'client' is
passed, then names are looked up as attributes on the
argument.
By passing a 'REQUEST' mapping -- If the argument 'REQUEST'
is passed, then names are looked up as items on the
argument. If the object is not a mapping, an TypeError
will be raised when a name lookup is attempted.
By passing keyword arguments -- names and their values can
be passed as keyword arguments to the Method.
The names pace given to a DTML Method is the composite of these
three methods. You can pass any number of them or none at
all.
Passing in a names pace to a DTML Method is often referred to
as providing the Method with a *context*.
DTML Methods are called three ways:
From DTML -- A DTML Method can be called from another DTML
Method or Document::
<dtml-var standard_html_header>
<dtml-var aDTMLMethod>
<dtml-var standard_html_footer>
In this example, the Method 'aDTMLMethod' is being called
from another DTML object by name. The calling method
passes the value 'this' as the client argument and the
current DTML names pace as the REQUEST argument. The above
is identical to this following usage in a DTML Python
expression::
<dtml-var standard_html_header>
<dtml-var "aDTMLMethod(_.None, _)">
<dtml-var standard_html_footer>
From Python -- Products, External Methods, and PythonMethods
can call a DTML Method in the same way as calling a DTML
Method from a Python expression in DTML; as shown in the
previous example.
By the Publisher -- When the URL of a DTML Method is fetched
from Zope, the DTML Method is called by the publisher.
The REQUEST object is passes as the second argument to the
Method. More information on the REQUEST can be found "on
the online Interface
documentation.":http://www.zope.org/Members/michel/Projects/Interfaces/PublisherRequest
Permission -- 'View'
"""
def manage_edit(self, data, title):
"""
Change the DTML Method, replacing its contents with 'data' and
changing its title.
The data argument may be a file object or a string.
Permission -- 'Change DTML Methods'
"""
def document_src(self):
"""
Returns the unrendered source text of the DTML Method.
Permission -- 'View management screens'
"""
def get_size(self):
"""
Returns the size of the unrendered source text of the DTML
Method in bytes.
Permission -- XXX None XXX
"""
class File:
"""
A File is a Zope object that contains file content. A File object
can be used to upload or download file information with Zope.
Examples:
Using a File object in Zope is easy. The most common usage is
to display the contents of a file object in a web page. This is
done by simply referencing the object from DTML::
<dtml-var standard_html_header>
<dtml-var FileObject>
<dtml-var standard_html_footer>
A more complex example is presenting the File object for
download by the user. The next example displays a link to every
File object in a folder for the user to download::
<dtml-var standard_html_header>
<ul>
<dtml-in "ObjectValues('File')">
<li><a href="<dtml-var absolute_url>"><dtml-var
id></a></li>
</dtml-in>
</ul>
<dtml-var standard_html_footer>
In this example, the 'absolute_url' method and 'id' are used to
create a list of HTML hyperlinks to all of the File objects in
the current Object Manager.
Also see Object Manager for details on the 'objectValues'
method.
"""
__extends__=(
'OFSP.ObjectManagerItem.ObjectManagerItem',
'OFSP.PropertyManager.PropertyManager',
)
def update_data(self, data, content_type=None, size=None):
"""
Updates the contents of the File with 'data'.
The 'data' argument must be a string. If 'content_type' is not
provided, then a content type will not be set. If size is not
provided, the size of the file will be computed from 'data'.
Permission -- XXX None XXX
"""
def getSize(self):
"""
Returns the size of the file in bytes.
Permission -- 'View'
"""
def getContentType(self):
"""
Returns the content type of the file.
Permission -- 'View'
"""
class Image:
"""
A Image is a Zope object that contains image content. A Image
object can be used to upload or download image information with
Zope.
Image objects have two properties the define their dimension,
'height' and 'width'. These are calculated when the image is
uploaded. For image types that Zope does not understand, these
properties may be undefined.
Examples:
Using a Image object in Zope is easy. The most common usage is
to display the contents of an image object in a web page. This
is done by simply referencing the object from DTML::
<dtml-var standard_html_header>
<dtml-var ImageObject>
<dtml-var standard_html_footer>
This will generate an HTML IMG tag referencing the URL to the
Image. This is equivalent to::
<dtml-var standard_html_header>
<dtml-with ImageObject>
<img src="<dtml-var absolute_url>">
</dtml-with>
<dtml-var standard_html_footer>
You can control the image display more precisely with the 'tag'
method. For example::
<dtml-var "ImageObject.tag(border=5, align=left)">
"""
__extends__=('OFSP.File.File',)
def tag(self, height=None, width=None, alt=None,
scale=0, xscale=0, yscale=0, **args):
"""
This method returns a string which contains an HTML IMG tag
reference to the image.
Optionally, the 'height', 'width', 'alt', 'scale', 'xscale'
and 'yscale' arguments can be provided which are turned into
HTML IMG tag attributes. Note, 'height' and 'width' are
provided by default, and 'alt' comes from the 'title_or_id'
method.
Keyword arguments may be provided to support other or future
IMG tag attributes.
Permission -- 'View'
"""
class ObjectManager:
"""
An ObjectManager contains other Zope objects. The contained
objects are Object Manager Items.
"""
def objectIds(self, type=None):
"""
This method returns a list of the ids of the contained
objects.
Optionally, you can pass an argument specifying what object
meta_type(es) to restrict the results to. This argument can be
a string specifying one meta_type, or it can be a list of
strings to specify many.
Example::
<dtml-in objectIds>
<dtml-var sequence-item>
<dtml-else>
There are no sub-objects.
</dtml-in>
This DTML code will display all the ids of the objects
contained in the current Object Manager.
Permission -- 'Access contents information'
"""
def objectValues(self, type=None):
"""
This method returns a sequence of contained objects.
Like objectValues and objectIds, it accepts one argument,
either a string or a list to restrict the results to objects
of a given meta_type or set of meta_types.
Example::
<dtml-in "objectValues('Folder')">
<dtml-var icon>
This is the icon for the: <dtml-var id> Folder<br>.
<dtml-else>
There are no Folders.
</dtml-in>
The results were restricted to Folders by passing a
meta_type to 'objectItems' method.
Permission -- 'Access contents information'
"""
def objectItems(self, type=None):
"""
This method returns a sequence of (id, object) tuples.
Each tuple's first element is the id of an object contained in
the Object Manager, and the second element is the object
itself.
Example::
<dtml-in objectItems>
id: <dtml-var sequence-key>,
type: <dtml-var meta_type>
<dtml-else>
There are no sub-objects.
</dtml-in>
Permission -- 'Access contents information'
"""
def superValues(self, t):
"""
This method returns a list of objects of a given meta_type(es)
contained in the Object Manager and all its parent Object
Managers.
The t argument specifies the meta_type(es). It can be a string
specifying one meta_type, or it can be a list of strings to
specify many.
Permission -- XXX None XXX
"""
class ObjectManagerItem:
"""
A Zope object that can be contained within an Object Manager.
Almost all Zope objects that can be managed through the web are
Object Manager Items.
Attributes
'id' -- The id of the object.
This is the unique name of the object within its parent
object manager. This should be a string, and can contain
letters, digits, underscores, dashes, commas, and spaces.
This attribute should not be changed directly.
'title' -- The title of the object.
This is an optional one-line string description of the object.
'meta_type' -- A short name for the type of the object.
This is the name that shows up in product add list for the
object and is used when filtering objects by type.
This attribute is provided by the object's class and should
not be changed directly.
'REQUEST' -- The current web request.
This object is acquired and should not be set.
"""
def title_or_id(self):
"""
If the title is not blank, return it, otherwise
return the id.
Permission -- XXX None XXX
"""
def title_and_id(self):
"""
If the title is not blank, the return the title
followed by the id in parentheses. Otherwise return the id.
Permission -- XXX None XXX
"""
def this(self):
"""
Return the object.
This turns out to be handy in two situations. First, it
provides a way to refer to an object in DTML expressions.
The second use for this is rather deep. It provides a way to
acquire an object without getting the full context that it was
acquired from. This is useful, for example, in cases where
you are in a method of a non-item subobject of an item and you
need to get the item outside of the context of the subobject.
Permission -- XXX None XXX
"""
def absolute_url(self, relative=None):
"""
Return the absolute url to the object.
If the relative argument is provided with a true value, then
the URL returned is relative to the site object. Note, if
virtual hosts are being used, then the path returned is a
logical, rather than a physical path.
Permission -- XXX None XXX
"""
def getPhysicalRoot(self):
"""
Returns the top-level Zope Application object.
Permission -- XXX None XXX
"""
\ No newline at end of file
class PropertyManager:
"""
A Property Manager object has a collection of typed attributes
called properties. Properties can be managed through the web or
via DTML.
In addition to having a type, properties can be writable or
read-only and can have default values.
"""
def getProperty(self, id, d=None):
"""
Return the value of the property 'id'. If the property is not
found the optional second argument or None is returned.
Permission -- XXX None XXX
"""
def getPropertyType(self, id):
"""
Get the type of property 'id'. Returns None if no such
property exists.
Permission -- XXX None XXX
"""
def hasProperty(self, id):
"""
Returns a true value if the Property Manager has the property
'id'. Otherwise returns a false value.
Permission -- 'Access contents information'
"""
def propertyIds(self):
"""
Returns a list of property ids.
Permission -- 'Access contents information'
"""
def propertyValues(self):
"""
Returns a list of property values.
Permission -- 'Access contents information'
"""
def propertyItems(self):
"""
Return a list of (id, property) tuples.
Permission -- 'Access contents information'
"""
def propertyMap(self):
"""
Returns a tuple of mappings, giving meta-data for properties.
The meta-data includes 'id', 'type', and 'mode'.
Permission -- XXX None XXX
"""
def propdict(self):
"""
Returns the properties as a mapping from property id to
property value.
Permission -- XXX None XXX
"""
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment