[z3-checkins] r5636 - z3/Five/trunk/demo/FiveFormDemo

andy_a at codespeak.net andy_a at codespeak.net
Fri Jul 23 16:11:17 MEST 2004


Author: andy_a
Date: Fri Jul 23 16:11:16 2004
New Revision: 5636

Added:
   z3/Five/trunk/demo/FiveFormDemo/
   z3/Five/trunk/demo/FiveFormDemo/README.txt
   z3/Five/trunk/demo/FiveFormDemo/__init__.py   (contents, props changed)
   z3/Five/trunk/demo/FiveFormDemo/browser.py   (contents, props changed)
   z3/Five/trunk/demo/FiveFormDemo/configure.zcml
   z3/Five/trunk/demo/FiveFormDemo/contact.py   (contents, props changed)
Log:
Added a *very* basic form demo. Just some fields from a schema.

Added: z3/Five/trunk/demo/FiveFormDemo/README.txt
==============================================================================
--- (empty file)
+++ z3/Five/trunk/demo/FiveFormDemo/README.txt	Fri Jul 23 16:11:16 2004
@@ -0,0 +1,3 @@
+This is a *very* basic example for zop3 schemas + widgets.
+
+Just copy to Products and run. Needs FiveViewsDemo for now.

Added: z3/Five/trunk/demo/FiveFormDemo/__init__.py
==============================================================================
--- (empty file)
+++ z3/Five/trunk/demo/FiveFormDemo/__init__.py	Fri Jul 23 16:11:16 2004
@@ -0,0 +1 @@
+# Very simple demo of zope3 forms
\ No newline at end of file

Added: z3/Five/trunk/demo/FiveFormDemo/browser.py
==============================================================================
--- (empty file)
+++ z3/Five/trunk/demo/FiveFormDemo/browser.py	Fri Jul 23 16:11:16 2004
@@ -0,0 +1,36 @@
+from Products.Five.api import BrowserView
+
+from zope.app.form.utility import setUpWidgets, getWidgetsData
+from zope.schema import getFieldNamesInOrder
+from zope.app.form.interfaces import IInputWidget
+
+from contact import ISimpleContact
+
+class SimpleFormView(BrowserView):
+    """More docstring. Please Zope"""
+
+    def __init__(self, context, request):
+        BrowserView.__init__(self, context, request)
+
+        setUpWidgets(self, ISimpleContact, IInputWidget)
+
+    def simpleForm(self):
+        """www"""
+        result=''
+        result+='<form action="formSubmit" method="post">'
+        for widget in self.getWidgets():
+            result+=widget.label+': <br/>'+widget()+'<br/>\n'
+        result+='<input type="submit" name="submit" value="submit"/>'
+        result+='</form>'
+
+        return result;
+
+    def formSubmit(self):
+        """www"""
+        data = getWidgetsData(self, ISimpleContact)
+        return "<html><body>The data you entered:<br/>"+str(data)+"</body></html>"
+
+    def getWidgets(self):
+        return ([getattr(self, name+'_widget')
+                 for name in getFieldNamesInOrder(ISimpleContact)]
+                )

Added: z3/Five/trunk/demo/FiveFormDemo/configure.zcml
==============================================================================
--- (empty file)
+++ z3/Five/trunk/demo/FiveFormDemo/configure.zcml	Fri Jul 23 16:11:16 2004
@@ -0,0 +1,19 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+           xmlns:browser="http://namespaces.zope.org/browser"
+           xmlns:five="http://namespaces.zope.org/five">
+
+  <include package="zope.app.form.browser"/>
+
+  <browser:pages
+    for="Products.Five.interfaces.IFolder"
+    class=".browser.SimpleFormView"
+    permission="zope2.Public">
+    <browser:page
+        attribute="simpleForm"
+        name="simpleform.html"/>
+    <browser:page
+        attribute="formSubmit"
+        name="formSubmit"/>
+    </browser:pages>
+
+</configure>

Added: z3/Five/trunk/demo/FiveFormDemo/contact.py
==============================================================================
--- (empty file)
+++ z3/Five/trunk/demo/FiveFormDemo/contact.py	Fri Jul 23 16:11:16 2004
@@ -0,0 +1,18 @@
+import re
+from zope.interface import Interface, implements
+from zope.schema import TextLine, Choice, Int
+
+class ISimpleContact(Interface):
+    salutation = Choice(title=u'Salutation', values=("Mr.", "Mrs.", "Captain", "Don"))
+    contactname = TextLine(title=u'Name')
+    mailaddress = TextLine(title=u'E-Mail Address', required=0)
+    age = Int(title=u'Your age')
+    postal_code = TextLine(title=u'Postal code',
+         constraint=re.compile("\d{5,5}(-\d{4,4})?$").match)
+
+class SimpleContact:
+    implements(ISimpleContact)
+    def __init__(self, mailaddress=None, contactname=None):
+        self.mailaddress = mailaddress
+        self.contactname = contactname
+


More information about the z3-checkins mailing list