[Checkins] SVN: Grokstar/trunk/src/grokstar/ factor out custom form template so that it can be shared across add/edit forms

Robert Marianski rmarianski at openplans.org
Tue Mar 18 23:37:36 EDT 2008


Log message for revision 84777:
  factor out custom form template so that it can be shared across add/edit forms

Changed:
  U   Grokstar/trunk/src/grokstar/blog.py
  D   Grokstar/trunk/src/grokstar/blog_templates/blogedit.pt
  U   Grokstar/trunk/src/grokstar/entry.py
  D   Grokstar/trunk/src/grokstar/entry_templates/add.pt
  D   Grokstar/trunk/src/grokstar/entry_templates/edit.pt
  A   Grokstar/trunk/src/grokstar/form.py
  A   Grokstar/trunk/src/grokstar/form_templates/
  A   Grokstar/trunk/src/grokstar/form_templates/grokstaraddform.pt
  A   Grokstar/trunk/src/grokstar/form_templates/grokstareditform.pt

-=-
Modified: Grokstar/trunk/src/grokstar/blog.py
===================================================================
--- Grokstar/trunk/src/grokstar/blog.py	2008-03-19 03:36:44 UTC (rev 84776)
+++ Grokstar/trunk/src/grokstar/blog.py	2008-03-19 03:37:36 UTC (rev 84777)
@@ -14,6 +14,7 @@
 from grokstar.interfaces import IRestructuredTextEntry, IBlog
 from grokstar.interfaces import PUBLISHED, CREATED
 from grokstar.base import ViewBase
+from form import GrokstarEditForm
 
 class Blog(grok.Container, grok.Application):
     interface.implements(IBlog)
@@ -65,9 +66,10 @@
 class BlogMacros(ViewBase):
     grok.context(Interface)
 
-class BlogEdit(grok.EditForm, ViewBase):
+class BlogEdit(GrokstarEditForm):
     grok.context(Blog)
     grok.name('edit')
+    title = u'Edit Blog'
 
     @grok.action('Save changes')
     def edit(self, **data):

Deleted: Grokstar/trunk/src/grokstar/blog_templates/blogedit.pt
===================================================================
--- Grokstar/trunk/src/grokstar/blog_templates/blogedit.pt	2008-03-19 03:36:44 UTC (rev 84776)
+++ Grokstar/trunk/src/grokstar/blog_templates/blogedit.pt	2008-03-19 03:37:36 UTC (rev 84777)
@@ -1,72 +0,0 @@
-<html metal:use-macro="context/@@blogmacros/macros/blogpage">
-<head>
-<title metal:fill-slot="title">Edit blog</title>
-</head>
-
-<body>
-  <div metal:fill-slot="main-content">
-    <form action="." tal:attributes="action request/URL" method="post"
-          class="edit-form" enctype="multipart/form-data">
-
-      <h1 i18n:translate=""
-          tal:condition="view/label"
-          tal:content="view/label">Label</h1>
-
-      <div class="form-status"
-           tal:define="status view/status"
-           tal:condition="status">
-
-        <div i18n:translate="" tal:content="view/status">
-          Form status summary
-        </div>
-
-        <ul class="errors" tal:condition="view/errors">
-          <li tal:repeat="error view/error_views">
-            <span tal:replace="structure error">Error Type</span>
-          </li>
-        </ul>
-      </div>
-
-      <table class="form-fields">
-        <tbody>
-          <tal:block repeat="widget view/widgets">
-            <tr>
-              <td class="label" tal:define="hint widget/hint">
-                <label tal:condition="python:hint"
-                       tal:attributes="for widget/name">
-                  <span class="required" tal:condition="widget/required"
-                        >*</span><span i18n:translate=""
-                                       tal:content="widget/label">label</span>
-                </label>
-                <label tal:condition="python:not hint"
-                       tal:attributes="for widget/name">
-                  <span class="required" tal:condition="widget/required"
-                        >*</span><span i18n:translate=""
-                                       tal:content="widget/label">label</span>
-                </label>
-              </td>
-              <td class="field">
-                <div class="widget" tal:content="structure widget">
-                  <input type="text" />
-                </div>
-                <div class="error" tal:condition="widget/error">
-                  <span tal:replace="structure widget/error">error</span>
-                </div>
-              </td>
-            </tr>
-          </tal:block>
-        </tbody>
-      </table>
-
-      <div id="actionsView">
-        <span class="actionButtons" tal:condition="view/availableActions">
-          <input tal:repeat="action view/actions"
-                 tal:replace="structure action/render"
-                 />
-        </span>
-      </div>
-    </form>
-
-  </div>
-</body>
-</html>

Modified: Grokstar/trunk/src/grokstar/entry.py
===================================================================
--- Grokstar/trunk/src/grokstar/entry.py	2008-03-19 03:36:44 UTC (rev 84776)
+++ Grokstar/trunk/src/grokstar/entry.py	2008-03-19 03:37:36 UTC (rev 84777)
@@ -11,6 +11,7 @@
 from grokstar.blog import Blog
 from grokstar import interfaces
 from grokstar.base import ViewBase
+from form import GrokstarAddForm, GrokstarEditForm
 
 class Entry(grok.Model):
     interface.implements(interfaces.IEntry, IAttributeAnnotatable)
@@ -41,9 +42,9 @@
         return published_date.strftime('%Y-%m-%d')
 
 
-class Add(grok.AddForm, ViewBase):
+class Add(GrokstarAddForm):
     grok.context(Blog)
-
+    title = u'Add Entry'
     # add the url that the user wants
     form_fields = grok.Fields(
         id=schema.TextLine(title=u"Url name"))
@@ -67,7 +68,9 @@
         self.redirect(self.url(self.context))
 
 
-class Edit(grok.EditForm, ViewBase):
+class Edit(GrokstarEditForm):
+    grok.context(RestructuredTextEntry)
+    title = u'Edit Entry'
     form_fields = grok.AutoFields(RestructuredTextEntry).omit(
         'published', 'updated')
 

Deleted: Grokstar/trunk/src/grokstar/entry_templates/add.pt
===================================================================
--- Grokstar/trunk/src/grokstar/entry_templates/add.pt	2008-03-19 03:36:44 UTC (rev 84776)
+++ Grokstar/trunk/src/grokstar/entry_templates/add.pt	2008-03-19 03:37:36 UTC (rev 84777)
@@ -1,71 +0,0 @@
-<html metal:use-macro="context/@@blogmacros/macros/blogpage" >
-<head>
-<title metal:fill-slot="title">Add Entry</title>
-</head>
-
-<body>
-<div metal:fill-slot="main-content">
-<form action="." tal:attributes="action request/URL" method="post"
-      class="edit-form" enctype="multipart/form-data">
-
-  <h1 i18n:translate=""
-    tal:condition="view/label"
-    tal:content="view/label">Label</h1>
-
-  <div class="form-status"
-    tal:define="status view/status"
-    tal:condition="status">
-
-    <div i18n:translate="" tal:content="view/status">
-      Form status summary
-    </div>
-
-    <ul class="errors" tal:condition="view/errors">
-      <li tal:repeat="error view/error_views">
-         <span tal:replace="structure error">Error Type</span>
-      </li>
-    </ul>
-  </div>
-
-  <table class="form-fields">
-    <tbody>
-      <tal:block repeat="widget view/widgets">
-        <tr>
-          <td class="label" tal:define="hint widget/hint">
-            <label tal:condition="python:hint"
-                   tal:attributes="for widget/name">
-              <span class="required" tal:condition="widget/required"
-              >*</span><span i18n:translate=""
-                             tal:content="widget/label">label</span>
-            </label>
-            <label tal:condition="python:not hint"
-                   tal:attributes="for widget/name">
-              <span class="required" tal:condition="widget/required"
-              >*</span><span i18n:translate=""
-                             tal:content="widget/label">label</span>
-            </label>
-          </td>
-          <td class="field">
-            <div class="widget" tal:content="structure widget">
-              <input type="text" />
-            </div>
-            <div class="error" tal:condition="widget/error">
-              <span tal:replace="structure widget/error">error</span>
-            </div>
-          </td>
-        </tr>
-      </tal:block>
-    </tbody>
-  </table>
-
-  <div id="actionsView">
-    <span class="actionButtons" tal:condition="view/availableActions">
-      <input tal:repeat="action view/actions"
-             tal:replace="structure action/render"
-             />
-    </span>
-  </div>
-</form>
-</div>
-</body>
-</html>

Deleted: Grokstar/trunk/src/grokstar/entry_templates/edit.pt
===================================================================
--- Grokstar/trunk/src/grokstar/entry_templates/edit.pt	2008-03-19 03:36:44 UTC (rev 84776)
+++ Grokstar/trunk/src/grokstar/entry_templates/edit.pt	2008-03-19 03:37:36 UTC (rev 84777)
@@ -1,72 +0,0 @@
-<html metal:use-macro="context/@@blogmacros/macros/blogpage">
-<head>
-<title metal:fill-slot="title">Edit entry</title>
-</head>
-
-<body>
-  <div metal:fill-slot="main-content">
-    <form action="." tal:attributes="action request/URL" method="post"
-          class="edit-form" enctype="multipart/form-data">
-
-      <h1 i18n:translate=""
-          tal:condition="view/label"
-          tal:content="view/label">Label</h1>
-
-      <div class="form-status"
-           tal:define="status view/status"
-           tal:condition="status">
-
-        <div i18n:translate="" tal:content="view/status">
-          Form status summary
-        </div>
-
-        <ul class="errors" tal:condition="view/errors">
-          <li tal:repeat="error view/error_views">
-            <span tal:replace="structure error">Error Type</span>
-          </li>
-        </ul>
-      </div>
-
-      <table class="form-fields">
-        <tbody>
-          <tal:block repeat="widget view/widgets">
-            <tr>
-              <td class="label" tal:define="hint widget/hint">
-                <label tal:condition="python:hint"
-                       tal:attributes="for widget/name">
-                  <span class="required" tal:condition="widget/required"
-                        >*</span><span i18n:translate=""
-                                       tal:content="widget/label">label</span>
-                </label>
-                <label tal:condition="python:not hint"
-                       tal:attributes="for widget/name">
-                  <span class="required" tal:condition="widget/required"
-                        >*</span><span i18n:translate=""
-                                       tal:content="widget/label">label</span>
-                </label>
-              </td>
-              <td class="field">
-                <div class="widget" tal:content="structure widget">
-                  <input type="text" />
-                </div>
-                <div class="error" tal:condition="widget/error">
-                  <span tal:replace="structure widget/error">error</span>
-                </div>
-              </td>
-            </tr>
-          </tal:block>
-        </tbody>
-      </table>
-
-      <div id="actionsView">
-        <span class="actionButtons" tal:condition="view/availableActions">
-          <input tal:repeat="action view/actions"
-                 tal:replace="structure action/render"
-                 />
-        </span>
-      </div>
-    </form>
-
-  </div>
-</body>
-</html>

Added: Grokstar/trunk/src/grokstar/form.py
===================================================================
--- Grokstar/trunk/src/grokstar/form.py	                        (rev 0)
+++ Grokstar/trunk/src/grokstar/form.py	2008-03-19 03:37:36 UTC (rev 84777)
@@ -0,0 +1,8 @@
+import grok
+from base import ViewBase
+
+class GrokstarAddForm(grok.AddForm, ViewBase):
+    pass
+
+class GrokstarEditForm(grok.EditForm, ViewBase):
+    pass

Added: Grokstar/trunk/src/grokstar/form_templates/grokstaraddform.pt
===================================================================
--- Grokstar/trunk/src/grokstar/form_templates/grokstaraddform.pt	                        (rev 0)
+++ Grokstar/trunk/src/grokstar/form_templates/grokstaraddform.pt	2008-03-19 03:37:36 UTC (rev 84777)
@@ -0,0 +1,71 @@
+<html metal:use-macro="context/@@blogmacros/macros/blogpage" >
+<head>
+  <title metal:fill-slot="title" tal:content="view/title | default">Add</title>
+</head>
+
+<body>
+<div metal:fill-slot="main-content">
+<form action="." tal:attributes="action request/URL" method="post"
+      class="edit-form" enctype="multipart/form-data">
+
+  <h1 i18n:translate=""
+    tal:condition="view/label"
+    tal:content="view/label">Label</h1>
+
+  <div class="form-status"
+    tal:define="status view/status"
+    tal:condition="status">
+
+    <div i18n:translate="" tal:content="view/status">
+      Form status summary
+    </div>
+
+    <ul class="errors" tal:condition="view/errors">
+      <li tal:repeat="error view/error_views">
+         <span tal:replace="structure error">Error Type</span>
+      </li>
+    </ul>
+  </div>
+
+  <table class="form-fields">
+    <tbody>
+      <tal:block repeat="widget view/widgets">
+        <tr>
+          <td class="label" tal:define="hint widget/hint">
+            <label tal:condition="python:hint"
+                   tal:attributes="for widget/name">
+              <span class="required" tal:condition="widget/required"
+              >*</span><span i18n:translate=""
+                             tal:content="widget/label">label</span>
+            </label>
+            <label tal:condition="python:not hint"
+                   tal:attributes="for widget/name">
+              <span class="required" tal:condition="widget/required"
+              >*</span><span i18n:translate=""
+                             tal:content="widget/label">label</span>
+            </label>
+          </td>
+          <td class="field">
+            <div class="widget" tal:content="structure widget">
+              <input type="text" />
+            </div>
+            <div class="error" tal:condition="widget/error">
+              <span tal:replace="structure widget/error">error</span>
+            </div>
+          </td>
+        </tr>
+      </tal:block>
+    </tbody>
+  </table>
+
+  <div id="actionsView">
+    <span class="actionButtons" tal:condition="view/availableActions">
+      <input tal:repeat="action view/actions"
+             tal:replace="structure action/render"
+             />
+    </span>
+  </div>
+</form>
+</div>
+</body>
+</html>

Added: Grokstar/trunk/src/grokstar/form_templates/grokstareditform.pt
===================================================================
--- Grokstar/trunk/src/grokstar/form_templates/grokstareditform.pt	                        (rev 0)
+++ Grokstar/trunk/src/grokstar/form_templates/grokstareditform.pt	2008-03-19 03:37:36 UTC (rev 84777)
@@ -0,0 +1,72 @@
+<html metal:use-macro="context/@@blogmacros/macros/blogpage">
+<head>
+  <title metal:fill-slot="title" tal:content="view/title | default">Edit</title>
+</head>
+
+<body>
+  <div metal:fill-slot="main-content">
+    <form action="." tal:attributes="action request/URL" method="post"
+          class="edit-form" enctype="multipart/form-data">
+
+      <h1 i18n:translate=""
+          tal:condition="view/label"
+          tal:content="view/label">Label</h1>
+
+      <div class="form-status"
+           tal:define="status view/status"
+           tal:condition="status">
+
+        <div i18n:translate="" tal:content="view/status">
+          Form status summary
+        </div>
+
+        <ul class="errors" tal:condition="view/errors">
+          <li tal:repeat="error view/error_views">
+            <span tal:replace="structure error">Error Type</span>
+          </li>
+        </ul>
+      </div>
+
+      <table class="form-fields">
+        <tbody>
+          <tal:block repeat="widget view/widgets">
+            <tr>
+              <td class="label" tal:define="hint widget/hint">
+                <label tal:condition="python:hint"
+                       tal:attributes="for widget/name">
+                  <span class="required" tal:condition="widget/required"
+                        >*</span><span i18n:translate=""
+                                       tal:content="widget/label">label</span>
+                </label>
+                <label tal:condition="python:not hint"
+                       tal:attributes="for widget/name">
+                  <span class="required" tal:condition="widget/required"
+                        >*</span><span i18n:translate=""
+                                       tal:content="widget/label">label</span>
+                </label>
+              </td>
+              <td class="field">
+                <div class="widget" tal:content="structure widget">
+                  <input type="text" />
+                </div>
+                <div class="error" tal:condition="widget/error">
+                  <span tal:replace="structure widget/error">error</span>
+                </div>
+              </td>
+            </tr>
+          </tal:block>
+        </tbody>
+      </table>
+
+      <div id="actionsView">
+        <span class="actionButtons" tal:condition="view/availableActions">
+          <input tal:repeat="action view/actions"
+                 tal:replace="structure action/render"
+                 />
+        </span>
+      </div>
+    </form>
+
+  </div>
+</body>
+</html>



More information about the Checkins mailing list