[Checkins] SVN: five.grok/branches/sylvain-static-and-forms/src/five/grok/ - Reorganize import in components.py
Sylvain Viollon
sylvain at infrae.com
Sat Aug 23 19:11:32 EDT 2008
Log message for revision 90164:
- Reorganize import in components.py
- Add test for forms,
- Add missing magic for forms support.
Changed:
U five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py
A five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/form/
A five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/form/__init__.py
A five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/form/form.py
U five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/test_grok_functional.py
-=-
Modified: five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py
===================================================================
--- five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py 2008-08-23 22:36:23 UTC (rev 90163)
+++ five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py 2008-08-23 23:11:31 UTC (rev 90164)
@@ -1,33 +1,38 @@
-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 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
+
# 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 +48,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,
@@ -77,10 +82,7 @@
namespace.update(template.pt_getContext())
return template(namespace)
-# resource
-from Products.Five.browser import resource
-
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
@@ -107,26 +109,35 @@
# forms from formlib
-from grokcore.formlib.components import GrokForm
-from Products.Five.formlib import formbase
+class GrokForm(BaseGrokForm):
-import martian
+ def __init__(self, *args):
+ super(GrokForm, self).__init__(*args)
+ self.__name__ = self.__view_name__
+ # super should not work correctly since this is needed again.
+ self.static = component.queryAdapter(
+ self.request, interface.Interface,
+ name = self.module_info.package_dotted_name)
+
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
Added: five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/form/__init__.py
===================================================================
Added: five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/form/form.py
===================================================================
--- five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/form/form.py (rev 0)
+++ five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/form/form.py 2008-08-23 23:11:31 UTC (rev 90164)
@@ -0,0 +1,63 @@
+"""
+ >>> from five.grok.ftests.form.form import *
+ >>> id = getRootFolder()._setObject("manfred", Mammoth(id='manfred'))
+
+ >>> from Products.Five.testbrowser import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+
+ We can test the display form as default view:
+
+ >>> browser.open("http://localhost/manfred")
+ >>> print browser.contents
+ <html>...
+ ... Name ...
+ ... Age ...
+ </html>
+
+ But we have an edition form:
+
+ >>> browser.open("http://localhost/manfred/edit")
+ >>> browser.getControl('Name').value = 'Arthur'
+ >>> browser.getControl('Age').value = '325'
+ >>> browser.getControl('Apply').click()
+ >>> 'Updated' in browser.contents
+ True
+
+ And if we look back to the display form, we will see new values:
+
+ >>> browser.open("http://localhost/manfred")
+ >>> print browser.contents
+ <html>...
+ ... Name ...
+ ... Arthur ...
+ ... Age ...
+ ... 325 ...
+ </html>
+
+"""
+
+from five import grok
+from zope import interface, schema
+from zope.schema.fieldproperty import FieldProperty
+
+class IMammoth(interface.Interface):
+
+ name = schema.TextLine(title=u"Name")
+ age = schema.Int(title=u"Age")
+
+class Mammoth(grok.Model):
+
+ grok.implements(IMammoth)
+
+ name = FieldProperty(IMammoth['name'])
+ age = FieldProperty(IMammoth['age'])
+
+class Edit(grok.EditForm):
+
+ grok.context(IMammoth)
+
+class Index(grok.DisplayForm):
+
+ grok.context(IMammoth)
+
Modified: five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/test_grok_functional.py
===================================================================
--- five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/test_grok_functional.py 2008-08-23 22:36:23 UTC (rev 90163)
+++ five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/test_grok_functional.py 2008-08-23 23:11:31 UTC (rev 90164)
@@ -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
More information about the Checkins
mailing list