Document Actions
08/19/2005
XML Schema support on Zope3 (Concret example)
I added a demo package to illustrate the zope3 / xml schema integration.
You can grab de code over there :
http://svn.nuxeo.org/trac/pub/browser/z3lab/zope/xmlschema/trunk/demo/

The goal of the demo is to get a new content object registred within Zope3 with an "add "and "edit" form driven by an XML Schema definition.

This example is pretty simple but illustrate perfectly the goal of the XML integration and the power of Zope3 ;)

Let's take a look at the xsd we will use in this demo  :
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:attribute name="title" use="required" type="xs:normalizedString" />
<xs:attribute name="description" use="required" type="xs:string"/>
</xs:schema>
(demo.foo.xs)

It defines a schema having 2 attributs : title and description.
title is required and is a normalizedString data type
description is required as well and is a string data type.


Let's define an interface IFoo and set the "foo" schema above. Note I'm using directly an id in here for the schema (i.e : foo). This is because at this stage the schema will be registred within Zope3 under this name. We will see how just after.
import zope.interface
import zope.xmlschema

class IFoo(zope.interface.Interface):
zope.xmlschema.set('foo')
(demo.interfaces.py)

Then define the Foo content object implementing IFoo. It inherits from presistent so that the content object will be persistent but it's not compulsory.
import persistent
import zope.interface
from zope.xmlschema.demo.interfaces import IFoo
class Foo(persistent.Persistent):
zope.interface.implements(IFoo)
def __init__(self, title='', description=''):
self.title = title
self.description = description
(demo.foo.py)

Now the zcml configuration (the glue) (see demo.configure.zcml) to tell Zope what to do whith the definitions above.

Let's take a look at the configure.zcml file for the package as explained below :

<xmlschema
id = "foo"
document ="foo.xs"
>
</xmlschema>
This directive registers the xsd foo.xs under the name of 'foo'

Then the one below defines the new content object (notice the set_schema directive.) You can forget about the Zope permission stuffs if you're not familiar with Zope3
 <content class=".foo.Foo">
<implements
interface="zope.app.annotation.IAttributeAnnotatable" />
<require permission="zope.View"
interface=".interfaces.IFoo" />
<require permission="zope.ManageContent"
set_schema=".interfaces.IFoo" />
</content>

Then, we specify the add and edit form for the Foo content object.

<browser:addform
schema=".interfaces.IFoo"
label="Add a Foo content object"
content_factory=".foo.Foo"
arguments="title description"
name="addFoo.html"
permission="zope.ManageContent"
/>

<browser:editform
schema=".interfaces.IFoo"
label="Edit Foo"
name="edit.html"
menu="zmi_views" title="Edit"
permission="zope.ManageContent"
/>

Then we need to tell Zope to add an entry in ZMI (Zope Management Interface) menu for us to be able to create a Foo content object through the ZMI.
<browser:addMenuItem
class=".foo.Foo"
title="Foo"
permission="zope.ManageContent"
view="addFoo.html"
/>

Now start Zope3 go in the ZMI and click the Add menu entry and ask for the creation of a Foo content object.

You will get the form below :



Then you can try to submit with empty values and since we specified required values on the xml schema the submission is not possible :




Here it is for today.

The 'magic' for the rendering against the schema is done by Zope3 itself. It's not the job of the zope.xmlschema component.

Again, the next step will be to have the rendering done with XForms :) Currently, looking at it. I played today with the mozilla xforms plugin. I'll dig into this whike coming back from holidays at the beginning of September.

Time to sleep...
Posted by Julien Anguenot @ 08/19/2005 07:45 AM. - Categories: python, zope3 -  0 comments
08/18/2005
XML Schema support on Zope3 (update #1)
Some news about the xmlschema component.

First, you may want to check the doctest over there :
http://svn.nuxeo.org/trac/pub/file/z3lab/zope/xmlschema/trunk/README.txt

I did some changes so that it's possible now to register the XML Schema document via ZCML such as this :

<configure xmlns="http://namespaces.zope.org/zope">
<XMLSchema
id="sample"
document="src/zope/xmlschema/tests/examples/simple.xsd"
/>
</configure>

Then the directive register a named utility within the global utility registy of Zope3 that will be used by the dedicated XSD handler.

Now, to use it from you class def you just need to give the id (name) of the registred schema such as :

  >>> import zope.interface
>>> import zope.xmlschema
>>> class IFoo(zope.interface.Interface):
... zope.xmlschema.set('sample')


A new feature as well the validation : the handler perform an XML Schema validation against the XMLSchema.xsd from the w3c.

If you want to test this package (or help right :)) be sure to check the deps. (especially, the CVS HEAD of libxml2 is required for the XML Schema validation)

You will find the dependencies over there :
https://svn.nuxeo.org/trac/pub/file/z3lab/zope/xmlschema/trunk/DEPENDENCIES.txt

Now time to print the XML Schema specifications and code field mappers for the zope interface.

Thanks to Kasimier Buchcik  for the pointer on the libxml2 CVS for the XML Schema validation.

Time to sleep now :)
Posted by Julien Anguenot @ 08/18/2005 04:24 AM. - Categories: python, zope3 -  0 comments
08/12/2005
XML Schema support on Zope3
I started yesterday an XML Schema support for the ZopeInterface.  I would like to be able to define my schema with XML Schemas definitions instead of having to define them in Python.  (which is boring and Python specific...)

The code is within the z3ecm repository: http://svn.nuxeo.org/trac/pub/browser/z3lab/zope/xmlschema/trunk/

See an example :

filepath is a path to an XML Schema definition as defined below :

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="description" type="xsd:string"/>
</xsd:schema>

>>> import zope.interface
>>> import zope.xmlschema
>>> class ITest(zope.interface.Interface):
... zope.xmlschema.set(filepath)

Now introspect the fields defined within the xsd. We will see two new
fields : title and description.

>>> names = list(ITest)
>>> names.sort()
>>> names
['description', 'title']

Now define a class implementing this interface.

>>> class Test(object):
... zope.interface.implements(ITest)
... title = ''
... description = ''
>>>

ITest is implemented by Test

>>> ITest.implementedBy(Test)
True

Let's create an instance of Test

>>> test = Test()

Defines potential values for the two fields

>>> title = u"Title field"
>>> description = u"Description field"

Now we get the fields from the interface:

>>> title_field = ITest.get('title')
>>> description_field = ITest.get('description')

Next we have to bind these fields to the context, so that instance-specific
information can be used for validation:

>>> title_bound = title_field.bind(test)
>>> description_bound = description_field.bind(test)

Now try to validate them :

>>> title_bound.validate(title)
>>> description_bound.validate(description)


You can see that once the schema is set on the interface the interface behaves like if it had been defined in Python. Now let's dig into the XML Schema specification and implements at least all the zope.schema features so that zope.schema and zope.xmlschema will provide the same delcaratives possibililty.

Notice, this component uses lxml as core XML parser.

It's the first step toward XForms support on z3ecm :)

Posted by Julien Anguenot @ 08/12/2005 07:43 PM. - Categories: python, zope3 -  0 comments
08/08/2005
Interfaces versus ABC within Python
Guido wrote a blog entry about interfaces versus ABC in Python.
http://www.artima.com/weblogs/viewpost.jsp?thread=92662

Nice to see the discussion about this point occuring. Note he's taking into account the fact that Zope3 and Twisted do have an actual interface implementation (which is the ZopeInterface BTW)

As a Zope3 developer I just hope he will go for core Python interfaces ;)
Posted by Julien Anguenot @ 08/08/2005 12:19 PM. - Categories: python, zope3 -  0 comments
08/04/2005
Zope3.1 -- Z3/ECM status and future
I just drop a mail on the z3lab mailing list about the Z3/ECM status and future as Zope3.1 has been released this week as an RC.

You may find the mail over there :
http://lists.nuxeo.com/pipermail/z3lab/2005-August/000625.html

Waiting for your comments.
Posted by Julien Anguenot @ 08/04/2005 04:19 PM. - Categories: five, zope, zope3 -  0 comments
08/03/2005
RC1 of Zope 3.1 released !
Here it is ! The first rc of Zope-3.1 is out.

After the bug day last week, which was really productive,  the first rc of Zope-3.1 is now  available. Stephan built the tarball today.

You can grab a tarball from there :
http://www.zope.org/Products/Zope3/3.1.0c1/Zope310c1Released

If you wanna try out this release and help releasing the final you may fill up bugs over there :
http://www.zope.org/Collectors/Zope3-dev/

Now the trunk is dedicated to the 3.2 release for 3 months before the next feature freeze that should occur in October as Zope is moving to a time based release cycle. (december / june)

Now back the Z3/ECM seriously (see my next posts)
Posted by Julien Anguenot @ 08/03/2005 02:14 AM. - Categories: zope3 -  0 comments
Last modified: 12/21/2005 01:11 AM

Nuxeo Bloggers: Log in!
Nuxeo - Indesko - Nuxeo 5 Project
All content is copyrighted by their author.
CPSSkins is Copyright © 2003-2006 by Jean-Marc Orliaguet. | CPS is Copyright © 2002-2006 by Nuxeo SAS.