[Checkins] SVN: Sandbox/cklinger/example/trunk/src/example/ First Steps for the example app

Christian Klinger cklinger at novareto.de
Tue Feb 3 09:48:19 EST 2009


Log message for revision 96037:
  First Steps for the example app

Changed:
  U   Sandbox/cklinger/example/trunk/src/example/app.py
  A   Sandbox/cklinger/example/trunk/src/example/layout.pt
  A   Sandbox/cklinger/example/trunk/src/example/message/
  A   Sandbox/cklinger/example/trunk/src/example/message/__init__.py
  A   Sandbox/cklinger/example/trunk/src/example/message/forms.py
  A   Sandbox/cklinger/example/trunk/src/example/message/interfaces.py
  A   Sandbox/cklinger/example/trunk/src/example/message/message.py
  A   Sandbox/cklinger/example/trunk/src/example/message/what_values.csv

-=-
Modified: Sandbox/cklinger/example/trunk/src/example/app.py
===================================================================
--- Sandbox/cklinger/example/trunk/src/example/app.py	2009-02-03 14:26:54 UTC (rev 96036)
+++ Sandbox/cklinger/example/trunk/src/example/app.py	2009-02-03 14:48:19 UTC (rev 96037)
@@ -1,7 +1,39 @@
 import grok
+import megrok.pagelet
+from zope.interface import Interface
 
+
+### Skin
+import z3c.formui.interfaces
+from z3c.form.interfaces import IFormLayer
+from z3c.layer.pagelet import IPageletBrowserLayer
+
+class MySkinLayer(grok.IBrowserRequest, IFormLayer):
+    pass
+
+class MySkin(z3c.formui.interfaces.IDivFormLayer, MySkinLayer):
+    grok.skin('myskin')
+
+
+grok.layer(MySkin)
+
 class Example(grok.Application, grok.Container):
     pass
 
 class Index(grok.View):
     pass # see app_templates/index.pt
+
+
+class ExampleLayout(megrok.pagelet.LayoutView):
+    """ This is our general Layout Template"""
+    grok.context(Interface)
+    megrok.pagelet.template('layout.pt')
+
+class Start(megrok.pagelet.Pagelet):
+    """ This is a simple Pagelet which is renderd in the Layout Template"""
+    grok.context(Example)
+    grok.layer(MySkin)
+
+    def render(self):
+        return "<p> This is the render method of the <b> Start </b> class </p>"
+    

Added: Sandbox/cklinger/example/trunk/src/example/layout.pt
===================================================================
--- Sandbox/cklinger/example/trunk/src/example/layout.pt	                        (rev 0)
+++ Sandbox/cklinger/example/trunk/src/example/layout.pt	2009-02-03 14:48:19 UTC (rev 96037)
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+  <head>
+    <title>EXAMPLE</title>
+    <style type="text/css">
+      <!--
+       * {
+         margin: 0;
+         padding: 0;
+       }
+       body {
+         padding: 1em;
+       }
+       #content{
+         border: 1px solid #999;
+         padding: 1em;
+         background: #eee;
+       }
+      -->
+    </style>
+  </head>
+  <body>
+    <h1>EXAMPLE</h1>
+
+    <!-- Die Magie findet in der naechsten Zeile statt! -->
+    <div id="content"
+         tal:content="structure view/render">Page Content</div>
+
+    <i>Example Tutorial Application</i>
+  </body>
+</html>
+

Added: Sandbox/cklinger/example/trunk/src/example/message/__init__.py
===================================================================
--- Sandbox/cklinger/example/trunk/src/example/message/__init__.py	                        (rev 0)
+++ Sandbox/cklinger/example/trunk/src/example/message/__init__.py	2009-02-03 14:48:19 UTC (rev 96037)
@@ -0,0 +1 @@
+# package

Added: Sandbox/cklinger/example/trunk/src/example/message/forms.py
===================================================================
--- Sandbox/cklinger/example/trunk/src/example/message/forms.py	                        (rev 0)
+++ Sandbox/cklinger/example/trunk/src/example/message/forms.py	2009-02-03 14:48:19 UTC (rev 96037)
@@ -0,0 +1,55 @@
+import grok
+import datetime
+from zope.traversing.browser import absoluteURL
+from z3c.form import button, field, form, widget
+from z3c.form.interfaces import IAddForm
+
+import interfaces, message
+from megrok.z3cform import AddForm, EditForm, DisplayForm
+from example.app import MySkin
+from example.app import Example
+
+grok.layer(MySkin)
+
+DefaultDate = widget.ComputedWidgetAttribute(
+    lambda adapter: datetime.date.today(),
+    field=interfaces.IHelloWorld['when'], view=IAddForm)
+
+class HelloWorldAddForm(AddForm):
+    """ A sample add form."""
+    grok.context(Example)
+    fields = field.Fields(interfaces.IHelloWorld)
+
+    def create(self, data):
+        return message.HelloWorld(**data)
+
+    def add(self, object):
+        count = 0
+        while 'helloworld-%i' %count in self.context:
+            count += 1;
+        self._name = 'helloworld-%i' %count
+        self.context[self._name] = object
+        return object
+
+    def nextURL(self):
+        return absoluteURL(self.context[self._name], self.request)
+
+
+class HelloWorldEditForm(EditForm):
+    grok.context(message.HelloWorld)
+    form.extends(form.EditForm)
+    label = u'Hello World Message Edit Form'
+    fields = field.Fields(interfaces.IHelloWorld)
+
+    @button.buttonAndHandler(u'Apply and View', name='applyView')
+    def handleApplyView(self, action):
+        self.handleApply(self, action)
+        if not self.widgets.errors:
+            url = absoluteURL(self.context, self.request)
+            self.request.response.redirect(url)
+
+class HelloWorldDisplayForm(DisplayForm):
+    grok.context(message.HelloWorld)
+    grok.name('index')
+    fields = field.Fields(interfaces.IHelloWorld)
+

Added: Sandbox/cklinger/example/trunk/src/example/message/interfaces.py
===================================================================
--- Sandbox/cklinger/example/trunk/src/example/message/interfaces.py	                        (rev 0)
+++ Sandbox/cklinger/example/trunk/src/example/message/interfaces.py	2009-02-03 14:48:19 UTC (rev 96037)
@@ -0,0 +1,28 @@
+import os
+import zope.interface
+import zope.schema
+from z3c.csvvocabulary import CSVVocabulary
+
+WhatVocabulary = CSVVocabulary(
+    os.path.join(os.path.dirname(__file__), 'what_values.csv'))
+
+class IHelloWorld(zope.interface.Interface):
+    """Information about a hello world message"""
+
+    who = zope.schema.TextLine(
+        title=u'Who',
+        description=u'Name of the person sending the message',
+        required=True)
+
+    when = zope.schema.Date(
+        title=u'When',
+        description=u'Date of the message sent.',
+        required=True)
+
+    what = zope.schema.Choice(
+        title=u'What',
+        description=u'What type of message it is.',
+        vocabulary=WhatVocabulary,
+        default=u'cool',
+        required=True)
+

Added: Sandbox/cklinger/example/trunk/src/example/message/message.py
===================================================================
--- Sandbox/cklinger/example/trunk/src/example/message/message.py	                        (rev 0)
+++ Sandbox/cklinger/example/trunk/src/example/message/message.py	2009-02-03 14:48:19 UTC (rev 96037)
@@ -0,0 +1,18 @@
+import grok
+import persistent
+import zope.interface
+from zope.schema import fieldproperty
+import interfaces
+
+class HelloWorld(grok.Model):
+    grok.implements(interfaces.IHelloWorld)
+
+    who = fieldproperty.FieldProperty(interfaces.IHelloWorld['who'])
+    when = fieldproperty.FieldProperty(interfaces.IHelloWorld['when'])
+    what = fieldproperty.FieldProperty(interfaces.IHelloWorld['what'])
+
+    def __init__(self, who, when, what):
+        self.who = who
+        self.when = when
+        self.what = what
+

Added: Sandbox/cklinger/example/trunk/src/example/message/what_values.csv
===================================================================
--- Sandbox/cklinger/example/trunk/src/example/message/what_values.csv	                        (rev 0)
+++ Sandbox/cklinger/example/trunk/src/example/message/what_values.csv	2009-02-03 14:48:19 UTC (rev 96037)
@@ -0,0 +1,4 @@
+"cool";"cool"
+"sunny";"sunny"
+"silent";"silent"
+"best";"best"



More information about the Checkins mailing list