use schema instance for import
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2713 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
4829cc7b6f
commit
6bf8c4faf0
5 changed files with 47 additions and 15 deletions
|
@ -19,7 +19,7 @@ pre {
|
|||
max-height: 35em;
|
||||
}
|
||||
|
||||
ul, p {
|
||||
ol, ul, p {
|
||||
margin-top: 0.4em;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
@ -28,6 +28,10 @@ ol li, ul li {
|
|||
line-height: 1.5em;
|
||||
}
|
||||
|
||||
blockquote ul {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* class-specific */
|
||||
|
||||
table.listing td {
|
||||
|
|
25
external/README.txt
vendored
25
external/README.txt
vendored
|
@ -28,11 +28,13 @@ Reading object information from an external source
|
|||
|
||||
>>> from loops.external.pyfunc import PyReader
|
||||
|
||||
>>> input = "concept('myquery', u'My Query', 'query', viewName='mystuff.html')"
|
||||
>>> input = ("concept('myquery', u'My Query', 'query', viewName='mystuff.html',"
|
||||
... " options='option1\\noption2')")
|
||||
>>> reader = PyReader()
|
||||
>>> elements = reader.read(input)
|
||||
>>> elements
|
||||
[{'type': 'query', 'name': 'myquery', 'viewName': 'mystuff.html', 'title': u'My Query'}]
|
||||
[{'options': 'option1\noption2', 'type': 'query', 'name': 'myquery',
|
||||
'viewName': 'mystuff.html', 'title': u'My Query'}]
|
||||
|
||||
Creating the corresponding objects
|
||||
----------------------------------
|
||||
|
@ -45,8 +47,12 @@ Creating the corresponding objects
|
|||
(12, 3, 0)
|
||||
|
||||
>>> from loops.common import adapted
|
||||
>>> adapted(concepts['myquery']).viewName
|
||||
'mystuff.html'
|
||||
>>> adMyquery = adapted(concepts['myquery'])
|
||||
|
||||
>>> adMyquery.viewName
|
||||
u'mystuff.html'
|
||||
>>> adMyquery.options
|
||||
[u'option1', u'option2']
|
||||
|
||||
Working with resources
|
||||
----------------------
|
||||
|
@ -86,7 +92,8 @@ registered.
|
|||
|
||||
>>> from loops.external import annotation
|
||||
|
||||
>>> input = """concept('myquery', u'My Query', 'query', viewName='mystuff.html')[
|
||||
>>> input = """concept('myquery', u'My Query', 'query', viewName='mystuff.html',
|
||||
... options='option1\\noption2')[
|
||||
... annotations(creators=(u'john',))]"""
|
||||
>>> elements = reader.read(input)
|
||||
>>> elements[0].subElements
|
||||
|
@ -126,7 +133,8 @@ Writing object information to the external storage
|
|||
type(u'customer', u'Customer', options=u'', typeInterface=u'', viewName=u'')...
|
||||
type(u'query', u'Query', options=u'', typeInterface='loops.query.IQueryConcept',
|
||||
viewName=u'')...
|
||||
concept(u'myquery', u'My Query', u'query', options=u'', viewName='mystuff.html')...
|
||||
concept(u'myquery', u'My Query', u'query', options=u'option1\noption2',
|
||||
viewName=u'mystuff.html')...
|
||||
child(u'projects', u'customer', u'standard')...
|
||||
resource(u'doc04.txt', u'Document 4', u'textdocument', contentType='text/restructured')
|
||||
resourceRelation(u'myquery', u'doc04.txt', u'standard')
|
||||
|
@ -153,7 +161,7 @@ Writing this sequence reproduces the import format.
|
|||
annotations(creators='john'),
|
||||
annotations(modified='2007-08-12')]...
|
||||
|
||||
DC annotations will be exported automaticall after registering the
|
||||
DC annotations will be exported automatically after registering the
|
||||
corresponding extractor adapter.
|
||||
|
||||
>>> from loops.external.annotation import AnnotationsExtractor
|
||||
|
@ -165,7 +173,8 @@ corresponding extractor adapter.
|
|||
|
||||
>>> 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')[
|
||||
concept(u'myquery', u'My Query', u'query', options=u'option1\noption2',
|
||||
viewName=u'mystuff.html')[
|
||||
annotations(creators=(u'john',))]...
|
||||
|
||||
|
||||
|
|
3
external/base.py
vendored
3
external/base.py
vendored
|
@ -191,8 +191,7 @@ class Extractor(Base):
|
|||
schema = schemaFactory(ti, manager=self) #, request=self.request)
|
||||
instance = IInstance(aObj)
|
||||
instance.template = schema
|
||||
# TODO: use ``_not_exportable`` attribute of adapter to control export;
|
||||
# this should also convert object attributes like e.g. typeInterface
|
||||
# TODO: this should also convert object attributes like e.g. typeInterface
|
||||
#data = instance.applyTemplate(mode='export')
|
||||
data = instance.applyTemplate(mode='edit')
|
||||
noexp = getattr(aObj, '_noexportAttributes', ())
|
||||
|
|
21
external/element.py
vendored
21
external/element.py
vendored
|
@ -24,11 +24,17 @@ $Id$
|
|||
"""
|
||||
|
||||
import os
|
||||
from zope import component
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.dottedname.resolve import resolve
|
||||
from zope.interface import Interface, implements
|
||||
from zope.traversing.api import getName, traverse
|
||||
|
||||
from cybertools.composer.interfaces import IInstance
|
||||
from cybertools.composer.schema.interfaces import ISchemaFactory
|
||||
from cybertools.typology.interfaces import IType
|
||||
from loops.common import adapted
|
||||
from loops.interfaces import IConceptSchema
|
||||
from loops.external.interfaces import IElement
|
||||
from loops.i18n.common import I18NValue
|
||||
|
||||
|
@ -82,7 +88,18 @@ class ConceptElement(Element):
|
|||
type = loader.concepts[self['type']]
|
||||
kw = dict((k, v) for k, v in self.items()
|
||||
if k not in self.posArgs)
|
||||
self.object = loader.addConcept(self['name'], self['title'], type, **kw)
|
||||
# use IInstance adapter (name='editor') for unmarshalling values
|
||||
#self.object = loader.addConcept(self['name'], self['title'], type, **kw)
|
||||
self.object = loader.addConcept(self['name'], self['title'], type)
|
||||
formState = self.getInstance().applyTemplate(data=kw, ignoreValidation=True)
|
||||
|
||||
def getInstance(self, omit=['title']):
|
||||
adObject = adapted(self.object)
|
||||
schemaFactory = ISchemaFactory(adObject)
|
||||
ti = IType(self.object).typeInterface or IConceptSchema
|
||||
instance = component.getAdapter(adObject, IInstance, name='editor')
|
||||
instance.template = schemaFactory(ti, manager=self, omit=omit)
|
||||
return instance
|
||||
|
||||
|
||||
class TypeElement(ConceptElement):
|
||||
|
@ -105,6 +122,8 @@ class TypeElement(ConceptElement):
|
|||
kw['typeInterface'] = resolve(ti)
|
||||
self.object = loader.addConcept(self['name'], self['title'],
|
||||
loader.typeConcept, **kw)
|
||||
instance = self.getInstance(omit=['title', 'typeInterface'])
|
||||
formState = instance.applyTemplate(data=kw, ignoreValidation=True)
|
||||
|
||||
|
||||
class ChildElement(Element):
|
||||
|
|
3
util.py
3
util.py
|
@ -90,9 +90,10 @@ def getObjectForUid(uid, intIds=None):
|
|||
intIds = component.getUtility(IIntIds)
|
||||
return intIds.getObject(int(uid))
|
||||
|
||||
def getUidForObject(obj):
|
||||
def getUidForObject(obj, intIds=None):
|
||||
if obj == '*': # wild card
|
||||
return '*'
|
||||
if intIds is None:
|
||||
intIds = component.getUtility(IIntIds)
|
||||
return str(intIds.queryId(obj))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue