[Checkins] SVN: Sandbox/dusty/z3c.formsnippet/trunk/ Initial import
of z3c.formsnippet written by Hermann Himmelbauer.
Daniel Nouri
daniel.nouri at gmail.com
Mon Jul 28 12:29:05 EDT 2008
Log message for revision 88875:
Initial import of z3c.formsnippet written by Hermann Himmelbauer.
This package is an addon to z3c.form, similar to z3c.formui which introduces
an alternate concept to customizing form templates by introducing so-called
"Form Frames" and "Widget Snippets".
Changed:
A Sandbox/dusty/z3c.formsnippet/trunk/
A Sandbox/dusty/z3c.formsnippet/trunk/CHANGES.txt
A Sandbox/dusty/z3c.formsnippet/trunk/LICENSE.txt
A Sandbox/dusty/z3c.formsnippet/trunk/README.txt
A Sandbox/dusty/z3c.formsnippet/trunk/bootstrap.py
A Sandbox/dusty/z3c.formsnippet/trunk/buildout.cfg
A Sandbox/dusty/z3c.formsnippet/trunk/setup.py
A Sandbox/dusty/z3c.formsnippet/trunk/src/
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/__init__.py
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/README.txt
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/SETUP.cfg
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/__init__.py
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/configure.zcml
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/i18n.py
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/interfaces.py
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/meta.zcml
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/errorstatus.pt
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/formframe.pt
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_div_display.pt
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_div_hidden.pt
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_div_input.pt
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_input_cb.pt
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_span_display.pt
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_span_hidden.pt
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_span_input.pt
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/testing.py
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/tests/
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/tests/__init__.py
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/tests/test_doc.py
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/z3c.formsnippet-configure.zcml
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/z3c.formsnippet-meta.zcml
A Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/zcml.py
-=-
Added: Sandbox/dusty/z3c.formsnippet/trunk/CHANGES.txt
===================================================================
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/CHANGES.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/LICENSE.txt
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/LICENSE.txt (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/LICENSE.txt 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,54 @@
+Zope Public License (ZPL) Version 2.1
+-------------------------------------
+
+A copyright notice accompanies this license document that
+identifies the copyright holders.
+
+This license has been certified as open source. It has also
+been designated as GPL compatible by the Free Software
+Foundation (FSF).
+
+Redistribution and use in source and binary forms, with or
+without modification, are permitted provided that the
+following conditions are met:
+
+1. Redistributions in source code must retain the
+ accompanying copyright notice, this list of conditions,
+ and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the accompanying
+ copyright notice, this list of conditions, and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+3. Names of the copyright holders must not be used to
+ endorse or promote products derived from this software
+ without prior written permission from the copyright
+ holders.
+
+4. The right to distribute this software or to use it for
+ any purpose does not give you the right to use
+ Servicemarks (sm) or Trademarks (tm) of the copyright
+ holders. Use of them is covered by separate agreement
+ with the copyright holders.
+
+5. If any files are modified, you must cause the modified
+ files to carry prominent notices stating that you changed
+ the files and the date of any change.
+
+Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS''
+ AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ NO EVENT SHALL THE COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ DAMAGE.
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/LICENSE.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/README.txt
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/README.txt (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/README.txt 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,3 @@
+This package is an addon to z3c.form, similar to z3c.formui which introduces
+an alternate concept to customizing form templates by introducing so-called
+"Form Frames" and "Widget Snippets".
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/bootstrap.py
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/bootstrap.py (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/bootstrap.py 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id: bootstrap.py 75940 2007-05-24 14:45:00Z srichter $
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+ cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+ os.P_WAIT, sys.executable, sys.executable,
+ '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/bootstrap.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/buildout.cfg
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/buildout.cfg (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/buildout.cfg 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,12 @@
+[buildout]
+develop = .
+parts = test coverage
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = z3c.formsnippet
+
+[coverage]
+recipe = zc.recipe.egg
+eggs = z3c.coverage
+
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/buildout.cfg
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/setup.py
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/setup.py (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/setup.py 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,18 @@
+from setuptools import setup, find_packages
+
+setup(
+ name="z3c.formsnippet",
+ version="0.1",
+ description="""\
+This package is an addon to z3c.form, similar to z3c.formui which introduces
+an alternate concept to customizing form templates by introducing so-called
+'Form Frames' and 'Widget Snippets'.
+""",
+
+ author="Hermann Himmelbauer",
+ author_email="dusty at qwer.tk",
+
+ packages=find_packages('src'),
+ package_dir={'':'src'},
+ namespace_packages=['z3c'],
+)
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/setup.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/__init__.py
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/__init__.py (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/__init__.py 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,6 @@
+try:
+ # Declare this a namespace package if pkg_resources is available.
+ import pkg_resources
+ pkg_resources.declare_namespace('z3c')
+except ImportError:
+ pass
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/README.txt
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/README.txt (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/README.txt 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,134 @@
+========
+Snippets
+========
+
+The idea of widget snippets is that often widgets will have some surrounding
+HTML code, perhaps a label, outlining what e.g. an input field is for, some
+code regarding error handling and perhaps some simple formatting.
+
+For instance, a widget may render as:
+
+<input type="text" value="" />
+
+But in the resulting HTML page, we need some surrounding code, e.g.
+
+<div>
+MyWidget: <input type="text" value="" />
+</div>
+
+Widget Snippets allow designers to create custom snippets and register them
+for certain widgets and display modes.
+
+First we have to register the meta configuration for the directive.
+
+ >>> import zope,sys
+ >>> from zope.configuration import xmlconfig
+ >>> import z3c.form
+ >>> context = xmlconfig.file('meta.zcml', z3c.form)
+ >>> from z3c.form import testing
+ >>> testing.setupFormDefaults()
+
+We need a custom snippet template
+
+ >>> import os, tempfile
+ >>> temp_dir = tempfile.mkdtemp()
+ >>> file = os.path.join(temp_dir, 'snippet_div_input.pt')
+ >>> open(file, 'w').write('''
+ ... <div tal:content="structure view/label">label</div>
+ ... <div tal:content="structure view/render">widget</div>
+ ... ''')
+
+Now we register it
+
+ >>> context = xmlconfig.string("""
+ ... <configure
+ ... xmlns:z3c="http://namespaces.zope.org/z3c">
+ ... <z3c:snippetTemplate
+ ... name="div"
+ ... mode="input"
+ ... template="%s"
+ ... />
+ ... </configure>
+ ... """ % file, context=context)
+
+And now we do that for a different snippet and register it under a
+different name
+
+ >>> file = os.path.join(temp_dir, 'snippet_span_input.pt')
+ >>> open(file, 'w').write('''
+ ... <div>
+ ... <span tal:replace="structure view/label" />:
+ ... <span tal:replace="structure view/render" />
+ ... </div>
+ ... ''')
+ >>> context = xmlconfig.string("""
+ ... <configure
+ ... xmlns:z3c="http://namespaces.zope.org/z3c">
+ ... <z3c:snippetTemplate
+ ... name="span"
+ ... mode="input"
+ ... template="%s"
+ ... />
+ ... </configure>
+ ... """ % file, context=context)
+
+Now we need a template for our form, which demonstrates the use
+of the different snippets.
+
+ >>> file = os.path.join(temp_dir, 'myform.pt')
+ >>> open(file, 'w').write('''
+ ... <span tal:replace="structure view/widgets/myname/snippets/div" />
+ ... <span tal:replace="structure view/widgets/myname/snippets/span" />
+ ... ''')
+
+We can see that the registered snippets are available under the widget
+and the object "snippets".
+
+We need some interface/class/browser view
+
+ >>> class IPerson(zope.interface.Interface):
+ ...
+ ... myname=zope.schema.TextLine(title=u'Persons Name')
+ >>> class Person(object):
+ ... zope.interface.implements(IPerson)
+ ... myname=''
+ ...
+ ... def __init__(self, myname):
+ ... self.myname = myname
+
+Now we create a form with our template, instantiate and update it
+(we use an AddForm as we have no context)
+
+ >>> from z3c.form import form, field
+ >>> from z3c.form.testing import TestRequest
+ >>> from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+ >>> class PersonForm(form.AddForm):
+ ...
+ ... fields = field.Fields(IPerson)
+ ... template = ViewPageTemplateFile('myform.pt', temp_dir)
+ ...
+ >>> request = TestRequest()
+ >>> personForm = PersonForm(None, request)
+ >>> personForm.update()
+
+And now we render the form
+
+ >>> print personForm.render()
+ <BLANKLINE>
+ <BLANKLINE>
+ <div>Persons Name</div>
+ <div><input type="text" id="form-widgets-myname"
+ name="form.widgets.myname"
+ class="textWidget textline-field" value="" />
+ </div>
+ <BLANKLINE>
+ <BLANKLINE>
+ <div>
+ Persons Name:
+ <input type="text" id="form-widgets-myname"
+ name="form.widgets.myname"
+ class="textWidget textline-field" value="" />
+ <BLANKLINE>
+ </div>
+ <BLANKLINE>
+ <BLANKLINE>
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/SETUP.cfg
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/SETUP.cfg (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/SETUP.cfg 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,3 @@
+<data-files zopeskel/etc/package-includes>
+ z3c.formsnippet-*.zcml
+</data-files>
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/SETUP.cfg
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/__init__.py
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/__init__.py (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/__init__.py 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,135 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Form Implementation
+
+$Id: form.py 77154 2007-06-27 19:29:23Z srichter $
+"""
+__docformat__ = "reStructuredText"
+import sys
+import zope.interface
+import zope.component
+import zope.location
+from zope.app.pagetemplate import ViewPageTemplateFile
+from zope.pagetemplate.interfaces import IPageTemplate
+from z3c.form import util
+from z3c.form.interfaces import IAfterWidgetUpdateEvent
+from z3c.template.interfaces import ILayoutTemplate
+
+from z3c.formsnippet import interfaces
+from z3c.formsnippet.i18n import MessageFactory as _
+
+
+class Formframe(object):
+ """A Mixin for Form Frames"""
+
+ frame = None
+ errorstatus = None #ViewPageTemplateFile('pt/errorstatus.pt')
+
+ def __call__(self):
+ self.update()
+ layout = zope.component.getMultiAdapter((self, self.request),
+ ILayoutTemplate)
+ return layout(self)
+
+ def render(self):
+ '''See interfaces.IForm'''
+ # render content template
+ # Make sure, the frame object has a template that can be called
+ # from the frame template
+
+ if self.template is None:
+ self.template = zope.component.getMultiAdapter(
+ (self, self.request), IPageTemplate)
+
+ if self.errorstatus is None:
+ self.errorstatus = zope.component.getMultiAdapter(
+ (self, self.request), interfaces.IErrorstatusTemplate)
+
+ if self.frame is None:
+ self.frame = zope.component.getMultiAdapter(
+ (self, self.request), interfaces.IFormframeTemplate)
+
+ return self.frame(self)
+
+class AddFormframe(Formframe):
+
+ def __call__(self):
+ self.update()
+ if self._finishedAdd:
+ self.request.response.redirect(self.nextURL())
+ return ''
+ layout = zope.component.getMultiAdapter((self, self.request),
+ ILayoutTemplate)
+ return layout(self)
+
+class Snippet(zope.location.Location):
+ """HTML snippets around a widget."""
+ zope.interface.implements(interfaces.ISnippets)
+
+ def __init__(self, view):
+ self.view = view
+
+ def __getattr__(self, name):
+ view = self.view
+ snippet = zope.component.getMultiAdapter(
+ (view.context, view.request, view.form, view.field, view),
+ IPageTemplate, name=name+'_'+view.mode)
+ return snippet(self.view)
+
+
+ at zope.component.adapter(IAfterWidgetUpdateEvent)
+def addWidgetsnippet(event):
+ """instantiates snippets"""
+ widget = event.widget
+ widget.snippets = Snippet(widget)
+
+class FormframeTemplateFactory(object):
+ """Formframe template factory."""
+
+ def __init__(self, filename, contentType='text/html'):
+ self.template = ViewPageTemplateFile(filename, content_type=contentType)
+ def __call__(self, view, request):
+ return self.template.__get__(view, None)
+
+
+class ErrorstatusTemplateFactory(object):
+ """Errorstatus template factory."""
+
+ def __init__(self, filename, contentType='text/html'):
+ self.template = ViewPageTemplateFile(filename, content_type=contentType)
+ def __call__(self, view, request):
+ # FIXME - Return a bound template - not very pretty, but
+ # I don't see another solution...
+ return self.template.__get__(view, None)
+
+
+class SnippetTemplateFactory(object):
+ """Snippet template factory."""
+
+ def __init__(self, filename, contentType='text/html',
+ context=None, request=None, view=None,
+ field=None, widget=None):
+ self.template = ViewPageTemplateFile(filename, content_type=contentType)
+ zope.component.adapter(
+ util.getSpecification(context),
+ util.getSpecification(request),
+ util.getSpecification(view),
+ util.getSpecification(field),
+ util.getSpecification(widget))(self)
+ zope.interface.implementer(IPageTemplate)(self)
+
+ def __call__(self, context, request, view, field, widget):
+ return self.template
+
+
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/configure.zcml
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/configure.zcml (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/configure.zcml 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,94 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:z3c="http://namespaces.zope.org/z3c"
+ i18n_domain="z3c.formsnippet">
+
+ <!-- Subscriber that adds snippets to widgets -->
+ <subscriber handler=".addWidgetsnippet" />
+
+ <!-- Default Frame and Snippets -->
+ <z3c:formframeTemplate
+ layer="z3c.form.interfaces.IFormLayer"
+ template="pt/formframe.pt"
+ />
+
+ <z3c:errorstatusTemplate
+ layer="z3c.form.interfaces.IFormLayer"
+ template="pt/errorstatus.pt"
+ />
+
+ <z3c:snippetTemplate
+ name="div"
+ mode="input"
+ layer="z3c.form.interfaces.IFormLayer"
+ template="pt/snippet_div_input.pt"
+ />
+
+ <z3c:snippetTemplate
+ name="div"
+ mode="input"
+ layer="z3c.form.interfaces.IFormLayer"
+ template="pt/snippet_input_cb.pt"
+ widget="z3c.form.interfaces.ICheckBoxWidget"
+ />
+
+ <z3c:snippetTemplate
+ name="span"
+ mode="input"
+ layer="z3c.form.interfaces.IFormLayer"
+ template="pt/snippet_span_input.pt"
+ />
+
+ <z3c:snippetTemplate
+ name="span"
+ mode="input"
+ layer="z3c.form.interfaces.IFormLayer"
+ template="pt/snippet_input_cb.pt"
+ widget="z3c.form.interfaces.ICheckBoxWidget"
+ />
+
+ <z3c:snippetTemplate
+ name="div"
+ mode="display"
+ layer="z3c.form.interfaces.IFormLayer"
+ template="pt/snippet_div_display.pt"
+ />
+
+ <z3c:snippetTemplate
+ name="span"
+ mode="display"
+ layer="z3c.form.interfaces.IFormLayer"
+ template="pt/snippet_span_display.pt"
+ />
+
+ <z3c:snippetTemplate
+ name="div"
+ mode="hidden"
+ layer="z3c.form.interfaces.IFormLayer"
+ template="pt/snippet_div_hidden.pt"
+ />
+
+ <z3c:snippetTemplate
+ name="span"
+ mode="hidden"
+ layer="z3c.form.interfaces.IFormLayer"
+ template="pt/snippet_span_hidden.pt"
+ />
+
+
+
+
+ <!-- APIDoc documentation -->
+ <configure
+ xmlns:zcml="http://namespaces.zope.org/zcml"
+ xmlns:apidoc="http://namespaces.zope.org/apidoc"
+ zcml:condition="have apidoc">
+
+ <apidoc:bookchapter
+ id="z3c-formsnippet"
+ title="z3c.formsnippet - Form Frames and Widget Snippets"
+ doc_path="README.txt"
+ />
+ </configure>
+
+</configure>
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/i18n.py
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/i18n.py (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/i18n.py 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,22 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""I18n message factory z3c.form
+
+$Id: i18n.py 77106 2007-06-26 17:23:09Z srichter $
+"""
+__docformat__ = "reStructuredText"
+
+import zope.i18nmessageid
+
+MessageFactory = zope.i18nmessageid.MessageFactory('z3c.formsnippet')
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/i18n.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/interfaces.py
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/interfaces.py (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/interfaces.py 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,38 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Form and Widget Framework Interfaces
+
+$Id: interfaces.py 77536 2007-07-06 21:13:41Z srichter $
+"""
+__docformat__ = "reStructuredText"
+
+import zope.interface
+import zope.schema
+from zope.interface.common import mapping
+from zope.location.interfaces import ILocation
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.pagetemplate.interfaces import IPageTemplate
+
+from z3c.form.i18n import MessageFactory as _
+
+
+class ISnippets(ILocation):
+ """HTML snippets around a widget"""
+
+class IErrorstatusTemplate(IPageTemplate):
+ """Marker interface for Errorstatus templates"""
+
+class IFormframeTemplate(IPageTemplate):
+ """Marker interface for formframe templates"""
+
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/interfaces.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/meta.zcml
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/meta.zcml (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/meta.zcml 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,29 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:meta="http://namespaces.zope.org/meta">
+
+ <meta:directives namespace="http://namespaces.zope.org/z3c">
+
+ <meta:directive
+ name="snippetTemplate"
+ schema=".zcml.ISnippetTemplateDirective"
+ handler=".zcml.snippetTemplateDirective"
+ />
+
+ <meta:directive
+ name="formframeTemplate"
+ schema=".zcml.IFormframeTemplateDirective"
+ handler=".zcml.formframeTemplateDirective"
+ />
+
+ <meta:directive
+ name="errorstatusTemplate"
+ schema=".zcml.IErrorstatusTemplateDirective"
+ handler=".zcml.errorstatusTemplateDirective"
+ />
+
+
+ </meta:directives>
+
+</configure>
+
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/meta.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/errorstatus.pt
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/errorstatus.pt (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/errorstatus.pt 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,14 @@
+<div tal:content="view/status" />
+<div class="status"
+ tal:condition="view/widgets/errors">
+<ul class="errors"
+ tal:condition="view/widgets/errors">
+ <li tal:repeat="error view/widgets/errors">
+ <tal:block condition="error/widget">
+ <span tal:replace="error/widget/label" />:
+ </tal:block>
+ <span tal:replace="structure error/render">Error Type</span>
+ </li>
+</ul>
+</div>
+
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/errorstatus.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/formframe.pt
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/formframe.pt (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/formframe.pt 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,22 @@
+<form action="." method="post" enctype="multipart/form-data" class="edit-form"
+ metal:define-macro="form"
+ tal:attributes="method view/method;
+ enctype view/enctype;
+ acceptCharset view/acceptCharset;
+ accept view/accept;
+ action view/action;
+ name view/name;
+ id view/id">
+
+<span tal:replace="structure view/errorstatus" />
+
+<span tal:replace="structure view/template" />
+
+<p />
+<div class="buttons">
+ <input tal:repeat="action view/actions/values"
+ tal:replace="structure action/render"
+ />
+</div>
+</form>
+
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/formframe.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_div_display.pt
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_div_display.pt (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_div_display.pt 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,2 @@
+<div tal:content="structure view/label">widget label</div>
+<div tal:content="structure view/render">widget</div>
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_div_display.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_div_hidden.pt
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_div_hidden.pt (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_div_hidden.pt 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,3 @@
+<div class="widget" tal:content="structure view/render">
+ <input type="text"/>
+</div>
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_div_hidden.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_div_input.pt
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_div_input.pt (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_div_input.pt 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,12 @@
+<div class="label">
+ <label tal:attributes="for view/id">
+ <span i18n:translate="" tal:content="view/label">label</span>
+ <span class="required" tal:condition="view/required">*</span>
+ </label>
+</div>
+<div class="widget" tal:content="structure view/render">
+ <input type="text"/>
+</div>
+<div class="error" tal:condition="view/error">
+ <span tal:replace="structure view/error/render">error</span>
+</div>
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_div_input.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_input_cb.pt
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_input_cb.pt (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_input_cb.pt 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,6 @@
+<div class="widget" tal:content="structure view/render">
+ <input type="text"/>
+</div>
+<div class="error" tal:condition="view/error">
+ <span tal:replace="structure view/error/render">error</span>
+</div>
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_input_cb.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_span_display.pt
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_span_display.pt (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_span_display.pt 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,4 @@
+<div>
+<span tal:replace="structure view/label" />:
+<span tal:replace="structure view/render" />
+</div>
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_span_display.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_span_hidden.pt
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_span_hidden.pt (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_span_hidden.pt 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,3 @@
+<span class="widget" tal:content="structure view/render">
+ <input type="text"/>
+</span>
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_span_hidden.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_span_input.pt
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_span_input.pt (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_span_input.pt 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,12 @@
+<span class="label">
+ <label tal:attributes="for view/id">
+ <span i18n:translate="" tal:content="view/label">label</span>
+ <span class="required" tal:condition="view/required">*</span>
+ </label>
+</span>
+<span class="widget" tal:content="structure view/render">
+ <input type="text"/>
+</span>
+<span class="error" tal:condition="view/error">
+ <span tal:replace="structure view/error/render">error</span>
+</span>
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/pt/snippet_span_input.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/testing.py
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/testing.py (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/testing.py 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,151 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Common z3c.form test setups
+
+$Id: testing.py 77519 2007-07-06 15:11:10Z srichter $
+"""
+__docformat__ = 'restructuredtext'
+import os
+import zope.component
+import zope.interface
+import zope.schema
+from zope.pagetemplate.interfaces import IPageTemplate
+from zope.publisher.browser import TestRequest
+from zope.security.interfaces import IInteraction
+from zope.security.interfaces import ISecurityPolicy
+from zope.security import checker
+from zope.app.testing import setup
+
+from z3c.form import browser, button, converter, datamanager, error, field
+from z3c.form import interfaces, term, validator, widget
+from z3c.form.browser import radio, select, text
+
+
+class TestRequest(TestRequest):
+ zope.interface.implements(interfaces.IFormLayer)
+
+class SimpleSecurityPolicy(object):
+ """Allow all access."""
+ zope.interface.implements(IInteraction)
+ zope.interface.classProvides(ISecurityPolicy)
+
+ loggedIn = False
+ allowedPermissions = ()
+
+ def __init__(self, loggedIn=False, allowedPermissions=()):
+ self.loggedIn = loggedIn
+ self.allowedPermissions = allowedPermissions
+
+ def __call__(self, *participations):
+ self.participations = []
+ return self
+
+ def add(self, participation):
+ pass
+
+ def remove(self, participation):
+ pass
+
+ def checkPermission(self, permission, object):
+ if permission is checker.CheckerPublic:
+ return True
+ if self.loggedIn:
+ if permission in self.allowedPermissions:
+ return True
+ return False
+
+
+def getPath(filename):
+ return os.path.join(os.path.dirname(browser.__file__), filename)
+
+def setUp(test):
+ test.globs = {'root': setup.placefulSetUp(True)}
+
+
+def setupFormDefaults():
+ # Validator adapters
+ zope.component.provideAdapter(validator.SimpleFieldValidator)
+ zope.component.provideAdapter(validator.InvariantsValidator)
+ # Data manager adapter to get and set values to content
+ zope.component.provideAdapter(datamanager.AttributeField)
+ # Adapter to use form.fields to generate widgets
+ zope.component.provideAdapter(field.FieldWidgets)
+ # Adapters to lookup the widget for a field
+ # Text Field Widget
+ zope.component.provideAdapter(
+ text.TextFieldWidget,
+ adapts=(zope.schema.interfaces.ITextLine, interfaces.IFormLayer))
+ zope.component.provideAdapter(
+ text.TextFieldWidget,
+ adapts=(zope.schema.interfaces.IInt, interfaces.IFormLayer))
+ zope.component.provideAdapter(
+ widget.WidgetTemplateFactory(getPath('text_input.pt'), 'text/html'),
+ (None, None, None, None, interfaces.ITextWidget),
+ IPageTemplate, name=interfaces.INPUT_MODE)
+ zope.component.provideAdapter(
+ widget.WidgetTemplateFactory(getPath('text_display.pt'), 'text/html'),
+ (None, None, None, None, interfaces.ITextWidget),
+ IPageTemplate, name=interfaces.DISPLAY_MODE)
+ zope.component.provideAdapter(
+ widget.WidgetTemplateFactory(getPath('text_hidden.pt'), 'text/html'),
+ (None, None, None, None, interfaces.ITextWidget),
+ IPageTemplate, name=interfaces.HIDDEN_MODE)
+ # Radio Field Widget
+ zope.component.provideAdapter(radio.RadioFieldWidget)
+ zope.component.provideAdapter(
+ widget.WidgetTemplateFactory(getPath('radio_input.pt'), 'text/html'),
+ (None, None, None, None, interfaces.IRadioWidget),
+ IPageTemplate, name=interfaces.INPUT_MODE)
+ zope.component.provideAdapter(
+ widget.WidgetTemplateFactory(getPath('radio_display.pt'), 'text/html'),
+ (None, None, None, None, interfaces.IRadioWidget),
+ IPageTemplate, name=interfaces.DISPLAY_MODE)
+ # Select Field Widget
+ zope.component.provideAdapter(select.SelectFieldWidget)
+ zope.component.provideAdapter(
+ widget.WidgetTemplateFactory(getPath('select_input.pt'), 'text/html'),
+ (None, None, None, None, interfaces.ISelectWidget),
+ IPageTemplate, name=interfaces.INPUT_MODE)
+ zope.component.provideAdapter(
+ widget.WidgetTemplateFactory(getPath('select_display.pt'), 'text/html'),
+ (None, None, None, None, interfaces.ISelectWidget),
+ IPageTemplate, name=interfaces.DISPLAY_MODE)
+ # Submit Field Widget
+ zope.component.provideAdapter(
+ widget.WidgetTemplateFactory(getPath('submit_input.pt'), 'text/html'),
+ (None, None, None, None, interfaces.ISubmitWidget),
+ IPageTemplate, name=interfaces.INPUT_MODE)
+ # selectwidget helper adapters
+ zope.component.provideAdapter(select.CollectionSelectFieldWidget)
+ zope.component.provideAdapter(select.CollectionChoiceSelectFieldWidget)
+ # Adapter to convert between field/internal and widget values
+ zope.component.provideAdapter(converter.FieldDataConverter)
+ zope.component.provideAdapter(converter.SequenceDataConverter)
+ zope.component.provideAdapter(converter.FieldWidgetDataConverter)
+ # Adapter for providing terms to radio list and other widgets
+ zope.component.provideAdapter(term.ChoiceTerms)
+ zope.component.provideAdapter(term.BoolTerms)
+ # Adapter to create an action from a button
+ zope.component.provideAdapter(
+ button.ButtonAction, provides=interfaces.IButtonAction)
+ # Adapter to use form.buttons to generate actions
+ zope.component.provideAdapter(button.ButtonActions)
+ # Adapter to use form.handlers to generate handle actions
+ zope.component.provideAdapter(button.ButtonActionHandler)
+ # Error View(s)
+ zope.component.provideAdapter(error.ErrorViewSnippet)
+ zope.component.provideAdapter(error.StandardErrorViewTemplate)
+
+def tearDown(test):
+ setup.placefulTearDown()
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/testing.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/tests/__init__.py
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/tests/__init__.py (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/tests/__init__.py 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1 @@
+# Make a package.
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/tests/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/tests/test_doc.py
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/tests/test_doc.py (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/tests/test_doc.py 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,33 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""z3c.form Test Module
+
+$Id: test_doc.py 77114 2007-06-26 22:35:05Z srichter $
+"""
+__docformat__ = "reStructuredText"
+import unittest
+from zope.testing import doctest
+from zope.app.testing import placelesssetup
+
+from z3c.form import testing
+
+def test_suite():
+ return unittest.TestSuite((
+ doctest.DocFileSuite(
+ '../README.txt',
+ setUp=testing.setUp, tearDown=testing.tearDown,
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS|\
+ doctest.REPORT_ONLY_FIRST_FAILURE
+ ),
+ ))
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/tests/test_doc.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/z3c.formsnippet-configure.zcml
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/z3c.formsnippet-configure.zcml (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/z3c.formsnippet-configure.zcml 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1 @@
+<include package="z3c.formsnippet" />
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/z3c.formsnippet-configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/z3c.formsnippet-meta.zcml
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/z3c.formsnippet-meta.zcml (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/z3c.formsnippet-meta.zcml 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,6 @@
+<configure
+ xmlns:zcml="http://namespaces.zope.org/zcml">
+
+ <include package="z3c.formsnippet" file="meta.zcml" />
+
+</configure>
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/z3c.formsnippet-meta.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/zcml.py
===================================================================
--- Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/zcml.py (rev 0)
+++ Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/zcml.py 2008-07-28 16:29:05 UTC (rev 88875)
@@ -0,0 +1,200 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id: zcml.py 75940 2007-05-24 14:45:00Z srichter $
+"""
+__docformat__ = "reStructuredText"
+
+import os
+
+import zope.interface
+import zope.component.zcml
+import zope.schema
+import zope.configuration.fields
+from zope.configuration.exceptions import ConfigurationError
+from zope.pagetemplate.interfaces import IPageTemplate
+from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+
+from z3c.form import interfaces
+from z3c.form.i18n import MessageFactory as _
+from z3c.formsnippet import FormframeTemplateFactory, SnippetTemplateFactory
+from z3c.formsnippet import ErrorstatusTemplateFactory
+from z3c.formsnippet.interfaces import IFormframeTemplate, IErrorstatusTemplate
+
+
+class IFormframeTemplateDirective(zope.interface.Interface):
+ """Parameters for the Formframe template directive."""
+
+ template = zope.configuration.fields.Path(
+ title=_('Form frame template.'),
+ description=_('Refers to a file containing a page template (should '
+ 'end in extension ``.pt`` or ``.html``).'),
+ required=True)
+
+ for_ = zope.configuration.fields.GlobalObject(
+ title=_('View'),
+ description=_('The view for which the template should be available'),
+ default=zope.interface.Interface,
+ required = False)
+
+ layer = zope.configuration.fields.GlobalObject(
+ title=_('Layer'),
+ description=_('The layer for which the template should be available'),
+ default=IDefaultBrowserLayer,
+ required=False)
+
+ contentType = zope.schema.BytesLine(
+ title=_('Content Type'),
+ description=_('The content type identifies the type of data.'),
+ default='text/html',
+ required=False)
+
+def formframeTemplateDirective(
+ _context, template, for_=zope.interface.Interface,
+ layer=IDefaultBrowserLayer, contentType='text/html'):
+
+ # Make sure that the template exists
+ template = os.path.abspath(str(_context.path(template)))
+ if not os.path.isfile(template):
+ raise ConfigurationError("No such file", template)
+
+ factory = FormframeTemplateFactory(template, contentType)
+ zope.interface.directlyProvides(factory, IFormframeTemplate)
+
+ # register the template
+ zope.component.zcml.adapter(_context, (factory,), IFormframeTemplate,
+ (for_, layer))
+
+
+class IErrorstatusTemplateDirective(zope.interface.Interface):
+ """Parameters for the Formframe template directive."""
+
+ template = zope.configuration.fields.Path(
+ title=_('Errorstatus template.'),
+ description=_('Refers to a file containing a page template (should '
+ 'end in extension ``.pt`` or ``.html``).'),
+ required=True)
+
+ for_ = zope.configuration.fields.GlobalObject(
+ title=_('View'),
+ description=_('The view for which the template should be available'),
+ default=zope.interface.Interface,
+ required = False)
+
+ layer = zope.configuration.fields.GlobalObject(
+ title=_('Layer'),
+ description=_('The layer for which the template should be available'),
+ default=IDefaultBrowserLayer,
+ required=False)
+
+ contentType = zope.schema.BytesLine(
+ title=_('Content Type'),
+ description=_('The content type identifies the type of data.'),
+ default='text/html',
+ required=False)
+
+def errorstatusTemplateDirective(
+ _context, template, for_=zope.interface.Interface,
+ layer=IDefaultBrowserLayer, contentType='text/html'):
+
+ # Make sure that the template exists
+ template = os.path.abspath(str(_context.path(template)))
+ if not os.path.isfile(template):
+ raise ConfigurationError("No such file", template)
+
+ factory = ErrorstatusTemplateFactory(template, contentType)
+ zope.interface.directlyProvides(factory, IErrorstatusTemplate)
+
+ # register the template
+ zope.component.zcml.adapter(_context, (factory,), IErrorstatusTemplate,
+ (for_, layer))
+
+
+
+class ISnippetTemplateDirective(zope.interface.Interface):
+ """Parameters for the snippet template directive."""
+
+ template = zope.configuration.fields.Path(
+ title=_('Layout template.'),
+ description=_('Refers to a file containing a page template (should '
+ 'end in extension ``.pt`` or ``.html``).'),
+ required=True)
+
+ name = zope.schema.BytesLine(
+ title=_('The name of the snippet'),
+ description=_('The snippet name that can be used in page templates'),
+ required=True)
+
+ mode = zope.schema.BytesLine(
+ title=_('The mode of the template.'),
+ description=_('The mode is used for define input and display '
+ 'templates'),
+ default=interfaces.INPUT_MODE,
+ required=False)
+
+ for_ = zope.configuration.fields.GlobalObject(
+ title=_('View'),
+ description=_('The view for which the template should be available'),
+ default=zope.interface.Interface,
+ required = False)
+
+ layer = zope.configuration.fields.GlobalObject(
+ title=_('Layer'),
+ description=_('The layer for which the template should be available'),
+ default=IDefaultBrowserLayer,
+ required=False)
+
+ view = zope.configuration.fields.GlobalObject(
+ title=_('View'),
+ description=_('The view for which the template should be available'),
+ default=zope.interface.Interface,
+ required=False)
+
+ field = zope.configuration.fields.GlobalObject(
+ title=_('Field'),
+ description=_('The field for which the template should be available'),
+ default=zope.schema.interfaces.IField,
+ required=False)
+
+ widget = zope.configuration.fields.GlobalObject(
+ title=_('View'),
+ description=_('The widget for which the template should be available'),
+ default=interfaces.IWidget,
+ required=False)
+
+ contentType = zope.schema.BytesLine(
+ title=_('Content Type'),
+ description=_('The content type identifies the type of data.'),
+ default='text/html',
+ required=False)
+
+def snippetTemplateDirective(
+ _context, template, for_=zope.interface.Interface,
+ layer=IDefaultBrowserLayer, view=None, field=None, widget=None,
+ name='', mode=interfaces.INPUT_MODE, contentType='text/html'):
+
+ # Make sure that the template exists
+ template = os.path.abspath(str(_context.path(template)))
+ if not os.path.isfile(template):
+ raise ConfigurationError("No such file", template)
+
+ factory = SnippetTemplateFactory(template, contentType)
+ zope.interface.directlyProvides(factory, IPageTemplate)
+
+ # register the template
+ zope.component.zcml.adapter(_context, (factory,), IPageTemplate,
+ (for_, layer, view, field, widget), name=name+'_'+mode)
+
+
+
Property changes on: Sandbox/dusty/z3c.formsnippet/trunk/src/z3c/formsnippet/zcml.py
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Checkins
mailing list