← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~allenap/launchpad/row-row-row-your-widget into lp:launchpad

 

Gavin Panella has proposed merging lp:~allenap/launchpad/row-row-row-your-widget into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~allenap/launchpad/row-row-row-your-widget/+merge/86035

This factors out the single-line, multi-line, checkbox and hidden layout code from the widget_row macro and reuses it to make a widget_div macro that will be useful where widgets need special placement.

-- 
https://code.launchpad.net/~allenap/launchpad/row-row-row-your-widget/+merge/86035
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/launchpad/row-row-row-your-widget into lp:launchpad.
=== added file 'lib/lp/app/browser/tests/test-widget-div.pt'
--- lib/lp/app/browser/tests/test-widget-div.pt	1970-01-01 00:00:00 +0000
+++ lib/lp/app/browser/tests/test-widget-div.pt	2011-12-16 12:38:26 +0000
@@ -0,0 +1,20 @@
+<div
+    xmlns="http://www.w3.org/1999/xhtml";
+    xmlns:tal="http://xml.zope.org/namespaces/tal";
+    xmlns:metal="http://xml.zope.org/namespaces/metal";
+    xmlns:i18n="http://xml.zope.org/namespaces/i18n";
+    i18n:domain="launchpad">
+
+  <tal:single-line define="widget nocall:view/widgets/single_line">
+    <metal:widget-div use-macro="widget/@@launchpad_form/widget_div" />
+  </tal:single-line>
+
+  <tal:multi-line define="widget nocall:view/widgets/multi_line">
+    <metal:widget-div use-macro="widget/@@launchpad_form/widget_div" />
+  </tal:multi-line>
+
+  <tal:checkbox define="widget nocall:view/widgets/checkbox">
+    <metal:widget-div use-macro="widget/@@launchpad_form/widget_div" />
+  </tal:checkbox>
+
+</div>

=== modified file 'lib/lp/app/browser/tests/test_launchpadform.py'
--- lib/lp/app/browser/tests/test_launchpadform.py	2011-04-04 19:52:15 +0000
+++ lib/lp/app/browser/tests/test_launchpadform.py	2011-12-16 12:38:26 +0000
@@ -5,14 +5,28 @@
 
 __metaclass__ = type
 
+from os.path import (
+    dirname,
+    join,
+    )
+
 from lxml import html
+from testtools.content import text_content
 from z3c.ptcompat import ViewPageTemplateFile
 from zope.interface import Interface
-from zope.schema import Text
+from zope.schema import (
+    Choice,
+    Text,
+    TextLine,
+    )
+from zope.schema.vocabulary import SimpleVocabulary
 
 from canonical.config import config
 from canonical.launchpad.webapp.servers import LaunchpadTestRequest
-from canonical.testing.layers import DatabaseFunctionalLayer
+from canonical.testing.layers import (
+    DatabaseFunctionalLayer,
+    FunctionalLayer,
+    )
 from lp.app.browser.launchpadform import (
     has_structured_doc,
     LaunchpadFormView,
@@ -42,7 +56,7 @@
 
 class TestHasStructuredDoc(TestCase):
 
-    layer = DatabaseFunctionalLayer
+    layer = FunctionalLayer
 
     def _widget_annotation(self, widget):
         return widget.context.queryTaggedValue('has_structured_doc')
@@ -59,7 +73,7 @@
 
 class TestQueryTalesForHasStructuredDoc(TestCase):
 
-    layer = DatabaseFunctionalLayer
+    layer = FunctionalLayer
 
     def test_query_tales(self):
         # Test that query:has-structured-doc gets sets the field annotation.
@@ -133,3 +147,54 @@
         self.assertEqual(
             u"http://widget.example.com/displayname";,
             displayname_help_link.get("href"))
+
+
+class TestWidgetDivInterface(Interface):
+    """Test interface for the view below."""
+
+    single_line = TextLine(title=u'single_line')
+    multi_line = Text(title=u'multi_line')
+    checkbox = Choice(
+        vocabulary=SimpleVocabulary.fromItems(
+            (('yes', True), ('no', False))))
+
+
+class TestWidgetDivView(LaunchpadFormView):
+    """A trivial view using `TestWidgetDivInterface`."""
+
+    schema = TestWidgetDivInterface
+    template = ViewPageTemplateFile(
+        join(dirname(__file__), "test-widget-div.pt"))
+
+
+class TestWidgetDiv(TestCase):
+    """Tests for the `widget_div` template macro."""
+
+    layer = FunctionalLayer
+
+    def test_all_widgets_present(self):
+        request = LaunchpadTestRequest()
+        view = TestWidgetDivView({}, request)
+        content = view()
+        self.addDetail("content", text_content(content))
+        root = html.fromstring(content)
+        # All the widgets appear in the page.
+        self.assertEqual(
+            ["field.single_line", "field.multi_line", "field.checkbox"],
+            root.xpath("//@id"))
+
+    def test_all_widgets_present_but_hidden(self):
+        request = LaunchpadTestRequest()
+        view = TestWidgetDivView({}, request)
+        view.initialize()
+        for widget in view.widgets:
+            widget.visible = False
+        content = view.render()
+        self.addDetail("content", text_content(content))
+        root = html.fromstring(content)
+        # All the widgets appear in the page as hidden inputs.
+        self.assertEqual(
+            ["field.single_line", "hidden",
+             "field.multi_line", "hidden",
+             "field.checkbox", "hidden"],
+            root.xpath("//input/@id | //input/@type"))

=== modified file 'lib/lp/app/templates/launchpad-form.pt'
--- lib/lp/app/templates/launchpad-form.pt	2011-04-04 19:49:39 +0000
+++ lib/lp/app/templates/launchpad-form.pt	2011-12-16 12:38:26 +0000
@@ -94,111 +94,117 @@
     </form>
   </div>
 
+  <metal:macro define-macro="widget_single_line">
+    <div tal:attributes="class widget_class">
+      <tal:label condition="display_label|widget/display_label|python:True">
+        <label tal:attributes="for widget/name"
+               tal:content="string:${widget/label}:">Label</label>
+        <span tal:condition="show_optional"
+              class="fieldRequired">(Optional)</span>
+      </tal:label>
+      <div>
+        <input tal:replace="structure widget" />
+        <tal:help-link condition="widget_help_link">
+          <a tal:attributes="href widget_help_link"
+             target="help" class="sprite maybe">
+            &nbsp;<span class="invisible-link">(?)</span>
+          </a>
+        </tal:help-link>
+      </div>
+      <div class="message" tal:condition="error"
+           tal:content="structure error">Error message</div>
+      <metal:help-hint use-macro="widget/@@launchpad_form/help_hint" />
+    </div>
+  </metal:macro>
+
+  <metal:macro define-macro="widget_multi_line">
+    <div tal:attributes="class widget_class">
+      <tal:label condition="display_label|widget/display_label|python:True">
+        <label
+            tal:attributes="for widget/name"
+            tal:content="string:${widget/label}:">Label:</label>
+        <span tal:condition="show_optional"
+              class="fieldRequired">(Optional)</span>
+      </tal:label>
+      <tal:help-link condition="widget_help_link">
+        <a tal:attributes="href widget_help_link"
+           target="help" class="sprite maybe">
+          &nbsp;<span class="invisible-link">(?)</span>
+        </a>
+      </tal:help-link>
+      <div tal:condition="error" tal:content="structure error"
+           class="message">Error message</div>
+      <div tal:content="structure widget">
+        <input type="text" />
+      </div>
+      <metal:help-hint use-macro="widget/@@launchpad_form/help_hint" />
+    </div>
+  </metal:macro>
+
+  <metal:macro define-macro="widget_checkbox">
+    <div tal:attributes="class widget_class">
+      <input type="checkbox" tal:replace="structure widget" />
+      <label tal:attributes="for widget/name"
+             tal:content="widget/label">Label</label>
+      <tal:help-link condition="widget_help_link">
+        <a tal:attributes="href widget_help_link"
+           target="help" class="sprite maybe">
+          &nbsp;<span class="invisible-link">(?)</span>
+        </a>
+      </tal:help-link>
+      <div tal:condition="error" tal:content="structure error"
+           class="message">Error message</div>
+      <metal:help-hint use-macro="widget/@@launchpad_form/help_hint" />
+    </div>
+  </metal:macro>
+
+  <metal:macro define-macro="widget_hidden">
+    <div tal:replace="structure widget/hidden" />
+  </metal:macro>
+
   <metal:macro define-macro="widget_rows">
     <table class="form" id="launchpad-form-widgets">
-      <tal:block define="widgets widgets|view/widgets"
-                 repeat="widget widgets">
-
-  <metal:macro define-macro="widget_row"
-      tal:define="field_name widget/context/__name__;
-                  error python:view.getFieldError(field_name);
-                  error_class python:error and 'error' or None;
-                  show_optional python:view.showOptionalMarker(field_name);
-                  widget_class widget/widget_class|nothing;
-                  widget_help_link widget_help_link|widget/help_link|nothing">
-    <tal:is-visible condition="widget/visible">
-      <tr
-        tal:condition="python: view.isSingleLineLayout(field_name)"
-        tal:attributes="class error_class"
-      >
-      <td colspan="2">
-      <div tal:attributes="class widget_class">
-        <tal:block tal:condition="display_label|widget/display_label|python:True">
-          <label tal:attributes="for widget/name"
-                 tal:content="string:${widget/label}:">Label</label>
-          <span tal:condition="show_optional"
-                class="fieldRequired">(Optional)</span>
-        </tal:block>
-          <div>
-            <input tal:replace="structure widget" />
-            <tal:help-link condition="widget_help_link">
-              <a tal:attributes="href widget_help_link"
-                 target="help" class="sprite maybe">
-                &nbsp;<span class="invisible-link">(?)</span>
-              </a>
-            </tal:help-link>
-          </div>
-          <div class="message" tal:condition="error"
-               tal:content="structure error">Error message</div>
-          <metal:help-hint use-macro="widget/@@launchpad_form/help_hint" />
-      </div>
-        </td>
-      </tr>
-      <tal:block condition="python: view.isMultiLineLayout(field_name)">
-        <tr tal:attributes="class error_class">
-          <td colspan="2" style="text-align: left">
-            <div tal:attributes="class widget_class">
-            <tal:showlabel
-              condition="display_label|widget/display_label|python:True"
-            >
-
-            <label
-              tal:attributes="for widget/name"
-              tal:content="string:${widget/label}:">Label:</label>
-            <span tal:condition="show_optional"
-                  class="fieldRequired">(Optional)</span>
-            </tal:showlabel>
-            <tal:help-link condition="widget_help_link">
-              <a tal:attributes="href widget_help_link"
-                 target="help" class="sprite maybe">
-                &nbsp;<span class="invisible-link">(?)</span>
-              </a>
-            </tal:help-link>
-            <div
-              tal:condition="error"
-              tal:content="structure error"
-              class="message"
-            >Error message</div>
-            <div tal:content="structure widget">
-              <input type="text" />
-            </div>
-            <metal:help-hint use-macro="widget/@@launchpad_form/help_hint" />
-            </div>
-          </td>
-        </tr>
-      </tal:block>
-      <tr tal:condition="python: view.isCheckBoxLayout(field_name)">
-        <td tal:attributes="class error_class" colspan="2">
-        <div tal:attributes="class widget_class">
-          <input type="checkbox" tal:replace="structure widget" />
-          <label tal:attributes="for widget/name"
-                 tal:content="widget/label">Label</label>
-          <tal:help-link condition="widget_help_link">
-            <a tal:attributes="href widget_help_link"
-               target="help" class="sprite maybe">
-              &nbsp;<span class="invisible-link">(?)</span>
-            </a>
-          </tal:help-link>
-          <div
-            tal:condition="error"
-            tal:content="structure error"
-            class="message"
-          >Error message</div>
-          <metal:help-hint use-macro="widget/@@launchpad_form/help_hint" />
-        </div>
-        </td>
-      </tr>
-    </tal:is-visible>
-    <tal:not-visible
-      condition="not: widget/visible">
-      <tr
-        tal:define="markup widget/hidden"
-        tal:condition="markup">
-        <td tal:content="structure markup" />
-      </tr>
-    </tal:not-visible>
-  </metal:macro>
-
+      <tal:block define="widgets widgets|view/widgets" repeat="widget widgets">
+        <metal:macro
+            define-macro="widget_row"
+            tal:define="field_name widget/context/__name__;
+                        error python:view.getFieldError(field_name);
+                        error_class python:'error' if error else None;
+                        show_optional python:view.showOptionalMarker(field_name);
+                        widget_class widget/widget_class|nothing;
+                        widget_help_link widget_help_link|widget/help_link|nothing">
+          <tal:is-visible condition="widget/visible">
+            <tr tal:condition="python: view.isSingleLineLayout(field_name)"
+                tal:attributes="class error_class">
+              <td colspan="2">
+                <metal:widget
+                    use-macro="widget/@@launchpad_form/widget_single_line" />
+              </td>
+            </tr>
+            <tal:block condition="python: view.isMultiLineLayout(field_name)">
+              <tr tal:attributes="class error_class">
+                <td colspan="2" style="text-align: left">
+                  <metal:widget
+                      use-macro="widget/@@launchpad_form/widget_multi_line" />
+                </td>
+              </tr>
+            </tal:block>
+            <tr tal:condition="python: view.isCheckBoxLayout(field_name)">
+              <td tal:attributes="class error_class" colspan="2">
+                <metal:widget
+                    use-macro="widget/@@launchpad_form/widget_checkbox" />
+              </td>
+            </tr>
+          </tal:is-visible>
+          <tal:not-visible condition="not: widget/visible">
+            <tr>
+              <td>
+                  <metal:widget
+                      use-macro="widget/@@launchpad_form/widget_hidden" />
+              </td>
+            </tr>
+          </tal:not-visible>
+        </metal:macro>
       </tal:block>
     </table>
   </metal:macro>
@@ -218,4 +224,31 @@
     </tal:widget-help>
   </metal:help-hint>
 
+  <metal:macro
+      define-macro="widget_div"
+      tal:define="field_name widget/context/__name__;
+                  error python:view.getFieldError(field_name);
+                  error_class python:'error' if error else None;
+                  show_optional python:view.showOptionalMarker(field_name);
+                  widget_class widget/widget_class|nothing;
+                  widget_help_link widget_help_link|widget/help_link|nothing">
+    <tal:is-visible condition="widget/visible">
+      <div tal:condition="python: view.isSingleLineLayout(field_name)"
+           tal:attributes="class error_class">
+        <metal:widget use-macro="widget/@@launchpad_form/widget_single_line" />
+      </div>
+      <div tal:condition="python: view.isMultiLineLayout(field_name)"
+           tal:attributes="class error_class">
+        <metal:widget use-macro="widget/@@launchpad_form/widget_multi_line" />
+      </div>
+      <div tal:condition="python: view.isCheckBoxLayout(field_name)"
+           tal:attributes="class error_class">
+        <metal:widget use-macro="widget/@@launchpad_form/widget_checkbox" />
+      </div>
+    </tal:is-visible>
+    <tal:not-visible condition="not: widget/visible">
+      <metal:widget use-macro="widget/@@launchpad_form/widget_hidden" />
+    </tal:not-visible>
+  </metal:macro>
+
 </div>