Skip to main content

megrok.z3cform.layout provides generic templates that can be used out-of-the-box with megrok.z3cform.base. These templates are totally independent from the megrok.z3cform.base library, meaning you can simply swap or override them.

Getting started

We import the base components to test our form layout:

>>> from megrok.z3cform.base import DisplayForm, EditForm, Fields
>>> from grokcore.component import context, implements
>>> from grokcore.component.testing import grok, grok_component

Let’s start with a simple example. We create a person object:

>>> from zope.interface import Interface, implements
>>> from zope.schema import TextLine

The Interface of our Object:

>>> class IPerson(Interface):
...   name = TextLine(title = u'Name')
...   age = TextLine(title = u'Age')

The class of our Object:

>>> class Person(object):
...   implements(IPerson)
...   name = u""
...   age = u""

And our instance:

>>> peter = Person()
>>> peter
<megrok.z3cform.base.ftests.Person object at ...>
>>> IPerson.providedBy(peter)
True

Rendering forms

For now, megrok.z3cform.layout provides only one template that works for all the different kinds of forms:

>>> class Edit(EditForm):
...   context(Interface)
...   fields = Fields(IPerson)

>>> grok_component('edit', Edit)
True

>>> from zope.component import getMultiAdapter
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()

>>> edit = getMultiAdapter((peter, request), name="edit")
>>> print edit()
<form action="http://127.0.0.1" method="post"
      enctype="multipart/form-data" class="form-edit">
  <div class="errors">
  </div>
  <p class="documentDescription"></p>
  <input type="hidden" name="camefrom" />
    <div id="edition-fields">
    <div class="field ">
      <label for="form-widgets-name">
        <span>Name</span>
        <span class="fieldRequired" title="Required">
          <span class="textual-info">(Required)</span>
        </span>
      </label>
      <div class="widget">
    <input id="form-widgets-name" name="form.widgets.name"
           class="text-widget required textline-field"
           value="" type="text" />
</div>
    </div>
    <div class="field ">
      <label for="form-widgets-age">
        <span>Age</span>
        <span class="fieldRequired" title="Required">
          <span class="textual-info">(Required)</span>
        </span>
      </label>
      <div class="widget">
    <input id="form-widgets-age" name="form.widgets.age"
           class="text-widget required textline-field"
           value="" type="text" />
</div>
    </div>
    </div>
    <div id="actionsView">
      <span class="actionButtons">
<input id="form-buttons-apply" name="form.buttons.apply"
       class="submit-widget button-field" value="Apply"
       type="submit" />
      </span>
    </div>
</form>

It works the same for a form with no actions:

>>> class Display(DisplayForm):
...   context(Interface)
...   fields = Fields(IPerson)

>>> grok_component('display', Display)
True

>>> view = getMultiAdapter((peter, request), name="display")
>>> print view()
<form action="http://127.0.0.1" method="post"
      enctype="multipart/form-data" class="form-display">
   <div class="errors">
   </div>
   <p class="documentDescription"></p>
   <input type="hidden" name="camefrom" />
     <div id="edition-fields">
       <div class="field ">
         <label for="form-widgets-name">
           <span>Name</span>
           <span class="fieldRequired" title="Required">
             <span class="textual-info">(Required)</span>
           </span>
         </label>
         <div class="widget">
           <span id="form-widgets-name"
                 class="text-widget required textline-field"></span>
         </div>
      </div>
      <div class="field ">
        <label for="form-widgets-age">
          <span>Age</span>
          <span class="fieldRequired" title="Required">
            <span class="textual-info">(Required)</span>
          </span>
        </label>
        <div class="widget">
          <span id="form-widgets-age"
                class="text-widget required textline-field"></span>
        </div>
      </div>
    </div>
 </form>

Changelog

0.2.1 (2009-12-03)

  • Fix : now errors render correctly inside the field.

0.2 (2009-12-03)

  • Updated template so it doesn’t show hidden fields’ label.

  • Added missing dependency.

0.1 (2009-11-02)

  • Initial release

Metadata

Release files for megrok.z3cform.layout 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for megrok.z3cform.layout 0.2.1
File Size Uploaded
megrok.z3cform.layout-0.2.1.tar.gz 6.6 kB Details

Release files / megrok.z3cform.layout-0.2.1.tar.gz

Download URL megrok.z3cform.layout-0.2.1.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
085f6b3c5af25cb1565ba86c6919360e20c67408959b6d0b0fb746439f7cb593
BLAKE2b-256 checksum
How to use checksums
f8876ded1e055c4d18da8587604641953e997a51968d7d53aa0c5d7a390ad5a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.1 This release

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page