[Checkins] SVN: grok/branches/sylvain-grokcore-formlib/src/grok/ - Remove test which are already included in grokcore.formlib,
Sylvain Viollon
sylvain at infrae.com
Fri Sep 26 07:40:17 EDT 2008
Log message for revision 91507:
- Remove test which are already included in grokcore.formlib,
- Add a test to ensure that forms include an application_url in Grok.
Changed:
D grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/actions.py
D grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/addform.py
D grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/addform_applydata.py
D grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/editform_applydata.py
D grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/editform_applydata_schema.py
D grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/editform_applydata_schemafields.py
U grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/form.py
D grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/templateform.py
D grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/update.py
D grok/branches/sylvain-grokcore-formlib/src/grok/tests/form/
-=-
Deleted: grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/actions.py
===================================================================
--- grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/actions.py 2008-09-26 11:17:12 UTC (rev 91506)
+++ grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/actions.py 2008-09-26 11:40:17 UTC (rev 91507)
@@ -1,81 +0,0 @@
-"""
-Using the @grok.action decorator, different actions can be defined on
-a grok.Form. When @grok.action is used, the default behaviour (the
-'Apply' action) is not available anymore, but it can triggered
-manually by calling self.applyData(object, data).
-
- >>> getRootFolder()["manfred"] = Mammoth()
-
- >>> from zope.testbrowser.testing import Browser
- >>> browser = Browser()
- >>> browser.handleErrors = False
- >>> browser.open("http://localhost/manfred/@@edit")
- >>> browser.getControl(name="form.name").value = "Manfred the Mammoth"
- >>> browser.getControl(name="form.size").value = "Really big"
- >>> browser.getControl("Apply").click()
- >>> print browser.contents
- <html>...
- ...Modified!...
- ...Manfred the Mammoth...
- ...Really big...
- ...
-
-Save again without any changes:
-
- >>> browser.getControl("Apply").click()
- >>> print browser.contents
- <html>...
- ...No changes!...
- ...
-
- >>> browser.open("http://localhost/manfred/@@edit")
- >>> browser.getControl(name="form.name").value = "Manfred the Second"
- >>> browser.getControl("Hairy").click()
- >>> print browser.contents
- <html>...
- ...Manfred the Second...
- ...Really big and hairy...
- ...
-
- >>> browser.open("http://localhost/manfred/meet")
- >>> browser.getControl(name="form.other").value = "Ellie"
- >>> browser.getControl("Meet").click()
- >>> print browser.contents
- Manfred the Second meets Ellie
-"""
-import grok
-from zope import schema
-from zope.interface import Interface, implements
-from zope.schema.fieldproperty import FieldProperty
-
-class IMammoth(Interface):
- name = schema.TextLine(title=u"Name")
- size = schema.TextLine(title=u"Size", default=u"Quite normal")
-
-class Mammoth(grok.Model):
- implements(IMammoth)
-
- name = FieldProperty(IMammoth['name'])
- size = FieldProperty(IMammoth['size'])
-
-class Edit(grok.EditForm):
- @grok.action("Apply")
- def handle_apply(self, **data):
- if self.applyData(self.context, **data):
- self.status = 'Modified!'
- else:
- self.status = 'No changes!'
-
- @grok.action("Hairy")
- def handle_hairy(self, **data):
- self.applyData(self.context, **data)
- self.context.size += " and hairy"
-
-class Meet(grok.Form):
- form_fields = grok.Fields(
- other = schema.TextLine(title=u'Mammoth to meet with')
- )
-
- @grok.action('Meet')
- def meet(self, other):
- return self.context.name + ' meets ' + other
Deleted: grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/addform.py
===================================================================
--- grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/addform.py 2008-09-26 11:17:12 UTC (rev 91506)
+++ grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/addform.py 2008-09-26 11:40:17 UTC (rev 91507)
@@ -1,70 +0,0 @@
-"""
-We can use grok.AddForm to render an add form for objects:
-
- >>> getRootFolder()["zoo"] = Zoo()
-
- >>> from zope.testbrowser.testing import Browser
- >>> browser = Browser()
- >>> browser.handleErrors = False
-
- >>> browser.open("http://localhost/zoo/@@addmammoth")
- >>> browser.getControl(name="form.name").value = "Manfred the Mammoth"
- >>> browser.getControl(name="form.size").value = "Really big"
- >>> browser.getControl("Add entry").click()
- >>> print browser.contents
- Hi, my name is Manfred the Mammoth, and I\'m "Really big"
-
-Instead of calling an object constructor with the form data, we can
-also use the ``applyData`` method to store the data on the object.
-
- >>> browser.open("http://localhost/zoo/@@addmammothapplydata")
- >>> browser.getControl(name="form.name").value = "Ellie the Mammoth"
- >>> browser.getControl(name="form.size").value = "Really small"
- >>> browser.getControl("Add entry").click()
- >>> print browser.contents
- Hi, my name is Ellie the Mammoth, and I\'m "Really small"
-
-"""
-import grok
-from zope import schema
-from zope.interface import Interface, implements
-
-class Zoo(grok.Container):
- pass
-
-class IMammoth(Interface):
- name = schema.TextLine(title=u"Name")
- size = schema.TextLine(title=u"Size", default=u"Quite normal")
-
-class Mammoth(grok.Model):
- implements(IMammoth)
-
- def __init__(self, name='', size=''):
- self.name = name
- self.size = size
-
-class Index(grok.View):
- grok.context(Mammoth)
- def render(self):
- return 'Hi, my name is %s, and I\'m "%s"' % (self.context.name,
- self.context.size)
-
-class AddMammoth(grok.AddForm):
- grok.context(Zoo)
-
- form_fields = grok.AutoFields(Mammoth)
-
- @grok.action('Add entry')
- def add(self, **data):
- # pass data into Mammoth constructor
- self.context['manfred'] = manfred = Mammoth(**data)
- self.redirect(self.url(manfred))
-
-class AddMammothApplyData(AddMammoth):
-
- @grok.action('Add entry')
- def add(self, **data):
- # instantiate Mammoth and then use self.applyData()
- self.context['ellie'] = ellie = Mammoth()
- self.applyData(ellie, **data)
- self.redirect(self.url(ellie))
Deleted: grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/addform_applydata.py
===================================================================
--- grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/addform_applydata.py 2008-09-26 11:17:12 UTC (rev 91506)
+++ grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/addform_applydata.py 2008-09-26 11:40:17 UTC (rev 91507)
@@ -1,66 +0,0 @@
-"""
-We can use AddFrom.applyData to save changes to a newly created
-object. The object doesn't yet need to have the attributes that are
-going to be set on it.
-
- >>> getRootFolder()["zoo"] = Zoo()
-
- >>> from zope.testbrowser.testing import Browser
- >>> browser = Browser()
- >>> browser.handleErrors = False
-
-AddForm.applyData() sends an IObjectModifiedEvent after having
-modified the object. Its return value is True in a Boolean sense when
-the object has been modified:
-
- >>> browser.open("http://localhost/zoo/@@addmammoth")
- >>> browser.getControl(name="form.name").value = "Ellie the Mammoth"
- >>> browser.getControl(name="form.size").value = "Really small"
- >>> browser.getControl("Add entry").click()
- An IObjectModifiedEvent was sent for a mammoth with the following changes:
- IMammoth: name, size
- >>> print browser.contents
- There were changes according to applyData.
-
- >>> browser.open("http://localhost/zoo/ellie")
- >>> print browser.contents
- Hi, my name is Ellie the Mammoth, and I\'m "Really small"
-
-"""
-import grok
-from zope import schema, interface
-
-class Zoo(grok.Container):
- pass
-
-class IMammoth(interface.Interface):
- name = schema.TextLine(title=u"Name")
- size = schema.TextLine(title=u"Size")
-
-class Mammoth(grok.Model):
- grok.implements(IMammoth)
-
-class Index(grok.View):
- grok.context(Mammoth)
- def render(self):
- return 'Hi, my name is %s, and I\'m "%s"' % (self.context.name,
- self.context.size)
-
-class AddMammoth(grok.AddForm):
- grok.context(Zoo)
-
- form_fields = grok.AutoFields(IMammoth)
-
- @grok.action('Add entry')
- def add(self, **data):
- self.context['ellie'] = ellie = Mammoth()
- if self.applyData(ellie, **data):
- return 'There were changes according to applyData.'
- return 'There were no changes according to applyData.'
-
- at grok.subscribe(Mammoth, grok.IObjectModifiedEvent)
-def notify_change_event(mammoth, event):
- print ("An IObjectModifiedEvent was sent for a mammoth with the "
- "following changes:")
- for descr in event.descriptions:
- print descr.interface.__name__ + ": " + ", ".join(descr.attributes)
Deleted: grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/editform_applydata.py
===================================================================
--- grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/editform_applydata.py 2008-09-26 11:17:12 UTC (rev 91506)
+++ grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/editform_applydata.py 2008-09-26 11:40:17 UTC (rev 91507)
@@ -1,89 +0,0 @@
-"""
-A grok.EditForm uses applyData in update mode to save the form data on
-the object. Update mode means that only those fields are changed on
-the object that need to be changed.
-
- >>> getRootFolder()["manfred"] = Mammoth('Manfred the Mammoth', 'Really big')
-
- >>> from zope.testbrowser.testing import Browser
- >>> browser = Browser()
- >>> browser.handleErrors = False
-
-If we don't change any of the fields, there will no object modified
-event and applyData will report no changes:
-
- >>> browser.open("http://localhost/manfred/@@edit")
- >>> browser.getControl("Apply").click()
- >>> 'No changes' in browser.contents
- True
-
-If we change one field, only that attribute will be changed. The
-object modified event also reflects that:
-
- >>> browser.getControl(name="form.name").value = "Manfred the Big Mammoth"
- >>> browser.getControl("Apply").click()
- The 'name' property is being set.
- An IObjectModifiedEvent was sent for a mammoth with the following changes:
- name
- >>> 'Updated' in browser.contents
- True
-
-Let's change the other field:
-
- >>> browser.getControl(name="form.size").value = "Enormously big"
- >>> browser.getControl("Apply").click()
- The 'size' property is being set.
- An IObjectModifiedEvent was sent for a mammoth with the following changes:
- size
- >>> 'Updated' in browser.contents
- True
-
-And finally let's change both fields:
-
- >>> browser.getControl(name="form.name").value = "Manfred the Mammoth"
- >>> browser.getControl(name="form.size").value = "Really big"
- >>> browser.getControl("Apply").click()
- The 'name' property is being set.
- The 'size' property is being set.
- An IObjectModifiedEvent was sent for a mammoth with the following changes:
- name, size
- >>> 'Updated' in browser.contents
- True
-
-"""
-import grok
-from zope import schema
-
-class Mammoth(grok.Model):
-
- def __init__(self, name='', size=''):
- self._name = name
- self._size = size
-
- def getName(self):
- return self._name
- def setName(self, value):
- print "The 'name' property is being set."
- self._name = value
- name = property(getName, setName)
-
- def getSize(self):
- return self._size
- def setSize(self, value):
- print "The 'size' property is being set."
- self._size = value
- size = property(getSize, setSize)
-
-class Edit(grok.EditForm):
-
- form_fields = grok.Fields(
- name = schema.TextLine(title=u"Name"),
- size = schema.TextLine(title=u"Size")
- )
-
- at grok.subscribe(Mammoth, grok.IObjectModifiedEvent)
-def notify_change_event(mammoth, event):
- print ("An IObjectModifiedEvent was sent for a mammoth with the "
- "following changes:")
- for descr in event.descriptions:
- print ", ".join(descr.attributes)
Deleted: grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/editform_applydata_schema.py
===================================================================
--- grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/editform_applydata_schema.py 2008-09-26 11:17:12 UTC (rev 91506)
+++ grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/editform_applydata_schema.py 2008-09-26 11:40:17 UTC (rev 91507)
@@ -1,93 +0,0 @@
-"""
-A grok.EditForm uses applyData in update mode to save the form data on
-the object. Update mode means that only those fields are changed on
-the object that need to be changed.
-
-This is essentially the same narrative as 'editform_applydata'. Here
-we test the whole procedure on fields from schemas:
-
- >>> getRootFolder()["manfred"] = Mammoth('Manfred the Mammoth', 'Really big')
-
- >>> from zope.testbrowser.testing import Browser
- >>> browser = Browser()
- >>> browser.handleErrors = False
-
-If we don't change any of the fields, there will no object modified
-event and applyData will report no changes:
-
- >>> browser.open("http://localhost/manfred/@@edit")
- >>> browser.getControl("Apply").click()
- >>> 'No changes' in browser.contents
- True
-
-If we change one field, only that attribute will be changed. The
-object modified event also reflects that:
-
- >>> browser.getControl(name="form.name").value = "Manfred the Big Mammoth"
- >>> browser.getControl("Apply").click()
- The 'name' property is being set.
- An IObjectModifiedEvent was sent for a mammoth with the following changes:
- IMammoth: name
- >>> 'Updated' in browser.contents
- True
-
-Let's change the other field:
-
- >>> browser.getControl(name="form.size").value = "Enormously big"
- >>> browser.getControl("Apply").click()
- The 'size' property is being set.
- An IObjectModifiedEvent was sent for a mammoth with the following changes:
- IMammoth: size
- >>> 'Updated' in browser.contents
- True
-
-And finally let's change both fields:
-
- >>> browser.getControl(name="form.name").value = "Manfred the Mammoth"
- >>> browser.getControl(name="form.size").value = "Really big"
- >>> browser.getControl("Apply").click()
- The 'name' property is being set.
- The 'size' property is being set.
- An IObjectModifiedEvent was sent for a mammoth with the following changes:
- IMammoth: name, size
- >>> 'Updated' in browser.contents
- True
-
-"""
-import grok
-from zope import schema, interface
-
-class IMammoth(interface.Interface):
- name = schema.TextLine(title=u"Name")
- size = schema.TextLine(title=u"Size")
-
-class Mammoth(grok.Model):
- grok.implements(IMammoth)
-
- def __init__(self, name='', size=''):
- self._name = name
- self._size = size
-
- def getName(self):
- return self._name
- def setName(self, value):
- print "The 'name' property is being set."
- self._name = value
- name = property(getName, setName)
-
- def getSize(self):
- return self._size
- def setSize(self, value):
- print "The 'size' property is being set."
- self._size = value
- size = property(getSize, setSize)
-
-class Edit(grok.EditForm):
- form_fields = grok.AutoFields(IMammoth)
-
- at grok.subscribe(Mammoth, grok.IObjectModifiedEvent)
-def notify_change_event(mammoth, event):
- print ("An IObjectModifiedEvent was sent for a mammoth with the "
- "following changes:")
- for descr in event.descriptions:
- print descr.interface.__name__ + ": " + ", ".join(descr.attributes)
Deleted: grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/editform_applydata_schemafields.py
===================================================================
--- grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/editform_applydata_schemafields.py 2008-09-26 11:17:12 UTC (rev 91506)
+++ grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/editform_applydata_schemafields.py 2008-09-26 11:40:17 UTC (rev 91507)
@@ -1,75 +0,0 @@
-"""
-A grok.EditForm uses applyData in update mode to save the form data on
-the object. Update mode means that only those fields are changed on
-the object that need to be changed.
-
-This is essentially the same narrative as 'editform_applydata'. Here we
-test the whole procedure on fields on the interface implemented by the
-model class:
-
- >>> getRootFolder()["manfred"] = mammoth = Mammoth()
- >>> mammoth.name = 'Manfred the Mammoth'
- >>> mammoth.size = 'Really big'
-
- >>> from zope.testbrowser.testing import Browser
- >>> browser = Browser()
- >>> browser.handleErrors = False
-
-If we don't change any of the fields, there will no object modified
-event and applyData will report no changes:
-
- >>> browser.open("http://localhost/manfred/@@edit")
- >>> browser.getControl("Apply").click()
- >>> 'No changes' in browser.contents
- True
-
-If we change one field, only that attribute will be changed. The
-object modified event also reflects that:
-
- >>> browser.getControl(name="form.name").value = "Manfred the Big Mammoth"
- >>> browser.getControl("Apply").click()
- An IObjectModifiedEvent was sent for a mammoth with the following changes:
- name
- >>> 'Updated' in browser.contents
- True
-
-Let's change the other field:
-
- >>> browser.getControl(name="form.size").value = "Enormously big"
- >>> browser.getControl("Apply").click()
- An IObjectModifiedEvent was sent for a mammoth with the following changes:
- size
- >>> 'Updated' in browser.contents
- True
-
-And finally let's change both fields:
-
- >>> browser.getControl(name="form.name").value = "Manfred the Mammoth"
- >>> browser.getControl(name="form.size").value = "Really big"
- >>> browser.getControl("Apply").click()
- An IObjectModifiedEvent was sent for a mammoth with the following changes:
- name, size
- >>> 'Updated' in browser.contents
- True
-
-"""
-import grok
-from zope import schema
-from zope.interface import Interface, implements
-
-class IMammoth(Interface):
- name = schema.TextLine(title=u"Name")
- size = schema.TextLine(title=u"Size", default=u"Quite normal")
-
-class Mammoth(grok.Model):
- implements(IMammoth)
-
-class Edit(grok.EditForm):
- pass
-
- at grok.subscribe(Mammoth, grok.IObjectModifiedEvent)
-def notify_change_event(mammoth, event):
- print ("An IObjectModifiedEvent was sent for a mammoth with the "
- "following changes:")
- for descr in event.descriptions:
- print ", ".join(descr.attributes)
Modified: grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/form.py
===================================================================
--- grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/form.py 2008-09-26 11:17:12 UTC (rev 91506)
+++ grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/form.py 2008-09-26 11:40:17 UTC (rev 91507)
@@ -1,49 +1,50 @@
"""
-A grok.EditForm is a special grok.View that renders an edit form.
- >>> getRootFolder()["manfred"] = Mammoth()
+Forms have an application_url() method to easily retrieve the url of the
+application, like views does::
+ >>> getRootFolder()['world'] = world = IceWorld()
+ >>> world['arthur'] = Mammoth()
+
+And we can access the display form which display the application URL::
+
>>> from zope.testbrowser.testing import Browser
>>> browser = Browser()
>>> browser.handleErrors = False
- >>> browser.open("http://localhost/manfred/@@edit")
- >>> browser.getControl(name="form.name").value = "Manfred the Mammoth"
- >>> browser.getControl(name="form.size").value = "Really big"
- >>> browser.getControl("Apply").click()
+ >>> browser.open('http://localhost/world/arthur')
>>> print browser.contents
- <html>...
- ...Manfred the Mammoth...
- ...Really big...
- ...
+ <p>Test display: application http://localhost/world</p>
-grok.DisplayForm renders a display form:
+Same for the edit form::
- >>> browser.open("http://localhost/manfred/@@display")
+ >>> browser.open('http://localhost/world/arthur/@@edit')
>>> print browser.contents
- <html>...
- ...Manfred the Mammoth...
- ...Really big...
- ...
+ <p>Test edit: application http://localhost/world</p>
+
"""
import grok
from zope import schema
-from zope.interface import Interface, implements
-from zope.schema.fieldproperty import FieldProperty
-class IMammoth(Interface):
- name = schema.TextLine(title=u"Name")
- size = schema.TextLine(title=u"Size", default=u"Quite normal")
+class IceWorld(grok.Application, grok.Container):
+ pass
+
class Mammoth(grok.Model):
- implements(IMammoth)
-
- name = FieldProperty(IMammoth['name'])
- size = FieldProperty(IMammoth['size'])
+ class fields:
+ name = schema.TextLine(title=u"Name")
+ size = schema.TextLine(title=u"Size", default=u"Quite normal")
+
+class Index(grok.DisplayForm):
+
+ grok.context(Mammoth)
+
+index = grok.PageTemplate('<p>Test display: application <tal:replace tal:replace="view/application_url" /></p>')
+
+
class Edit(grok.EditForm):
- pass
+
+ grok.context(Mammoth)
-class Display(grok.DisplayForm):
- pass
-
+edit = grok.PageTemplate('<p>Test edit: application <tal:replace tal:replace="view/application_url" /></p>')
Deleted: grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/templateform.py
===================================================================
--- grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/templateform.py 2008-09-26 11:17:12 UTC (rev 91506)
+++ grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/templateform.py 2008-09-26 11:40:17 UTC (rev 91507)
@@ -1,74 +0,0 @@
-"""
-If a form does not have a template, a simple default template is
-associated with them. Otherwise, the supplied template is used.
-
- >>> from zope.publisher.browser import TestRequest
- >>> request = TestRequest()
- >>> from zope import component
-
-Default edit template:
-
- >>> view = component.getMultiAdapter((Mammoth(), request), name='edit')
- >>> print view()
- <html>...
-
-Custom edit template:
-
- >>> view = component.getMultiAdapter((Mammoth(), request), name='edit2')
- >>> print view()
- <p>Test edit</p>
-
-Custom edit template with an explicit template
-
- >>> view = component.getMultiAdapter((Mammoth(), request), name='edit3')
- >>> print view()
- <p>Test edit</p>
-
-Default display template:
-
- >>> view = component.getMultiAdapter((Mammoth(), request), name='display')
- >>> print view()
- <html>...
-
-Custom display template:
-
- >>> view = component.getMultiAdapter((Mammoth(), request), name='display2')
- >>> print view()
- <p>Test display</p>
-
-Custom display template with an explicit template:
-
- >>> view = component.getMultiAdapter((Mammoth(), request), name='display3')
- >>> print view()
- <p>Test display</p>
-
-"""
-import grok
-from zope import schema
-
-class Mammoth(grok.Model):
- class fields:
- name = schema.TextLine(title=u"Name")
- size = schema.TextLine(title=u"Size", default=u"Quite normal")
-
-class Edit(grok.EditForm):
- pass
-
-class Edit2(grok.EditForm):
- pass
-
-edit2 = grok.PageTemplate('<p>Test edit</p>')
-
-class Edit3(grok.EditForm):
- grok.template('edit2')
-
-class Display(grok.DisplayForm):
- pass
-
-class Display2(grok.DisplayForm):
- pass
-
-display2 = grok.PageTemplate('<p>Test display</p>')
-
-class Display3(grok.DisplayForm):
- grok.template('display2')
Deleted: grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/update.py
===================================================================
--- grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/update.py 2008-09-26 11:17:12 UTC (rev 91506)
+++ grok/branches/sylvain-grokcore-formlib/src/grok/ftests/form/update.py 2008-09-26 11:40:17 UTC (rev 91507)
@@ -1,93 +0,0 @@
-"""
-Forms can implement an update() method that will be called before any
-form processing has happened:
-
- >>> getRootFolder()["manfred"] = Mammoth()
-
- >>> from zope.testbrowser.testing import Browser
- >>> browser = Browser()
- >>> browser.handleErrors = False
- >>> browser.open("http://localhost/manfred/edit")
- >>> browser.getControl(name="form.name").value = "Ellie"
- >>> browser.getControl("Apply").click()
-
- >>> browser.open("http://localhost/manfred")
- >>> print browser.contents
- Ellie, the Mammoth reports: The form's update() was called and my name was Manfred.
-
-A form's update() method can issue a redirect. In that case, the form
-won't proceed to do any form processing nor rendering:
-
- >>> browser.open("http://localhost/manfred/editredirect")
- >>> browser.getControl(name="form.name").value = "Mallie"
- >>> browser.getControl("Apply").click()
- >>> print browser.url
- http://localhost/manfred/index
-
-Because of the redirect, no changes happened to the edited object:
-
- >>> print browser.contents
- Ellie, the Mammoth reports: The form's update() was called and my name was Manfred.
-
-A form's update() method may also take arbitrary parameters that will
-be filled with values from the request (such as form values):
-
- >>> browser.open("http://localhost/manfred/editupdatewitharguments")
- >>> browser.getControl(name="report").value = "Request argument dispatch to update() works."
- >>> browser.getControl(name="form.name").value = "Mallie"
- >>> browser.getControl("Apply").click()
-
- >>> browser.open("http://localhost/manfred")
- >>> print browser.contents
- Mallie, the Mammoth reports: Request argument dispatch to update() works.
-
-"""
-import grok
-from zope import schema
-
-from zope.interface import Interface, implements
-
-class IMammoth(Interface):
- name = schema.TextLine(title=u"Name")
-
-class Mammoth(grok.Model):
- implements(IMammoth)
-
- name = u'Manfred'
-
-class Index(grok.View):
-
- def render(self):
- return "%s, the Mammoth reports: %s" % (self.context.name,
- self.context.report)
-
-class Edit(grok.EditForm):
-
- def update(self):
- self.context.report = ("The form's update() was called and my name "
- "was %s." % self.context.name)
-
-class EditRedirect(grok.EditForm):
-
- def update(self):
- # redirect upon form submit so that no changes are ever saved
- if 'form.name' in self.request:
- self.redirect(self.url('index'))
-
-class EditUpdateWithArguments(grok.EditForm):
-
- def update(self, report=None):
- if report is not None:
- self.context.report = report
-
-editupdatewitharguments = grok.PageTemplate("""
-<html>
-<body>
-<form action="" tal:attributes="action request/URL">
- <input type="text" name="report" />
- <div tal:repeat="widget view/widgets" tal:content="structure widget" />
- <div tal:repeat="action view/actions" tal:content="structure action/render" />
-</form>
-</body>
-</html>
-""")
More information about the Checkins
mailing list