[Checkins] SVN: grok/branches/darrylcousins-branch/ Added
mars.contentprovider
Darryl Cousins
darryl at darrylcousins.net.nz
Thu Jul 5 02:29:08 EDT 2007
Log message for revision 77443:
Added mars.contentprovider
Changed:
U grok/branches/darrylcousins-branch/buildout.cfg
A grok/branches/darrylcousins-branch/mars.contentprovider/
A grok/branches/darrylcousins-branch/mars.contentprovider/setup.py
A grok/branches/darrylcousins-branch/mars.contentprovider/src/
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/__init__.py
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/README.txt
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/__init__.py
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/components.py
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/directive.py
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/directive.txt
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/interfaces.py
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/meta.py
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/meta.zcml
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/__init__.py
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/contentprovider.py
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/ftesting.zcml
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/index.pt
A grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/test_all.py
U grok/branches/darrylcousins-branch/mars.template/src/mars/template/meta.py
U grok/branches/darrylcousins-branch/mars.view/src/mars/view/README.txt
U grok/branches/darrylcousins-branch/mars.view/src/mars/view/components.py
U grok/branches/darrylcousins-branch/mars.view/src/mars/view/meta.py
U grok/branches/darrylcousins-branch/mars.view/src/mars/view/tests/layout.py
-=-
Modified: grok/branches/darrylcousins-branch/buildout.cfg
===================================================================
--- grok/branches/darrylcousins-branch/buildout.cfg 2007-07-05 01:18:50 UTC (rev 77442)
+++ grok/branches/darrylcousins-branch/buildout.cfg 2007-07-05 06:29:07 UTC (rev 77443)
@@ -1,5 +1,5 @@
[buildout]
-develop = . mars.layer mars.template mars.macro mars.view
+develop = . mars.layer mars.template mars.macro mars.view mars.contentprovider
parts = app data instance test
find-links = http://download.zope.org/distribution/
@@ -14,6 +14,7 @@
mars.template
mars.macro
mars.view
+ mars.contentprovider
recipe = zc.zope3recipes:app
site.zcml = <include package="zope.security" file="meta.zcml" />
<include package="zope.i18n" file="meta.zcml" />
@@ -93,5 +94,6 @@
mars.template
mars.macro
mars.view
+ mars.contentprovider
defaults = ['--tests-pattern', '^f?tests$', '-v']
Added: grok/branches/darrylcousins-branch/mars.contentprovider/setup.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/setup.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/setup.py 2007-07-05 06:29:07 UTC (rev 77443)
@@ -0,0 +1,33 @@
+import os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+ return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+setup(
+ name='mars.contentprovider',
+ version='0.1',
+ author='Darryl Cousins',
+ author_email='darryl.cousins at tfws.org.nz',
+ url='http://www.tfws.org.nz/martian',
+ description="""\
+Martian is a library that allows the embedding of configuration
+information in Python code. Martian can then grok the system and
+do the appropriate configuration registrations.
+
+This package uses martian to define contentproviders""",
+ long_description=(
+ read('src/mars/contentprovider/README.txt')
+ ),
+ packages=find_packages('src'),
+ package_dir = {'': 'src'},
+ include_package_data = True,
+ zip_safe=False,
+ license='ZPL',
+ install_requires=['setuptools',
+ 'martian',
+ 'zope.contentprovider',
+ ],
+)
+
+
Property changes on: grok/branches/darrylcousins-branch/mars.contentprovider/setup.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/__init__.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/__init__.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/__init__.py 2007-07-05 06:29:07 UTC (rev 77443)
@@ -0,0 +1,7 @@
+try:
+ # Declare this a namespace package if pkg_resources is available.
+ import pkg_resources
+ pkg_resources.declare_namespace('mars')
+except ImportError:
+ pass
+
Property changes on: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/README.txt
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/README.txt (rev 0)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/README.txt 2007-07-05 06:29:07 UTC (rev 77443)
@@ -0,0 +1,28 @@
+====================
+Mars ContentProvider
+====================
+
+Martian is a library that allows the embedding of configuration
+information in Python code. Martian can then grok the system and
+do the appropriate configuration registrations.
+
+This package uses martian to configure contentproviders.
+
+Example Code
+------------
+
+::
+
+ Code
+
+Directives
+----------
+
+Please see ``directive.txt``.
+
+Tests
+-----
+
+See test directory.
+
+
Property changes on: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/README.txt
___________________________________________________________________
Name: svn:keywords
+ Date Author
Added: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/__init__.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/__init__.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/__init__.py 2007-07-05 06:29:07 UTC (rev 77443)
@@ -0,0 +1,2 @@
+from components import ContentProvider
+
Property changes on: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/components.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/components.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/components.py 2007-07-05 06:29:07 UTC (rev 77443)
@@ -0,0 +1,8 @@
+from mars.view.components import TemplateViewBase
+
+class ContentProvider(TemplateViewBase):
+
+ def __init__(self, context, request, view):
+ self.__parent__ = self.view = view
+ self.context = context
+ self.request = request
Property changes on: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/components.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/directive.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/directive.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/directive.py 2007-07-05 06:29:07 UTC (rev 77443)
@@ -0,0 +1 @@
+#
Property changes on: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/directive.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/directive.txt
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/directive.txt (rev 0)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/directive.txt 2007-07-05 06:29:07 UTC (rev 77443)
@@ -0,0 +1,31 @@
+========================
+Mars Template Directives
+========================
+
+The mars.layer directive may be used
+-----------------------------------------
+
+* mars.layer.layer(class_or_interface):
+ The layer for which the template should be available.
+ Default: zope.publisher.browser.interfaces.IDefaultBrowserLayer
+
+Relevant grok directives
+------------------------
+
+* grok.name(name):
+ Name of the view, available in url as object/@@viewname.
+ Default: factory.__name__.lower()
+
+* grok.context(class_or_interface):
+ The view for which the template should be available. Usually should be
+ defined.
+ Default: module context
+
+* grok.template(name):
+ If defined the template will be looked up as a `named adapter`. Should only be
+ defined if a template has been registered as a named adapter.
+ Default: ''
+
+* grok.provides(class_or_interface):
+ Interface the class is looked up as, probably wouldn't be used.
+ Default: zope.interface.Interface
Property changes on: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/directive.txt
___________________________________________________________________
Name: svn:keywords
+ Date Author
Added: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/interfaces.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/interfaces.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/interfaces.py 2007-07-05 06:29:07 UTC (rev 77443)
@@ -0,0 +1,4 @@
+import zope.interface
+
+class IMarsContentProviderDirectives(zope.interface.Interface):
+ pass
Property changes on: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/interfaces.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/meta.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/meta.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/meta.py 2007-07-05 06:29:07 UTC (rev 77443)
@@ -0,0 +1,20 @@
+import zope.component
+from zope.publisher.interfaces.browser import IBrowserView
+from zope.contentprovider.interfaces import IContentProvider
+
+import mars.contentprovider
+from mars.view.meta import ViewGrokkerBase
+
+class ContentProviderGrokker(ViewGrokkerBase):
+ component_class = mars.contentprovider.ContentProvider
+ provides = IContentProvider
+
+ def register(self, factory, module_info):
+
+# print '\nname:', self.view_name,'context:', self.view_context,'factory:', factory,\
+# 'layer:', self.view_layer, 'provides', self.provides, '\n'
+ zope.component.provideAdapter(factory,
+ adapts=(self.view_context, self.view_layer, IBrowserView),
+ provides=self.provides,
+ name=self.view_name)
+
Property changes on: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/meta.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/meta.zcml
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/meta.zcml (rev 0)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/meta.zcml 2007-07-05 06:29:07 UTC (rev 77443)
@@ -0,0 +1,2 @@
+<grok package=".meta" xmlns="http://namespaces.zope.org/grok" />
+
Added: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/__init__.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/__init__.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/__init__.py 2007-07-05 06:29:07 UTC (rev 77443)
@@ -0,0 +1 @@
+#
Property changes on: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/contentprovider.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/contentprovider.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/contentprovider.py 2007-07-05 06:29:07 UTC (rev 77443)
@@ -0,0 +1,48 @@
+"""
+ >>> import grok
+ >>> grok.grok('mars.contentprovider.tests.contentprovider')
+ >>> from mars.contentprovider.tests.contentprovider import Mammoth
+ >>> getRootFolder()["mammoth"] = Mammoth()
+
+ >>> from zope.testbrowser.testing import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+ >>> skinURL = 'http://localhost/++skin++myskin'
+ >>> browser.open(skinURL + '/mammoth/@@index')
+ >>> print browser.contents
+ <div>
+ I am Manfred the Mammoth
+ </div>
+
+"""
+
+import grok
+import mars.view
+import mars.layer
+import mars.template
+import mars.contentprovider
+
+class Mammoth(grok.Model):
+ title = u'Manfred'
+
+class IMySkinLayer(mars.layer.IMinimalLayer):
+ pass
+
+# layer used for all registrations in this module
+mars.layer.layer(IMySkinLayer)
+
+class MySkin(mars.layer.Skin):
+ pass
+
+class Index(mars.view.LayoutView):
+ pass
+
+class IndexLayout(mars.template.LayoutFactory):
+ grok.template('index.pt')
+ grok.context(Index)
+
+class Title(mars.contentprovider.ContentProvider):
+
+ def render(self):
+ return self.context.title
+
Property changes on: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/contentprovider.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/ftesting.zcml
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/ftesting.zcml (rev 0)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/ftesting.zcml 2007-07-05 06:29:07 UTC (rev 77443)
@@ -0,0 +1,20 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:meta="http://namespaces.zope.org/meta"
+ xmlns:browser="http://namespaces.zope.org/browser"
+ i18n_domain="zope"
+ package="mars.template.tests">
+
+ <include package="grok" file="meta.zcml" />
+ <include package="mars.template" file="meta.zcml" />
+ <include package="mars.layer" file="meta.zcml" />
+ <include package="mars.view" file="meta.zcml" />
+ <include package="mars.contentprovider" file="meta.zcml" />
+
+ <include package="z3c.layer.minimal.tests" file="ftesting.zcml" />
+
+ <include package="grok" />
+ <include package="zope.contentprovider" />
+
+</configure>
+
+
Added: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/index.pt
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/index.pt (rev 0)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/index.pt 2007-07-05 06:29:07 UTC (rev 77443)
@@ -0,0 +1,3 @@
+<div>
+I am <tal:block tal:content="structure provider:title" /> the Mammoth
+</div>
Added: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/test_all.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/test_all.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/test_all.py 2007-07-05 06:29:07 UTC (rev 77443)
@@ -0,0 +1,22 @@
+import unittest
+from pkg_resources import resource_listdir
+
+from grok.ftests.test_grok_functional import FunctionalDocTestSuite
+
+from zope.app.testing import functional
+functional.defineLayer('TestLayer', 'ftesting.zcml')
+
+def test_suite():
+ suite = unittest.TestSuite()
+ dottedname = 'mars.contentprovider.tests.%s'
+ for name in ['contentprovider']:
+ test = FunctionalDocTestSuite(dottedname % name)
+ test.layer = TestLayer
+ suite.addTest(test)
+
+ return suite
+
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
+
Property changes on: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/test_all.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: grok/branches/darrylcousins-branch/mars.template/src/mars/template/meta.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.template/src/mars/template/meta.py 2007-07-05 01:18:50 UTC (rev 77442)
+++ grok/branches/darrylcousins-branch/mars.template/src/mars/template/meta.py 2007-07-05 06:29:07 UTC (rev 77443)
@@ -21,6 +21,7 @@
# TODO raise errors if anything missing?
class TemplateFactoryGrokkerBase(martian.ClassGrokker):
component_class = None
+ provides = None
def grok(self, name, factory, context, module_info, templates):
view_context = util.determine_class_context(factory, context)
@@ -63,16 +64,10 @@
class TemplateFactoryGrokker(TemplateFactoryGrokkerBase):
component_class = mars.template.TemplateFactory
+ provides = IPageTemplate
- @property
- def provides(self):
- return IPageTemplate
-
class LayoutFactoryGrokker(TemplateFactoryGrokkerBase):
component_class = mars.template.LayoutFactory
+ provides = ILayoutTemplate
- @property
- def provides(self):
- return ILayoutTemplate
-
Modified: grok/branches/darrylcousins-branch/mars.view/src/mars/view/README.txt
===================================================================
--- grok/branches/darrylcousins-branch/mars.view/src/mars/view/README.txt 2007-07-05 01:18:50 UTC (rev 77442)
+++ grok/branches/darrylcousins-branch/mars.view/src/mars/view/README.txt 2007-07-05 06:29:07 UTC (rev 77443)
@@ -24,10 +24,38 @@
Example Code
------------
-::
+The following registers a view for Context named view. It has a
+`render` method that renders the template defined by ViewTemplate::
- Code
+ class Context(grok.Model):
+ pass
+ class View(mars.view.TemplateView):
+ pass
+
+ class ViewTemplate(mars.template.TemplateFactory):
+ grok.template('templates/template.pt')
+ grok.context(View)
+
+The following snippet registers a view for Context named view. It has a
+`__call__` method that renders the template defined by ViewLayout in addition to a
+`render` method that renders the template defined by ViewTemplate::
+
+ class Context(grok.Model):
+ pass
+
+ class View(mars.view.LayoutView):
+ pass
+
+ class ViewLayout(mars.template.LayoutFactory):
+ grok.template('templates/template.pt')
+ grok.context(View)
+
+ class ViewSnippet(mars.template.TemplateFactory):
+ grok.template('templates/snippet.pt')
+ grok.context(View)
+
+
Directives
----------
Modified: grok/branches/darrylcousins-branch/mars.view/src/mars/view/components.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.view/src/mars/view/components.py 2007-07-05 01:18:50 UTC (rev 77442)
+++ grok/branches/darrylcousins-branch/mars.view/src/mars/view/components.py 2007-07-05 06:29:07 UTC (rev 77443)
@@ -11,6 +11,9 @@
from grok.interfaces import IGrokView
class ViewBase(object):
+ """Maybe this could be in the grok.components module?
+
+ All of this is directly copied from grok.View"""
template_name = u''
@@ -71,7 +74,7 @@
# give nice error message if template is None
return self.template.macros[key]
-class TemplateViewBase(BrowserPage, ViewBase):
+class TemplateViewBase(ViewBase):
"""Mixin to reuse render method"""
template = None
_template_name = u'' # will be set if grok.template defined
@@ -89,24 +92,18 @@
return template(self)
return template(self)
-class TemplateView(TemplateViewBase):
- """This differs from the above in that instead of expecting a template
- or render method, the template will be looked up.
- No call method is provided.
- """
+class TemplateView(TemplateViewBase, BrowserPage):
+
def __init__(self, context, request):
super(TemplateView, self).__init__(context, request)
-class LayoutView(TemplateViewBase):
- """This differs from the above in that instead of expecting a template
- or render method, a layout template will be looked up in the call method
- """
+
+class LayoutView(TemplateViewBase, BrowserPage):
layout = None
_layout_name = u'' # will be set if mars.view.layout defined
_layout_interface = ILayoutTemplate
-
def __init__(self, context, request):
super(LayoutView, self).__init__(context, request)
Modified: grok/branches/darrylcousins-branch/mars.view/src/mars/view/meta.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.view/src/mars/view/meta.py 2007-07-05 01:18:50 UTC (rev 77442)
+++ grok/branches/darrylcousins-branch/mars.view/src/mars/view/meta.py 2007-07-05 06:29:07 UTC (rev 77443)
@@ -20,7 +20,7 @@
view_name = ''
layer_name = ''
view_context = None
- provider = zope.interface.Interface
+ provides = zope.interface.Interface
def grok(self, name, factory, context, module_info, templates):
self.view_context = util.determine_class_context(factory, context)
@@ -44,7 +44,7 @@
# don't know if this would ever need to be set
self.provides = util.class_annotation(factory, 'grok.provides',
- self.provider)
+ self.provides)
#print '\nname:', self.view_name,'context:', self.view_context,'factory:', factory,\
# 'layer:', self.view_layer, '\n'
self.register(factory, module_info)
Modified: grok/branches/darrylcousins-branch/mars.view/src/mars/view/tests/layout.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.view/src/mars/view/tests/layout.py 2007-07-05 01:18:50 UTC (rev 77442)
+++ grok/branches/darrylcousins-branch/mars.view/src/mars/view/tests/layout.py 2007-07-05 06:29:07 UTC (rev 77443)
@@ -2,8 +2,8 @@
Testing the LayoutView, which unlike grok.View will look up a layout.
>>> import grok
+ >>> grok.grok('mars.view.tests.layout')
>>> from mars.view.tests.layout import Mammoth
- >>> grok.grok('mars.view.tests.layout')
>>> getRootFolder()["manfred"] = Mammoth()
>>> from zope.testbrowser.testing import Browser
More information about the Checkins
mailing list