[Checkins] SVN: grok/trunk/doc/reference/directives.rst remove incorrect, misleading example. clarify purpose of grok.adapts for multi adapters.
Kevin Teague
kevin at bud.ca
Wed Feb 18 02:46:59 EST 2009
Log message for revision 96674:
remove incorrect, misleading example. clarify purpose of grok.adapts for multi adapters.
Changed:
U grok/trunk/doc/reference/directives.rst
-=-
Modified: grok/trunk/doc/reference/directives.rst
===================================================================
--- grok/trunk/doc/reference/directives.rst 2009-02-18 07:01:15 UTC (rev 96673)
+++ grok/trunk/doc/reference/directives.rst 2009-02-18 07:46:58 UTC (rev 96674)
@@ -225,6 +225,11 @@
:func:`grok.adapts` -- declare that a class adapts certain objects
==================================================================
+In the case of a simple adapter which only requires a single object
+for adapation, the :func:`grok.context` directive is used to declare
+the interface or class the adapter is for. It is only necessary to use
+:func:`grok.adapts` to declare the adapation requirements for a multi adapter.
+
.. function:: grok.adapts(*classes_or_interfaces)
A class-level directive to declare that a class adapts objects of
@@ -232,56 +237,10 @@
This directive accepts several arguments.
- It works much like the :mod:`zope.component`\ s :func:`adapts()`,
+ It works much like the :mod:`zope.component.`:func:`adapts()`,
but you do not have to make a ZCML entry to register the adapter.
-**Example: Register a MammothSize adapter for Mammoths**
-Imagine you want to create an adapter that extends a Mammoth object
-with an ISized interface. Your code could look like this:
-
-.. code-block:: python
-
- import grok
- from zope import interface, schema
- from zope.size.interfaces import ISized
-
- class IMammoth(interface.Interface):
- name = schema.TextLine(title=u"Name")
- size = schema.TextLine(title=u"Size", default=u"Quite normal")
-
- class Mammoth(grok.Model):
- interface.implements(IMammoth)
-
- class MammothSize(object):
- grok.implements(ISized)
- grok.adapts(IMammoth)
-
- def __init__(self, context):
- self.context = context
-
- def sizeForSorting(self):
- return ('byte', 1000)
-
- def sizeForDisplay(self):
- return ('1000 bytes')
-
-When this code is "grokked" that `MammothSize` class is registered as
-an adapter that provides ISized for IMammoth objects. You could then
-perform adaptation elsewhere in your code with:
-
-.. code-block:: python
-
- manfred = Mammoth()
- from zope.size.interfaces import ISized
- size = ISized(manfred)
- return size.sizeForDisplay()
-
-.. seealso::
-
- :func:`grok.implements`
-
-
:func:`grok.baseclass` -- declare a class as base
=================================================
More information about the Checkins
mailing list