[Checkins] SVN: Sandbox/darrylcousins/mars.form/ Building mars.form
package
Darryl Cousins
darryl at darrylcousins.net.nz
Fri Jul 20 20:12:18 EDT 2007
Log message for revision 78230:
Building mars.form package
Changed:
A Sandbox/darrylcousins/mars.form/AUTHOR.txt
A Sandbox/darrylcousins/mars.form/CHANGES.txt
A Sandbox/darrylcousins/mars.form/LICENSE.txt
A Sandbox/darrylcousins/mars.form/README.txt
A Sandbox/darrylcousins/mars.form/buildout.cfg
A Sandbox/darrylcousins/mars.form/setup.py
A Sandbox/darrylcousins/mars.form/src/mars/form/README.txt
A Sandbox/darrylcousins/mars.form/src/mars/form/__init__.py
A Sandbox/darrylcousins/mars.form/src/mars/form/components.py
A Sandbox/darrylcousins/mars.form/src/mars/form/directive.py
A Sandbox/darrylcousins/mars.form/src/mars/form/directive.txt
U Sandbox/darrylcousins/mars.form/src/mars/form/form.txt
A Sandbox/darrylcousins/mars.form/src/mars/form/interfaces.py
A Sandbox/darrylcousins/mars.form/src/mars/form/meta.py
A Sandbox/darrylcousins/mars.form/src/mars/form/meta.zcml
A Sandbox/darrylcousins/mars.form/src/mars/form/tests.py
-=-
Added: Sandbox/darrylcousins/mars.form/AUTHOR.txt
===================================================================
--- Sandbox/darrylcousins/mars.form/AUTHOR.txt (rev 0)
+++ Sandbox/darrylcousins/mars.form/AUTHOR.txt 2007-07-21 00:12:17 UTC (rev 78230)
@@ -0,0 +1 @@
+Darryl Cousins (darryl.cousins <at> tfws.org.nz)
Property changes on: Sandbox/darrylcousins/mars.form/AUTHOR.txt
___________________________________________________________________
Name: svn:keywords
+ Date Author
Added: Sandbox/darrylcousins/mars.form/CHANGES.txt
===================================================================
--- Sandbox/darrylcousins/mars.form/CHANGES.txt (rev 0)
+++ Sandbox/darrylcousins/mars.form/CHANGES.txt 2007-07-21 00:12:17 UTC (rev 78230)
@@ -0,0 +1,8 @@
+=======
+CHANGES
+=======
+
+Version 0.1 (7/21/2007)
+-------------------------
+
+- Initial Release
Property changes on: Sandbox/darrylcousins/mars.form/CHANGES.txt
___________________________________________________________________
Name: svn:keywords
+ Date Author
Added: Sandbox/darrylcousins/mars.form/LICENSE.txt
===================================================================
--- Sandbox/darrylcousins/mars.form/LICENSE.txt (rev 0)
+++ Sandbox/darrylcousins/mars.form/LICENSE.txt 2007-07-21 00:12:17 UTC (rev 78230)
@@ -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/darrylcousins/mars.form/LICENSE.txt
___________________________________________________________________
Name: svn:keywords
+ Date Author
Added: Sandbox/darrylcousins/mars.form/README.txt
===================================================================
--- Sandbox/darrylcousins/mars.form/README.txt (rev 0)
+++ Sandbox/darrylcousins/mars.form/README.txt 2007-07-21 00:12:17 UTC (rev 78230)
@@ -0,0 +1,30 @@
+=========
+Mars Form
+=========
+
+Introduction
+------------
+
+`Grok`_ is a project which seeks to provide convention over configuration.
+
+``Martian`` grew from `Grok`_:
+
+ Martian provides a framework that allows configuration to be expressed
+ in declarative Python code. These declarations can often be deduced
+ from the structure of the code itself. The idea is to make these
+ declarations so minimal and easy to read that even extensive
+ configuration does not overly burden the programmers working with the
+ code. Configuration actions are executed during a separate phase
+ ("grok time"), not at import time, which makes it easier to reason
+ about and easier to test.
+
+ The ``martian`` package is a spin-off from the `Grok`_ project, in the
+ context of which this codebase was first developed. While Grok uses
+ it, the code is completely independent of Grok.
+
+.. _Grok: http://grok.zope.org/
+
+Mars Form
+---------
+
+The mars.form package provides registrations for using z3c.form.
Property changes on: Sandbox/darrylcousins/mars.form/README.txt
___________________________________________________________________
Name: svn:keywords
+ Date Author
Added: Sandbox/darrylcousins/mars.form/buildout.cfg
===================================================================
--- Sandbox/darrylcousins/mars.form/buildout.cfg (rev 0)
+++ Sandbox/darrylcousins/mars.form/buildout.cfg 2007-07-21 00:12:17 UTC (rev 78230)
@@ -0,0 +1,14 @@
+[buildout]
+develop = .
+parts = test
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = mars.form [test]
+defaults = ['--tests-pattern', '^f?tests$',
+ '-v'
+ ]
+
+[zope3]
+location = .
+
Added: Sandbox/darrylcousins/mars.form/setup.py
===================================================================
--- Sandbox/darrylcousins/mars.form/setup.py (rev 0)
+++ Sandbox/darrylcousins/mars.form/setup.py 2007-07-21 00:12:17 UTC (rev 78230)
@@ -0,0 +1,38 @@
+import os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+ return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+setup(
+ name='mars.form',
+ version='0.1',
+ author='Darryl Cousins',
+ author_email='darryl.cousins at tfws.org.nz',
+ url='http://www.tfws.org.nz/mars',
+ description="""\
+This package uses ``martian`` and ``grok`` to provide registrations using z3c.form
+for applications built on the ``zope`` framework.""",
+ long_description=(
+ read('src/mars/form/README.txt')
+ ),
+ packages=find_packages('src'),
+ package_dir = {'': 'src'},
+ include_package_data = True,
+ namespace_packages = ['mars'],
+ zip_safe=False,
+ license='ZPL',
+ dependency_links = ['http://download.zope.org/distribution'],
+ extras_require = dict(
+ test=['zope.app.testing',
+ 'zope.testbrowser',
+ ]
+ ),
+ install_requires = [
+ 'setuptools',
+ 'grok',
+ 'z3c.form',
+ 'z3c.formui',
+ 'z3c.layer',
+ ],
+)
Property changes on: Sandbox/darrylcousins/mars.form/setup.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: Sandbox/darrylcousins/mars.form/src/mars/form/README.txt
===================================================================
--- Sandbox/darrylcousins/mars.form/src/mars/form/README.txt (rev 0)
+++ Sandbox/darrylcousins/mars.form/src/mars/form/README.txt 2007-07-21 00:12:17 UTC (rev 78230)
@@ -0,0 +1,16 @@
+=========
+Mars Form
+=========
+
+Layers
+------
+
+* mars.form.IFormLayer
+ Uses z3c.form.IFormLayer, z3c.layer.IPageletBrowserLayer
+
+* mars.form.IDivFormLayer
+ Uses z3c.formui.IDivFormLayer, z3c.form.IFormLayer, z3c.layer.IPageletBrowserLayer
+
+* mars.form.ITableFormLayer
+ Uses z3c.formui.ITableFormLayer, z3c.form.IFormLayer, z3c.layer.IPageletBrowserLayer
+
Property changes on: Sandbox/darrylcousins/mars.form/src/mars/form/README.txt
___________________________________________________________________
Name: svn:keywords
+ Date Author
Added: Sandbox/darrylcousins/mars.form/src/mars/form/__init__.py
===================================================================
--- Sandbox/darrylcousins/mars.form/src/mars/form/__init__.py (rev 0)
+++ Sandbox/darrylcousins/mars.form/src/mars/form/__init__.py 2007-07-21 00:12:17 UTC (rev 78230)
@@ -0,0 +1,6 @@
+from directive import mode, view, field, widget
+from components import (IFormLayer,
+ IDivFormLayer,
+ ITableFormLayer,
+ FormView,
+ WidgetTemplateFactory)
Property changes on: Sandbox/darrylcousins/mars.form/src/mars/form/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: Sandbox/darrylcousins/mars.form/src/mars/form/components.py
===================================================================
--- Sandbox/darrylcousins/mars.form/src/mars/form/components.py (rev 0)
+++ Sandbox/darrylcousins/mars.form/src/mars/form/components.py 2007-07-21 00:12:17 UTC (rev 78230)
@@ -0,0 +1,20 @@
+from z3c.pagelet.interfaces import IPagelet
+from z3c.form.interfaces import IFormLayer as IZ3CFormLayer
+from z3c.formui.interfaces import IDivFormLayer as IZ3CDivFormLayer
+from z3c.formui.interfaces import ITableFormLayer as IZ3CTableFormLayer
+
+from mars.layer import ILayer
+
+class IFormLayer(ILayer, IZ3CFormLayer, IPageletBrowserLayer):
+ pass
+
+class IDivFormLayer(ILayer, IZ3CDivFormLayer, IZ3CFormLayer, IPageletBrowserLayer):
+ pass
+
+class ITableFormLayer(ILayer, IZ3CTableFormLayer, IZ3CFormLayer, IPageletBrowserLayer):
+ pass
+
+
+class FormView(object):
+ """Vanilla view to mixin with z3c.form views"""
+ zope.interface.implements(IPagelet)
Property changes on: Sandbox/darrylcousins/mars.form/src/mars/form/components.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: Sandbox/darrylcousins/mars.form/src/mars/form/directive.py
===================================================================
--- Sandbox/darrylcousins/mars.form/src/mars/form/directive.py (rev 0)
+++ Sandbox/darrylcousins/mars.form/src/mars/form/directive.py 2007-07-21 00:12:17 UTC (rev 78230)
@@ -0,0 +1,13 @@
+from martian.directive import (InterfaceOrClassDirective,
+ SingleTextDirective,
+ ClassDirectiveContext)
+
+mode = SingleTextDirective('mars.form.mode',
+ ClassDirectiveContext())
+view = InterfaceOrClassDirective('mars.form.view',
+ ClassDirectiveContext())
+field = InterfaceOrClassDirective('mars.form.field',
+ ClassDirectiveContext())
+widget = InterfaceOrClassDirective('mars.form.widget',
+ ClassDirectiveContext())
+
Property changes on: Sandbox/darrylcousins/mars.form/src/mars/form/directive.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: Sandbox/darrylcousins/mars.form/src/mars/form/directive.txt
===================================================================
--- Sandbox/darrylcousins/mars.form/src/mars/form/directive.txt (rev 0)
+++ Sandbox/darrylcousins/mars.form/src/mars/form/directive.txt 2007-07-21 00:12:17 UTC (rev 78230)
@@ -0,0 +1,4 @@
+========================
+Mars Form Directives
+========================
+
Property changes on: Sandbox/darrylcousins/mars.form/src/mars/form/directive.txt
___________________________________________________________________
Name: svn:keywords
+ Date Author
Modified: Sandbox/darrylcousins/mars.form/src/mars/form/form.txt
===================================================================
--- Sandbox/darrylcousins/mars.form/src/mars/form/form.txt 2007-07-20 23:34:34 UTC (rev 78229)
+++ Sandbox/darrylcousins/mars.form/src/mars/form/form.txt 2007-07-21 00:12:17 UTC (rev 78230)
@@ -2,8 +2,31 @@
Mars Form
=========
-``mars.form`` includes a FormView object and widget template implementation.
+``mars.form`` includes a FormView object, widget template implementation and
+layers derived from z3c.formui.
+Set up
+------
+
+First some imports.
+
+ >>> import zope.component
+ >>> import zope.interface
+ >>> from zope.pagetemplate.interfaces import IPageTemplate
+ >>> import mars.template
+ >>> import grok
+ >>> import os, tempfile
+ >>> temp_dir = tempfile.mkdtemp()
+ >>> from z3c.form import form, field
+ >>> from z3c.formui import layout
+ >>> from zope.traversing.browser import absoluteURL
+
+And we'll access and set up the z3c.form package defaults.
+
+ >>> from z3c.form import testing
+ >>> testing.setupFormDefaults()
+
+
Form View
---------
@@ -25,17 +48,6 @@
... text = None
>>> document = Document()
-Some form imports
-
- >>> from z3c.form import form, field
- >>> from z3c.formui import layout
- >>> from zope.traversing.browser import absoluteURL
-
-And we'll simply access and set up the z3c.form package defaults.
-
- >>> from z3c.form import testing
- >>> testing.setupFormDefaults()
-
Now create and grok an add form.
>>> class Add(mars.view.FormView, layout.AddFormLayoutSupport, form.AddForm):
@@ -94,3 +106,9 @@
>>> print view()
+Cleanup
+-------
+
+ >>> import shutil
+ >>> shutil.rmtree(temp_dir)
+
Added: Sandbox/darrylcousins/mars.form/src/mars/form/interfaces.py
===================================================================
--- Sandbox/darrylcousins/mars.form/src/mars/form/interfaces.py (rev 0)
+++ Sandbox/darrylcousins/mars.form/src/mars/form/interfaces.py 2007-07-21 00:12:17 UTC (rev 78230)
@@ -0,0 +1,17 @@
+import zope.interface
+
+class IMarsFormDirectives(zope.interface.Interface):
+ """These directives are used with WidgetTemplateFactory"""
+
+ def mode(string):
+ """ """
+
+ def view(class_or_interface):
+ """ """
+
+ def field(class_or_interface):
+ """ """
+
+ def widget(class_or_interface):
+ """ """
+
Property changes on: Sandbox/darrylcousins/mars.form/src/mars/form/interfaces.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: Sandbox/darrylcousins/mars.form/src/mars/form/meta.py
===================================================================
--- Sandbox/darrylcousins/mars.form/src/mars/form/meta.py (rev 0)
+++ Sandbox/darrylcousins/mars.form/src/mars/form/meta.py 2007-07-21 00:12:17 UTC (rev 78230)
@@ -0,0 +1,85 @@
+import os
+
+import zope.component
+import zope.interface
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+from zope.pagetemplate.interfaces import IPageTemplate
+
+from z3c.form.interfaces import INPUT_MODE
+from z3c.form.widget import WidgetTemplateFactory
+from z3c.template.template import TemplateFactory
+from z3c.template.interfaces import ILayoutTemplate
+
+import martian
+from martian import util
+from martian.error import GrokError
+
+import grok
+from grok.util import check_adapts
+
+import mars.view
+import mars.template
+from mars.view.meta import ViewGrokkerBase
+
+
+class FormViewGrokker(ViewGrokkerBase):
+ component_class = mars.view.FormView
+
+ def register(self, factory, module_info):
+
+ # is name defined for layout?
+ # if defined a named template is looked up
+ factory._layout_name = util.class_annotation(factory, 'mars.view.layout', '')
+
+ zope.component.provideAdapter(factory,
+ adapts=(self.view_context, self.view_layer),
+ provides=self.provides,
+ name=self.view_name)
+
+class WidgetTemplateFactoryGrokker(martian.ClassGrokker):
+ component_class = mars.template.WidgetTemplateFactory
+ provides = IPageTemplate
+
+ def grok(self, name, factory, context, module_info, templates):
+ view_context = util.determine_class_context(factory, context)
+ factory.module_info = module_info
+ factory_name = factory.__name__.lower()
+
+ # we need a path to the file containing the template
+ template_name = util.class_annotation(factory, 'grok.template',
+ factory_name)
+ filepath = os.path.join(os.path.dirname(module_info.path), template_name)
+ if not os.path.exists(filepath):
+ filepath = None
+ if os.path.exists(template_name):
+ filepath = template_name
+ if filepath is None:
+ raise GrokError("No template found for %s."
+ " Please use grok.template to define path to the"
+ " file containing the template"
+ % (factory.__name__),
+ factory)
+
+ provides = util.class_annotation(factory, 'grok.provides', self.provides)
+ contentType = util.class_annotation(factory,
+ 'mars.template.content_type', 'text/html')
+ view_layer = util.class_annotation(factory, 'mars.layer.layer',
+ None) or module_info.getAnnotation('mars.layer.layer',
+ None) or IDefaultBrowserLayer
+ mode = util.class_annotation(factory, 'mars.form.mode', INPUT_MODE)
+ view = util.class_annotation(factory, 'mars.form.view', None)
+ field = util.class_annotation(factory, 'mars.form.field', None)
+ widget = util.class_annotation(factory, 'mars.form.widget', None)
+
+ factory = WidgetTemplateFactory(filepath, contentType)
+ zope.interface.directlyProvides(factory, provides)
+ #print '\nname:', mode,'context:', view_context,'factory:',\
+ # factory, 'provides', provides, 'view:', view, 'field:', field, \
+ # 'widget:', widget, '\n'
+ zope.component.provideAdapter(factory,
+ adapts=(view_context, view_layer, view, field, widget),
+ provides=provides,
+ name=mode)
+ return True
+
Property changes on: Sandbox/darrylcousins/mars.form/src/mars/form/meta.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: Sandbox/darrylcousins/mars.form/src/mars/form/meta.zcml
===================================================================
--- Sandbox/darrylcousins/mars.form/src/mars/form/meta.zcml (rev 0)
+++ Sandbox/darrylcousins/mars.form/src/mars/form/meta.zcml 2007-07-21 00:12:17 UTC (rev 78230)
@@ -0,0 +1 @@
+<grok package=".meta" xmlns="http://namespaces.zope.org/grok" />
Added: Sandbox/darrylcousins/mars.form/src/mars/form/tests.py
===================================================================
--- Sandbox/darrylcousins/mars.form/src/mars/form/tests.py (rev 0)
+++ Sandbox/darrylcousins/mars.form/src/mars/form/tests.py 2007-07-21 00:12:17 UTC (rev 78230)
@@ -0,0 +1,20 @@
+import unittest
+from zope.testing import doctest
+
+optionflags = doctest.NORMALIZE_WHITESPACE + doctest.ELLIPSIS
+
+def setUp(test):
+ pass
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTests([doctest.DocFileSuite('./form.txt',
+ setUp=setUp,
+ optionflags=optionflags),
+ ])
+
+ return suite
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
+
Property changes on: Sandbox/darrylcousins/mars.form/src/mars/form/tests.py
___________________________________________________________________
Name: svn:keywords
+ Id
More information about the Checkins
mailing list