Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
new features, but backward compatible, new version, old version is in…
Browse files Browse the repository at this point in the history
… branches/1.0. see CHANGES.txt for details
  • Loading branch information
dobe committed Jan 14, 2007
1 parent 9fed517 commit f59cdb2
Show file tree
Hide file tree
Showing 17 changed files with 495 additions and 37 deletions.
27 changes: 27 additions & 0 deletions src/z3c/configurator/CHANGES.txt
@@ -0,0 +1,27 @@
========================
z3c.configurator Changes
========================

This file contains change information for the current z3c.configurator
package.

After 1.0 (trunk only)
======================

New features
------------

- Added possibility to apply only specific named plugins in confugure.

- New option to configure allows to have namespaced data to resolve
naming conflicts.

- Added a page to call configurators TTW. This is the first step
towards mergin z3c.configurator and z3c.sampledata into one package.

Bug fixes
---------

- SchemaConfigurationPluginBase now implements
ISchemaConfigurationPluginBase.

55 changes: 55 additions & 0 deletions src/z3c/configurator/README.txt
Expand Up @@ -125,3 +125,58 @@ The value must exist and be valid:
...
WrongType: (1, <type 'unicode'>)

Data Namespaces
---------------

In order to not confuse attribute names if two plugins share a common
name it is possible to pass data as a dictionary of dictionaries. The
keys of the dictionary is the name under which the plugins are
registered.

>>> something = Something()
>>> data = {u'add foo': {'foo': u'foo value'},
... u'add bar': {'bar': u'bar value'}}
>>> configurator.configure(something, data, useNameSpaces=True)
>>> something.foo, something.bar
(u'Text: foo value', u'bar value')

Named Configuration
-------------------

Sometimes we do not want all registered configuration plugins to be
executed. This can be achieved by providing the names argument to the
configure function.

Let us create a new something:

>>> something = Something()

If we now configure it without names we get both attributes set.

>>> configurator.configure(something, {'foo': u'my value', 'bar': u'asdf'})
>>> something.__dict__
{'foo': u'Text: my value', 'bar': u'asdf'}

Now let us just configure the plugin 'add bar'.

>>> something = Something()
>>> configurator.configure(something, {'foo': u'my value', 'bar': u'asdf'},
... names=['add bar'])
>>> something.__dict__
{'bar': u'asdf'}

Dependencies of plugins are always executed - they don't have to be
added to the ```names``` argument.

>>> something = Something()
>>> configurator.configure(something, {'foo': u'my value'},
... names=['extend foo'])
>>> something.foo
u'Text: my value'

Named configurations are usefull when called manually through the web
(see browser/README.txt). The configurator package does not look if a
configuration is already applied if called twice. It is the
responsibility of the plugin to be aware that it doesn't do things
twice or delete things.

3 changes: 3 additions & 0 deletions src/z3c/configurator/SETUP.cfg
@@ -0,0 +1,3 @@
<data-files zopeskel/etc/package-includes>
z3c.configurator-*.zcml
</data-files>
46 changes: 46 additions & 0 deletions src/z3c/configurator/browser/README.txt
@@ -0,0 +1,46 @@
=========================
Calling Configurators TTW
=========================

A configuration view is registered to apply named configuration on any
object. We defined two example configurators which we now gonna apply
to the site object.

>>> from zope.testbrowser.testing import Browser
>>> browser = Browser()
>>> browser.addHeader('Authorization','Basic mgr:mgrpw')
>>> browser.handleErrors = False

>>> browser.open('http://localhost/manage')
>>> browser.url
'http://localhost/@@contents.html'

The view is registered in the zmi_views menu

>>> browser.getLink(u'Configurators').click()
>>> viewURL = browser.url
>>> viewURL
'http://localhost/@@configurators.html'

>>> sel = browser.getControl(name="form.pluginNames.to")

First we can choose from the registered named plugins.

>>> plugs = browser.getControl(name="form.pluginNames.from").options
>>> sorted(plugs)
['z3c.configurator.testing.setdescription',
'z3c.configurator.testing.settitle']
>>> browser.open(viewURL + '?form.pluginNames=z3c.configurator.testing.settitle')

We have choosen a plugin, so now we have a form for the arguments needed.

>>> browser.getControl('Some Argument').value
''
>>> browser.getControl('Some Argument').value = "New Title"
>>> browser.getControl('Apply').click()


XXX form.pluginNames have to be set, but we can't because the widget
uses javascript.


1 change: 1 addition & 0 deletions src/z3c/configurator/browser/__init__.py
@@ -0,0 +1 @@
#
9 changes: 9 additions & 0 deletions src/z3c/configurator/browser/configure.pt
@@ -0,0 +1,9 @@
<div metal:use-macro="view/base_template/macros/main" >
<div metal:fill-slot="above_buttons">
<tal:block tal:repeat="subform view/subforms">
<p tal:content="subform/prefix"></p>
<div tal:replace="structure subform" /><hr/>
</tal:block>
</div>
</div>

14 changes: 14 additions & 0 deletions src/z3c/configurator/browser/configure.zcml
@@ -0,0 +1,14 @@
<configure
xmlns:zope="http://namespaces.zope.org/zope"
xmlns="http://namespaces.zope.org/browser"
i18n_domain="z3c.configurator">

<page
for="*"
permission="z3c.configurator.ManageConfigurations"
name="configurators.html"
title="Configurators"
class=".views.ConfigureForm"
menu="zmi_views"/>

</configure>
66 changes: 66 additions & 0 deletions src/z3c/configurator/browser/ftesting.zcml
@@ -0,0 +1,66 @@
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:meta="http://namespaces.zope.org/meta"
i18n_domain="zope">

<include package="zope.app" />

<include package="zope.app.securitypolicy" file="meta.zcml" />

<include package="zope.app.server" />
<include package="zope.app.authentication" />
<securityPolicy
component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy" />

<include package="zope.app.securitypolicy" />

<role id="zope.Anonymous" title="Everybody"
description="All users have this role implicitly" />

<role id="zope.Manager" title="Site Manager" />


<principal
id="zope.manager"
title="Administrator"
login="mgr"
password="mgrpw" />
<grant
role="zope.Manager"
principal="zope.manager"
/>

<unauthenticatedPrincipal
id="zope.anybody"
title="Unauthenticated User" />

<unauthenticatedGroup
id="zope.Anybody"
title="Unauthenticated Users"
/>

<authenticatedGroup
id="zope.Authenticated"
title="Authenticated Users"
/>

<everybodyGroup
id="zope.Everybody"
title="All Users"
/>

<include package="zope.app.form.browser" />
<include package="zope.formlib" />
<include package="z3c.configurator"/>

<adapter
name="z3c.configurator.testing.settitle"
factory="z3c.configurator.browser.testing.SetTitle"/>

<adapter
name="z3c.configurator.testing.setdescription"
factory="z3c.configurator.browser.testing.SetDescription"/>


<grantAll role="zope.Manager" />
</configure>
29 changes: 29 additions & 0 deletions src/z3c/configurator/browser/ftests.py
@@ -0,0 +1,29 @@
import unittest
from zope.app.testing import functional

functional.defineLayer('TestLayer', 'ftesting.zcml')


def setUp(test):
"""Setup a reasonable environment for the category tests"""
pass


def tearDown(test):
pass


def test_suite():
suite = unittest.TestSuite()
suites = (
functional.FunctionalDocFileSuite('README.txt',
setUp=setUp, tearDown=tearDown,
),
)
for s in suites:
s.layer=TestLayer
suite.addTest(s)
return suite

if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
32 changes: 32 additions & 0 deletions src/z3c/configurator/browser/testing.py
@@ -0,0 +1,32 @@
"""Some test classes
"""
from z3c.configurator import configurator
from zope import interface
from zope import component
from zope import schema
from zope.dublincore.interfaces import IZopeDublinCore
from zope.annotation.interfaces import IAttributeAnnotatable

class ISingleArg(interface.Interface):

arg = schema.TextLine(title=u'Some Argument')

class SetTitle(configurator.SchemaConfigurationPluginBase):
"""makes an object implement IFoo"""
component.adapts(IAttributeAnnotatable)
schema = ISingleArg

def __call__(self, data):
dc = IZopeDublinCore(self.context)
dc.title = data.get('arg')

class SetDescription(configurator.SchemaConfigurationPluginBase):

component.adapts(IAttributeAnnotatable)
schema = ISingleArg

def __call__(self, data):
dc = IZopeDublinCore(self.context)
dc.description = data.get('arg')


0 comments on commit f59cdb2

Please sign in to comment.