Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
svn merge -r 121965:121982 svn+ssh://svn.zope.org/repos/main/grokcore…
….view/branches/jw-contentproviders .
- Loading branch information
Showing
29 changed files
with
542 additions
and
20 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
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
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 @@ | ||
#package |
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,64 @@ | ||
""" | ||
Content providers auto-associate with the context object that may be in a | ||
module. | ||
Set up the model object to view:: | ||
>>> root = getRootFolder() | ||
>>> root['cave'] = cave = Cave() | ||
We also set up another model that the content provider should not be auto- | ||
associated with:: | ||
>>> root['club'] = club = Club() | ||
Let's get a content rpvoider associated with ``cave``:: | ||
>>> from zope.publisher.browser import TestRequest | ||
>>> request = TestRequest() | ||
>>> from zope import component | ||
>>> view = component.getMultiAdapter((cave, request), name='index') | ||
>>> from zope.contentprovider.interfaces import IContentProvider | ||
>>> mgr = component.getMultiAdapter((cave, request, view), IContentProvider, | ||
... 'manage.cavemen') | ||
We cannot get this content provider for ``club``, as there is none associated | ||
with that as a context for the given name:: | ||
>>> component.queryMultiAdapter((club, request, view), IContentProvider, | ||
... 'manage.caveman') is None | ||
True | ||
Ther is for one with a different name, using an explicit grok.context directive | ||
however: | ||
>>> mgr = component.getMultiAdapter((club, request, view), IContentProvider, | ||
... 'manage.clubmen') | ||
""" | ||
|
||
import zope.interface | ||
import grokcore.view as grok | ||
from context_fixture import Club | ||
|
||
class CavemenContentProvider(grok.ContentProvider): | ||
grok.name('manage.cavemen') | ||
|
||
def render(self): | ||
pass | ||
|
||
class Cave(grok.Context): | ||
pass | ||
|
||
class Index(grok.View): | ||
grok.context(zope.interface.Interface) | ||
|
||
def render(self): | ||
return u"Hi" | ||
|
||
class ClubContentProvider(grok.ContentProvider): | ||
grok.name('manage.clubmen') | ||
grok.context(Club) | ||
|
||
def render(self): | ||
pass |
10 changes: 10 additions & 0 deletions
10
src/grokcore/view/ftests/contentprovider/context_fixture.py
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,10 @@ | ||
""" | ||
This file is used by viewlet_context. It defines a model that the viewlets | ||
and viewlet manager should *not* be associating with. | ||
""" | ||
|
||
import grokcore.view as grok | ||
|
||
class Club(grok.Context): | ||
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,49 @@ | ||
""" | ||
Verify that associating a content provider with an view interface instead of | ||
with a view class works as expected. | ||
Set up the model object to view:: | ||
>>> root = getRootFolder() | ||
>>> root['cave'] = Cave() | ||
Viewing the cave object should result in the content provider being displayed, | ||
as it is associated with the view's interface:: | ||
>>> from zope.app.wsgi.testlayer import Browser | ||
>>> browser = Browser() | ||
>>> browser.handleErrors = False | ||
>>> browser.open("http://localhost/cave") | ||
>>> print browser.contents | ||
Hi | ||
>>> browser.open("http://localhost/cave/@@secondindex") | ||
>>> print browser.contents | ||
Hi | ||
""" | ||
|
||
from zope.interface import Interface | ||
import grokcore.view as grok | ||
|
||
class Cave(grok.Context): | ||
pass | ||
|
||
class ICavemenView(Interface): | ||
pass | ||
|
||
class Index(grok.View): | ||
grok.implements(ICavemenView) | ||
|
||
class CavemenContentProvider(grok.ContentProvider): | ||
grok.name('manage.cavemen') | ||
grok.view(ICavemenView) | ||
|
||
def render(self): | ||
return u'Hi' | ||
|
||
class SecondIndex(grok.View): | ||
grok.implements(ICavemenView) | ||
|
||
def render(self): | ||
return u'Hi' |
1 change: 1 addition & 0 deletions
1
src/grokcore/view/ftests/contentprovider/interface_templates/index.pt
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 @@ | ||
<tal:block content="provider:manage.cavemen" /> |
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 @@ | ||
""" | ||
Content providers can be discriminated based on layer too:: | ||
>>> root = getRootFolder() | ||
>>> root['wilma'] = CaveWoman() | ||
Traverse to the view on the model object. We get the content provider | ||
registered for the default layer:: | ||
>>> from zope.app.wsgi.testlayer import Browser | ||
>>> browser = Browser() | ||
>>> browser.handleErrors = False | ||
>>> browser.open("http://localhost/wilma/@@caveview") | ||
>>> print browser.contents | ||
Soup pot | ||
Traverse to the view on the model object. We get the content provider | ||
registered for the "boneskin" layer:: | ||
>>> browser.open("http://localhost/++skin++boneskin/wilma/@@caveview") | ||
>>> print browser.contents | ||
Layered pot | ||
""" | ||
|
||
from zope.interface import Interface | ||
from zope.publisher.interfaces.browser import IDefaultBrowserLayer | ||
import grokcore.view as grok | ||
|
||
class CaveWoman(grok.Context): | ||
pass | ||
|
||
class CaveView(grok.View): | ||
grok.context(Interface) | ||
|
||
class Pot(grok.ContentProvider): | ||
grok.context(Interface) | ||
|
||
def render(self): | ||
return u"Soup pot" | ||
|
||
class IBoneLayer(IDefaultBrowserLayer): | ||
grok.skin('boneskin') | ||
|
||
class LayeredPot(grok.ContentProvider): | ||
grok.name('pot') | ||
grok.context(Interface) | ||
grok.layer(IBoneLayer) | ||
|
||
def render(self): | ||
return u"Layered pot" |
1 change: 1 addition & 0 deletions
1
src/grokcore/view/ftests/contentprovider/layer_templates/caveview.pt
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 @@ | ||
<span tal:replace="provider:pot" /> |
Oops, something went wrong.