Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use zope.container and zope.lifecycleevent
- Loading branch information
1 parent
9435219
commit 39bb114
Showing
8 changed files
with
109 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
Changes | ||
======= | ||
|
||
1.2 (unreleased) | ||
---------------- | ||
|
||
* ... | ||
|
||
1.1 (2009-09-18) | ||
---------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
A site can be created by mixing in grok.Site into a grok.Model or | ||
grok.Container. | ||
>>> from zope import interface | ||
>>> from zope.app.component.interfaces import IPossibleSite, ISite | ||
>>> manfred = Mammoth() | ||
>>> IPossibleSite.providedBy(manfred) | ||
True | ||
>>> herd = Herd() | ||
>>> IPossibleSite.providedBy(herd) | ||
True | ||
>>> nonsite = NonSite() | ||
>>> IPossibleSite.providedBy(nonsite) | ||
False | ||
>>> nonsitecontainer = NonSiteContainer() | ||
>>> IPossibleSite.providedBy(nonsitecontainer) | ||
False | ||
While manfred and herd are possible sites, they are not yet sites; | ||
>>> ISite.providedBy(manfred) | ||
False | ||
>>> ISite.providedBy(herd) | ||
False | ||
When a site is added to a container it will be initialized as a site | ||
(when the ObjectAddedEvent is fired): | ||
>>> nonsitecontainer['manfred'] = manfred | ||
>>> ISite.providedBy(manfred) | ||
True | ||
>>> nonsitecontainer['herd'] = herd | ||
>>> ISite.providedBy(herd) | ||
True | ||
""" | ||
import grokcore.site | ||
from persistent import Persistent | ||
from zope.container.btree import BTreeContainer | ||
|
||
class Mammoth(grokcore.site.Site): | ||
pass | ||
|
||
class Herd(grokcore.site.Site): | ||
pass | ||
|
||
class NonSite(Persistent): | ||
pass | ||
|
||
class NonSiteContainer(BTreeContainer): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
By default, a utility is not in the public site; it's in ++etc++site. We can | ||
also specify the utility to be public. It will then be created in the container | ||
that is the site. The name the utility should have in the container can | ||
be controlled using name_in_container: | ||
>>> cave = Cave() | ||
>>> getRootFolder()["cave"] = cave | ||
>>> from zope import component | ||
>>> from zope.app.component.hooks import getSite, setSite | ||
>>> setSite(cave) | ||
>>> cave['fireplace'] is component.getUtility(IFireplace) | ||
True | ||
name_in_container can also be used for objects stored under the site manager | ||
(that is in ++etc++site): | ||
>>> cave2 = Cave2() | ||
>>> getRootFolder()['cave2'] = cave2 | ||
>>> setSite(cave2) | ||
>>> (cave2.getSiteManager()['fireplace'] is | ||
... component.getUtility(IFireplace)) | ||
True | ||
""" | ||
|
||
import grokcore.site | ||
from zope import interface | ||
from zope.container.btree import BTreeContainer | ||
|
||
class IFireplace(interface.Interface): | ||
pass | ||
|
||
class Fireplace(grokcore.site.LocalUtility): | ||
interface.implements(IFireplace) | ||
|
||
class Cave(BTreeContainer, grokcore.site.Site): | ||
grokcore.site.local_utility(Fireplace, public=True, | ||
name_in_container='fireplace') | ||
|
||
class Cave2(BTreeContainer, grokcore.site.Site): | ||
grokcore.site.local_utility(Fireplace, public=False, | ||
name_in_container='fireplace') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters