export and import of DC annotations basically working

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2479 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2008-03-28 14:42:54 +00:00
parent 8e8797a4d1
commit fc3e3096c8
3 changed files with 51 additions and 9 deletions

42
external/README.txt vendored
View file

@ -77,16 +77,29 @@ Working with nodes
Sub-elements
------------
Complex attributes or other informations related to an object may be
represented by sub-elements. The standard example for this kind of data
are the Dublin Core (DC) attributes.
By importing the annotation module the corresponding element class will be
registered.
>>> from loops.external import annotation
>>> input = """concept('myquery', u'My Query', 'query', viewName='mystuff.html')[
... annotations(creators='john')]"""
... annotations(creators=(u'john',))]"""
>>> elements = reader.read(input)
>>> elements[0].subElements
[{'creators': 'john'}]
[{'creators': (u'john',)}]
Loading the element with the sub-element stores the DC attributes.
>>> loader.load(elements)
[('creators', 'john')]
>>> from zope.dublincore.interfaces import IZopeDublinCore
>>> dc = IZopeDublinCore(concepts['myquery'])
>>> dc.creators
(u'john',)
Exporting loops Objects
=======================
@ -120,20 +133,41 @@ Writing object information to the external storage
node('home', u'Home', '', u'menu', body=u'Welcome')
node('myquery', u'My Query', 'home', u'page', target=u'concepts/myquery')...
Writing subElements
Writing sub-elements
-------------------
Let's first set up a sequence with one element containing
two sub-elements.
>>> input = """concept('myquery', u'My Query', 'query', viewName='mystuff.html')[
... annotations(creators='john'),
... annotations(modified='2007-08-12')]"""
>>> elements = reader.read(input)
>>> output = StringIO()
>>> writer.write(elements, output)
Writing this sequence reproduces the import format.
>>> print output.getvalue()
concept('myquery', u'My Query', 'query', viewName='mystuff.html')[
annotations(creators='john'),
annotations(modified='2007-08-12')]...
DC annotations will be exported automaticall after registering the
corresponding extractor adapter.
>>> from loops.external.annotation import AnnotationsExtractor
>>> component.provideAdapter(AnnotationsExtractor)
>>> output = StringIO()
>>> extractor = Extractor(loopsRoot, os.path.join(dataDirectory, 'export'))
>>> PyWriter().write(extractor.extract(), output)
>>> print output.getvalue()
type(u'customer', u'Customer', options=u'', typeInterface=u'', viewName=u'')...
concept(u'myquery', u'My Query', u'query', options=u'', viewName='mystuff.html')[
annotations(creators=(u'john',))]...
The Export/Import View
======================

View file

@ -22,6 +22,8 @@ Export/import of annotations.
$Id$
"""
from datetime import datetime
from time import time
from zope.component import adapts
from zope.dublincore.interfaces import IZopeDublinCore
from zope.interface import implements
@ -40,7 +42,13 @@ class AnnotationsElement(Element):
self[k] = v
def __call__(self, loader):
print self.items()
obj = self.parent.object
dc = IZopeDublinCore(obj, None)
if dc is not None:
for k, v in self.items():
if k in ('created', 'modified'):
v = datetime(*time.strptime(u'%Y-%m-%dT%H:%M')[0:6])
setattr(dc, k, v)
class AnnotationsExtractor(object):

View file

@ -76,11 +76,11 @@ def nl2br(text):
else: # gracefully handle Mac line endings
return '<br />\n'.join(text.split('\r'))
def toUnicode(text, encoding='UTF-8'):
if type(text) is not unicode:
return text.decode(encoding)
def toUnicode(value, encoding='UTF-8'):
if type(value) is not unicode:
return value.decode(encoding)
else:
return text
return value
def getObjectForUid(uid, intIds=None):