First steps towards creating resources via a node object
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1034 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
2f8d17e0f7
commit
dedd7d8736
3 changed files with 28 additions and 11 deletions
10
README.txt
10
README.txt
|
@ -300,6 +300,16 @@ application uses a subclass that does all the other stuff for form handling.)
|
||||||
>>> from loops.browser.node import ConfigureBaseView
|
>>> from loops.browser.node import ConfigureBaseView
|
||||||
>>> view = ConfigureBaseView(INodeConfigSchema(m111), TestRequest())
|
>>> view = ConfigureBaseView(INodeConfigSchema(m111), TestRequest())
|
||||||
>>> view.checkCreateTarget()
|
>>> view.checkCreateTarget()
|
||||||
|
>>> sorted(resources.keys())
|
||||||
|
[u'doc1']
|
||||||
|
>>> form = {'field.createTarget': True,
|
||||||
|
... 'field.targetUri': '.loops/resources/ma07',
|
||||||
|
... 'field.targetType': 'loops.resource.MediaAsset'}
|
||||||
|
>>> view = ConfigureBaseView(INodeConfigSchema(m111), TestRequest(form=form))
|
||||||
|
>>> view = ConfigureBaseView(m111, TestRequest(form=form))
|
||||||
|
>>> view.checkCreateTarget()
|
||||||
|
>>> sorted(resources.keys())
|
||||||
|
[u'doc1', u'ma07']
|
||||||
|
|
||||||
It is also possible to edit a target's attributes directly in an
|
It is also possible to edit a target's attributes directly in an
|
||||||
edit form provided by the node:
|
edit form provided by the node:
|
||||||
|
|
|
@ -30,6 +30,7 @@ from zope.proxy import removeAllProxies
|
||||||
from zope.security import canAccess, canWrite
|
from zope.security import canAccess, canWrite
|
||||||
from zope.security.proxy import removeSecurityProxy
|
from zope.security.proxy import removeSecurityProxy
|
||||||
|
|
||||||
|
from loops.resource import MediaAsset
|
||||||
|
|
||||||
class NodeView(object):
|
class NodeView(object):
|
||||||
|
|
||||||
|
@ -95,17 +96,26 @@ class NodeView(object):
|
||||||
|
|
||||||
|
|
||||||
class ConfigureBaseView(object):
|
class ConfigureBaseView(object):
|
||||||
""" Helper view object for editing/configuring a node, providing the
|
""" Helper view class for editing/configuring a node, providing the
|
||||||
stuff needed for creating a target object.
|
stuff needed for creating a target object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, context, request):
|
def __init__(self, context, request):
|
||||||
self.context = context
|
self.context = removeSecurityProxy(context)
|
||||||
self.request = request
|
self.request = request
|
||||||
|
|
||||||
def checkCreateTarget(self):
|
def checkCreateTarget(self):
|
||||||
pass
|
form = self.request.form
|
||||||
|
if 'field.createTarget' in form:
|
||||||
|
type = self.request.form.get('field.targetType',
|
||||||
|
'loops.resource.MediaAsset')
|
||||||
|
# TODO: find class (better: factory) from type name
|
||||||
|
uri = self.request.form.get('field.targetUri', None)
|
||||||
|
# TODO: generate uri/__name__ if not given
|
||||||
|
if uri:
|
||||||
|
# TODO: find container
|
||||||
|
self.context.getLoopsRoot()['resources']['ma07'] = MediaAsset()
|
||||||
|
#self.context.loopsRoot['resources']['ma07'] = MediaAsset()
|
||||||
|
|
||||||
class ConfigureView(object):
|
class ConfigureView(object):
|
||||||
""" An editing view for configuring a node, optionally creating
|
""" An editing view for configuring a node, optionally creating
|
||||||
|
@ -117,6 +127,8 @@ class ConfigureView(object):
|
||||||
self.delegate = ConfigureBaseView(context, request)
|
self.delegate = ConfigureBaseView(context, request)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
if self.update_status is not None:
|
||||||
|
return self.update_status
|
||||||
self.delegate.checkCreateTarget()
|
self.delegate.checkCreateTarget()
|
||||||
return super(ConfigureView, self).update()
|
return super(ConfigureView, self).update()
|
||||||
|
|
||||||
|
|
9
view.py
9
view.py
|
@ -212,13 +212,8 @@ class NodeConfigAdapter(object):
|
||||||
return '%s.%s' % (target.__module__, target.__class__.__name__)
|
return '%s.%s' % (target.__module__, target.__class__.__name__)
|
||||||
return None
|
return None
|
||||||
def setTargetType(self, tt):
|
def setTargetType(self, tt):
|
||||||
self._targetType = tt # to be able to use it in setCreateTarget()
|
pass # only used whe a new target object is created
|
||||||
targetType = property(getTargetType, setTargetType)
|
targetType = property(getTargetType, setTargetType)
|
||||||
|
|
||||||
def setCreateTarget(self, value):
|
createTarget = False # not used
|
||||||
if value:
|
|
||||||
print 'targetType:', self._targetType or self.targetType
|
|
||||||
def getCreateTarget(self): return False
|
|
||||||
createTarget = property(getCreateTarget, setCreateTarget)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue