[Checkins] SVN: five.grok/trunk/ Merge static and formlib forms branch with the trunk.
Sylvain Viollon
sylvain at infrae.com
Thu Sep 25 08:30:10 EDT 2008
Log message for revision 91474:
Merge static and formlib forms branch with the trunk.
Changed:
U five.grok/trunk/buildout.cfg
U five.grok/trunk/docs/HISTORY.txt
D five.grok/trunk/setup.cfg
U five.grok/trunk/setup.py
D five.grok/trunk/src/five/grok/HISTORY.txt
U five.grok/trunk/src/five/grok/__init__.py
U five.grok/trunk/src/five/grok/components.py
A five.grok/trunk/src/five/grok/ftests/form/
U five.grok/trunk/src/five/grok/ftests/test_grok_functional.py
A five.grok/trunk/src/five/grok/ftests/view/namespace.py
A five.grok/trunk/src/five/grok/ftests/view/resource.py
A five.grok/trunk/src/five/grok/ftests/view/static/
U five.grok/trunk/src/five/grok/meta.py
U five.grok/trunk/src/five/grok/meta.zcml
U five.grok/trunk/src/five/grok/testing.py
A five.grok/trunk/src/five/grok/tests/all/statichaspy/
A five.grok/trunk/src/five/grok/tests/all/staticispackage/
A five.grok/trunk/src/five/grok/tests/resource.py
U five.grok/trunk/src/five/grok/tests/test_all.py
-=-
Modified: five.grok/trunk/buildout.cfg
===================================================================
--- five.grok/trunk/buildout.cfg 2008-09-25 12:22:51 UTC (rev 91473)
+++ five.grok/trunk/buildout.cfg 2008-09-25 12:30:10 UTC (rev 91474)
@@ -24,7 +24,6 @@
verbose-security = on
eggs =
zope.component>=3.4,<3.5dev
- grokcore.view
five.grok
zcml = five.grok:meta.zcml
five.grok
Modified: five.grok/trunk/docs/HISTORY.txt
===================================================================
--- five.grok/trunk/docs/HISTORY.txt 2008-09-25 12:22:51 UTC (rev 91473)
+++ five.grok/trunk/docs/HISTORY.txt 2008-09-25 12:30:10 UTC (rev 91474)
@@ -5,19 +5,25 @@
five.grok - 0.1 Unreleased
+ - Added support for formlib forms with grokcore.formlib.
+ [thefunny42]
+
+ - Added support for static resource directory.
+ [thefunny42]
+
- Added support for inline templates and made Zope 2 template semantics
the default when doing 'from five import grok' and using
grok.PageTemplate.
[optilude]
- Added override to make templates use Five's ViewPageTemplateFile instead
- of the one from zope.app.pagetemplate
+ of the one from zope.app.pagetemplate.
[optilude]
- - Added tests for grok.subscriber directive
+ - Added tests for grok.subscriber directive.
[kamon]
- Initial release (tests for adapters and utilities, initial support for
- views)
+ views).
[regebro, gotcha]
Deleted: five.grok/trunk/setup.cfg
===================================================================
--- five.grok/trunk/setup.cfg 2008-09-25 12:22:51 UTC (rev 91473)
+++ five.grok/trunk/setup.cfg 2008-09-25 12:30:10 UTC (rev 91474)
@@ -1,3 +0,0 @@
-[egg_info]
-tag_build = dev
-tag_svn_revision = true
Modified: five.grok/trunk/setup.py
===================================================================
--- five.grok/trunk/setup.py 2008-09-25 12:22:51 UTC (rev 91473)
+++ five.grok/trunk/setup.py 2008-09-25 12:30:10 UTC (rev 91474)
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import os
-version = '0.1'
+version = '1.0dev'
setup(name='five.grok',
version=version,
@@ -29,7 +29,9 @@
install_requires=[
'setuptools',
'martian',
- 'grokcore.view',
+ 'grokcore.security',
+ 'grokcore.view >= 1.1',
+ 'grokcore.formlib',
],
entry_points="""
""",
Deleted: five.grok/trunk/src/five/grok/HISTORY.txt
===================================================================
--- five.grok/trunk/src/five/grok/HISTORY.txt 2008-09-25 12:22:51 UTC (rev 91473)
+++ five.grok/trunk/src/five/grok/HISTORY.txt 2008-09-25 12:30:10 UTC (rev 91474)
@@ -1,8 +0,0 @@
-0.1
----
-
- Features added:
-
- - Switched to refactored martian/grokcore.component directives
- - syntax Inital version
-
\ No newline at end of file
Modified: five.grok/trunk/src/five/grok/__init__.py
===================================================================
--- five.grok/trunk/src/five/grok/__init__.py 2008-09-25 12:22:51 UTC (rev 91473)
+++ five.grok/trunk/src/five/grok/__init__.py 2008-09-25 12:30:10 UTC (rev 91474)
@@ -1,8 +1,10 @@
from grokcore.component import *
from grokcore.security import *
from grokcore.view import *
+from grokcore.formlib import *
-from five.grok.components import View, Model
+from five.grok.components import View, Model, Form, AddForm, EditForm, DisplayForm
# Override the one from grokcore.view so that we get Zope 2 semantics
-from five.grok.components import ZopeTwoPageTemplate as PageTemplate
\ No newline at end of file
+from five.grok.components import ZopeTwoPageTemplate as PageTemplate
+
Modified: five.grok/trunk/src/five/grok/components.py
===================================================================
--- five.grok/trunk/src/five/grok/components.py 2008-09-25 12:22:51 UTC (rev 91473)
+++ five.grok/trunk/src/five/grok/components.py 2008-09-25 12:30:10 UTC (rev 91474)
@@ -1,33 +1,50 @@
-from zope import interface
+import martian
+
from zope.annotation.interfaces import IAttributeAnnotatable
+from zope.app.pagetemplate.viewpagetemplatefile import ViewMapper
+from zope import interface, component
+from grokcore.component.interfaces import IContext
+from grokcore.formlib.components import GrokForm as BaseGrokForm
+from grokcore.formlib.components import default_display_template, default_form_template
+from grokcore.view.components import PageTemplate
import grokcore.view
-from grokcore.view.components import PageTemplate
-from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
+from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile \
+ as BaseViewPageTemplateFile
+from Products.Five.browser.pagetemplatefile import getEngine
+from Products.Five.browser import resource
+from Products.Five.formlib import formbase
+from Products.PageTemplates.Expressions import SecureModuleImporter
+from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
+from OFS.SimpleItem import SimpleItem
+import Acquisition
-from grokcore.component.interfaces import IContext
-import Acquisition
-from OFS.SimpleItem import SimpleItem
-
class Model(SimpleItem):
# XXX Inheritance order is important here. If we reverse this,
# then containers can't be models anymore because no unambigous MRO
# can be established.
interface.implements(IAttributeAnnotatable, IContext)
+
class View(grokcore.view.View, Acquisition.Explicit):
- pass
+ def __init__(self, *args):
+ super(View, self).__init__(*args)
+ if not (self.static is None):
+ # static should be wrapper correctly with acquisition,
+ # otherwise you will not be able to compute URL for
+ # resources.
+ self.static = self.static.__of__(self)
+
+ # We let getPhysicalPath to be acquired. This make static URL's
+ # work, and prevent us to inherit from Acquisition.Implicit
+ getPhysicalPath = Acquisition.Acquired
+
+
# TODO: This should probably move to Products.Five.browser
-from Acquisition import aq_inner
-from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
-from Products.PageTemplates.Expressions import SecureModuleImporter
-from Products.Five.browser.pagetemplatefile import getEngine
-from zope.app.pagetemplate.viewpagetemplatefile import ViewMapper
-
class ViewAwareZopePageTemplate(ZopePageTemplate):
def pt_getEngine(self):
@@ -43,7 +60,7 @@
root = None
view = self._getContext()
- here = aq_inner(self.context)
+ here = Acquisition.aq_inner(self.context)
request = getattr(root, 'REQUEST', None)
c = {'template': self,
@@ -60,9 +77,21 @@
c['view'] = view
c['views'] = ViewMapper(here, request)
+ if hasattr(self, 'pt_grokContext'):
+ c.update(self.pt_grokContext)
+
return c
+class ViewPageTemplateFile(BaseViewPageTemplateFile):
+
+ def pt_getContext(self):
+ c = super(ViewPageTemplateFile, self).pt_getContext()
+ if hasattr(self, 'pt_grokContext'):
+ c.update(self.pt_grokContext)
+
+ return c
+
class ZopeTwoPageTemplate(PageTemplate):
def setFromString(self, string):
@@ -74,5 +103,67 @@
def render(self, view):
namespace = self.getNamespace(view)
template = self._template.__of__(view)
- namespace.update(template.pt_getContext())
- return template(namespace)
+ template.pt_grokContext = namespace
+ return template()
+
+
+class DirectoryResource(resource.DirectoryResource):
+ # We subclass this, because we want to override the default factories for
+ # the resources so that .pt and .html do not get created as page
+ # templates
+
+ resource_factories = {}
+ for type, factory in (resource.DirectoryResource.resource_factories.items()):
+ if factory is resource.PageTemplateResourceFactory:
+ continue
+ resource_factories[type] = factory
+
+
+class DirectoryResourceFactory(resource.DirectoryResourceFactory):
+ # __name__ is needed if you want to get url's of resources
+
+ def __init__(self, name, path):
+ self.__name = name
+ self.__rsrc = self.factory(path, name)
+
+ def __call__(self, request):
+ resource = DirectoryResource(self.__rsrc, request)
+ resource.__name__ = self.__name # We need to add name
+ return resource
+
+# forms from formlib
+
+class GrokForm(BaseGrokForm):
+
+ def __init__(self, *args):
+ super(GrokForm, self).__init__(*args)
+ self.__name__ = self.__view_name__
+ # super seems not to work correctly since this is needed again.
+ self.static = component.queryAdapter(
+ self.request, interface.Interface,
+ name = self.module_info.package_dotted_name)
+ if not (self.static is None):
+ self.static = self.static.__of__(self)
+
+
+class Form(GrokForm, formbase.PageForm, View):
+
+ martian.baseclass()
+ template = default_form_template
+
+class AddForm(GrokForm, formbase.AddForm, View):
+
+ martian.baseclass()
+ template = default_form_template
+
+
+class EditForm(GrokForm, formbase.EditForm, View):
+
+ martian.baseclass()
+ template = default_form_template
+
+
+class DisplayForm(GrokForm, formbase.DisplayForm, View):
+
+ martian.baseclass()
+ template = default_display_template
Copied: five.grok/trunk/src/five/grok/ftests/form (from rev 91473, five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/form)
Modified: five.grok/trunk/src/five/grok/ftests/test_grok_functional.py
===================================================================
--- five.grok/trunk/src/five/grok/ftests/test_grok_functional.py 2008-09-25 12:22:51 UTC (rev 91473)
+++ five.grok/trunk/src/five/grok/ftests/test_grok_functional.py 2008-09-25 12:30:10 UTC (rev 91474)
@@ -58,7 +58,7 @@
def test_suite():
suite = unittest.TestSuite()
- for name in ['view']:
+ for name in ['view', 'form']:
suite.addTest(suiteFromPackage(name))
return suite
Copied: five.grok/trunk/src/five/grok/ftests/view/namespace.py (from rev 91473, five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/view/namespace.py)
===================================================================
--- five.grok/trunk/src/five/grok/ftests/view/namespace.py (rev 0)
+++ five.grok/trunk/src/five/grok/ftests/view/namespace.py 2008-09-25 12:30:10 UTC (rev 91474)
@@ -0,0 +1,36 @@
+"""
+ >>> from five.grok.ftests.view.namespace import *
+ >>> id = getRootFolder()._setObject("manfred", Mammoth(id='manfred'))
+
+ >>> from Products.Five.testbrowser import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+ >>> browser.open("http://localhost/manfred")
+ >>> print browser.contents
+ <html>
+ <body>
+ <h1>Hello I am manfred!</h1>
+ </body>
+ </html>
+
+"""
+from five import grok
+
+class Mammoth(grok.Model):
+
+ def __init__(self, id):
+ super(Mammoth, self).__init__(id)
+ self.id = id
+
+class Index(grok.View):
+
+ def namespace(self):
+ return {'name': self.context.id}
+
+index = grok.PageTemplate("""\
+<html>
+<body>
+<h1>Hello I am <tal:name tal:replace="name" />!</h1>
+</body>
+</html>
+""")
Copied: five.grok/trunk/src/five/grok/ftests/view/resource.py (from rev 91473, five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/view/resource.py)
===================================================================
--- five.grok/trunk/src/five/grok/ftests/view/resource.py (rev 0)
+++ five.grok/trunk/src/five/grok/ftests/view/resource.py 2008-09-25 12:30:10 UTC (rev 91474)
@@ -0,0 +1,62 @@
+"""
+ >>> from five.grok.ftests.view.resource import *
+
+ >>> from Products.Five.testbrowser import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+
+ We can access to our CSS file:
+
+ >>> browser.open("http://localhost/++resource++five.grok.ftests.view/style.css")
+ >>> print browser.contents
+ body {
+ color: green;
+ }
+ >>> print browser.headers['content-type']
+ text/css; charset=iso-8859-15
+
+ And the template file:
+
+ >>> browser.open("http://localhost/++resource++five.grok.ftests.view/template.pt")
+ >>> print browser.contents
+ <tal:test>This template should be considered as a file.</tal:test>
+ >>> print browser.headers['content-type']
+ text/html; charset=iso-8859-15
+
+ Set a content, and ask the view on it. In a view, you should be able
+ to get the resource URL:
+
+ >>> id = getRootFolder()._setObject("manfred", Mammoth(id='manfred'))
+ >>> browser.open("http://localhost/manfred")
+ >>> print browser.contents
+ <html>
+ <body>
+ <h1>Hello I a mammoth!</h1>
+ <a href="http://localhost/manfred/++resource++five.grok.ftests.view/style.css">A link to some style for life!</a>
+ </body>
+ </html>
+
+
+"""
+from five import grok
+
+class Mammoth(grok.Model):
+
+ def __init__(self, id):
+ super(Mammoth, self).__init__(id)
+ self.id = id # XXX: if you don't have an id, the
+ # link will be bad. Maybe this should
+ # happens by default.
+
+class Index(grok.View):
+ pass
+
+index = grok.PageTemplate("""\
+<html>
+<body>
+<h1>Hello I a mammoth!</h1>
+<a href="#"
+ tal:attributes="href view/static/style.css">A link to some style for life!</a>
+</body>
+</html>
+""")
Copied: five.grok/trunk/src/five/grok/ftests/view/static (from rev 91473, five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/view/static)
Modified: five.grok/trunk/src/five/grok/meta.py
===================================================================
--- five.grok/trunk/src/five/grok/meta.py 2008-09-25 12:22:51 UTC (rev 91473)
+++ five.grok/trunk/src/five/grok/meta.py 2008-09-25 12:30:10 UTC (rev 91474)
@@ -1,3 +1,4 @@
+
import martian
import five.grok
import grokcore.security
@@ -2,5 +3,11 @@
+from zope import interface, component
+from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+from five.grok import components
+from martian.error import GrokError
+
from Products.Five.security import protectClass
from Globals import InitializeClass as initializeClass
+import os.path
@@ -28,3 +35,40 @@
)
return True
+
+class StaticResourcesGrokker(martian.GlobalGrokker):
+
+ def grok(self, name, module, module_info, config, **kw):
+ # we're only interested in static resources if this module
+ # happens to be a package
+ if not module_info.isPackage():
+ return False
+
+ resource_path = module_info.getResourcePath('static')
+ if os.path.isdir(resource_path):
+ static_module = module_info.getSubModuleInfo('static')
+ if static_module is not None:
+ if static_module.isPackage():
+ raise GrokError(
+ "The 'static' resource directory must not "
+ "be a python package.",
+ module_info.getModule())
+ else:
+ raise GrokError(
+ "A package can not contain both a 'static' "
+ "resource directory and a module named "
+ "'static.py'", module_info.getModule())
+
+ # FIXME: This is public, we need to set security on resources ?
+ name = module_info.dotted_name
+ resource_factory = components.DirectoryResourceFactory(
+ name, resource_path)
+ adapts = (IDefaultBrowserLayer,)
+ provides = interface.Interface
+
+ config.action(
+ discriminator=('adapter', adapts, provides, name),
+ callable=component.provideAdapter,
+ args=(resource_factory, adapts, provides, name),
+ )
+ return True
Modified: five.grok/trunk/src/five/grok/meta.zcml
===================================================================
--- five.grok/trunk/src/five/grok/meta.zcml 2008-09-25 12:22:51 UTC (rev 91473)
+++ five.grok/trunk/src/five/grok/meta.zcml 2008-09-25 12:30:10 UTC (rev 91474)
@@ -5,7 +5,14 @@
<include package="grokcore.component" file="meta.zcml" />
<include package="grokcore.security" file="meta.zcml" />
- <include package="grokcore.view" file="meta.zcml" />
+
+ <!-- Load minimal support of grokcore.view, views + templates -->
+ <include package="grokcore.view" file="meta-minimal.zcml" />
+ <include package="grokcore.formlib" file="meta.zcml" />
+
+ <!-- Include skin support as well -->
+ <grok:grok package="grokcore.view.meta.skin" />
+
<grok:grok package=".meta" />
</configure>
Modified: five.grok/trunk/src/five/grok/testing.py
===================================================================
--- five.grok/trunk/src/five/grok/testing.py 2008-09-25 12:22:51 UTC (rev 91473)
+++ five.grok/trunk/src/five/grok/testing.py 2008-09-25 12:30:10 UTC (rev 91474)
@@ -22,7 +22,9 @@
def grok(module_name):
config = ConfigurationMachine()
zcml.do_grok('grokcore.component.meta', config)
- zcml.do_grok('grokcore.view.meta', config)
+ zcml.do_grok('grokcore.view.meta.views', config)
+ zcml.do_grok('grokcore.view.meta.templates', config)
+ zcml.do_grok('grokcore.view.meta.skin', config)
# Use the Five override for the page template factory
# zcml.do_grok('grokcore.view.templatereg', config)
zcml.do_grok('five.grok.templatereg', config)
Copied: five.grok/trunk/src/five/grok/tests/all/statichaspy (from rev 91473, five.grok/branches/sylvain-static-and-forms/src/five/grok/tests/all/statichaspy)
Copied: five.grok/trunk/src/five/grok/tests/all/staticispackage (from rev 91473, five.grok/branches/sylvain-static-and-forms/src/five/grok/tests/all/staticispackage)
Copied: five.grok/trunk/src/five/grok/tests/resource.py (from rev 91473, five.grok/branches/sylvain-static-and-forms/src/five/grok/tests/resource.py)
===================================================================
--- five.grok/trunk/src/five/grok/tests/resource.py (rev 0)
+++ five.grok/trunk/src/five/grok/tests/resource.py 2008-09-25 12:30:10 UTC (rev 91474)
@@ -0,0 +1,18 @@
+"""
+It is an error for the 'static' directory to be a python package:
+
+ >>> grok.testing.grok('five.grok.tests.all.staticispackage')
+ Traceback (most recent call last):
+ ...
+ GrokError: The 'static' resource directory must not be a python package.
+
+When a package contains a 'static' resource directory, it must not also contain
+a module called 'static.py':
+
+ >>> grok.testing.grok('five.grok.tests.all.statichaspy')
+ Traceback (most recent call last):
+ ...
+ GrokError: A package can not contain both a 'static' resource directory and a module named 'static.py'
+"""
+
+from five import grok
Modified: five.grok/trunk/src/five/grok/tests/test_all.py
===================================================================
--- five.grok/trunk/src/five/grok/tests/test_all.py 2008-09-25 12:22:51 UTC (rev 91473)
+++ five.grok/trunk/src/five/grok/tests/test_all.py 2008-09-25 12:30:10 UTC (rev 91474)
@@ -98,6 +98,9 @@
module='five.grok.tests.subscribers',
setUp=setUp, tearDown=testing.tearDown),
+ doctestunit.DocTestSuite(
+ module='five.grok.tests.resource',
+ setUp=setUp, tearDown=testing.tearDown),
])
More information about the Checkins
mailing list