Refactored ordered container stuff out of loops package and put into cybertools.container
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1037 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
0be4751c55
commit
da07ee465c
4 changed files with 23 additions and 48 deletions
|
@ -3,19 +3,15 @@ Ordered Containers
|
||||||
|
|
||||||
($Id$)
|
($Id$)
|
||||||
|
|
||||||
>>> from zope.app.testing.setup import placefulSetUp, placefulTearDown
|
|
||||||
>>> site = placefulSetUp(True)
|
|
||||||
>>> from zope.interface import implements
|
|
||||||
|
|
||||||
Let's add an ordered container and place some objects in it:
|
Let's add an ordered container and place some objects in it:
|
||||||
|
|
||||||
|
>>> from zope.interface import implements
|
||||||
>>> from zope.app.container.interfaces import IOrderedContainer
|
>>> from zope.app.container.interfaces import IOrderedContainer
|
||||||
>>> import zope.app.container.ordered
|
>>> import zope.app.container.ordered
|
||||||
>>> class OrderedContainer(zope.app.container.ordered.OrderedContainer):
|
>>> class OrderedContainer(zope.app.container.ordered.OrderedContainer):
|
||||||
... implements(IOrderedContainer)
|
... implements(IOrderedContainer)
|
||||||
|
|
||||||
>>> c1 = OrderedContainer()
|
>>> c1 = OrderedContainer()
|
||||||
>>> site['c1'] = c1
|
|
||||||
>>> c1['sub1'] = OrderedContainer()
|
>>> c1['sub1'] = OrderedContainer()
|
||||||
>>> c1['sub2'] = OrderedContainer()
|
>>> c1['sub2'] = OrderedContainer()
|
||||||
>>> c1['sub3'] = OrderedContainer()
|
>>> c1['sub3'] = OrderedContainer()
|
||||||
|
@ -29,20 +25,16 @@ to the bottom, and to the top
|
||||||
>>> from cybertools.container.ordered import OrderedContainerView
|
>>> from cybertools.container.ordered import OrderedContainerView
|
||||||
>>> from zope.publisher.browser import TestRequest
|
>>> from zope.publisher.browser import TestRequest
|
||||||
>>> view = OrderedContainerView(c1, TestRequest())
|
>>> view = OrderedContainerView(c1, TestRequest())
|
||||||
>>> view.moveToBottom(('sub3',))
|
>>> view.move_bottom(('sub3',))
|
||||||
>>> c1.keys()
|
>>> c1.keys()
|
||||||
['sub1', 'sub2', 'sub4', 'sub3']
|
['sub1', 'sub2', 'sub4', 'sub3']
|
||||||
>>> view.moveUp(('sub4',), 1)
|
>>> view.move_up(('sub4',), 1)
|
||||||
>>> c1.keys()
|
>>> c1.keys()
|
||||||
['sub1', 'sub4', 'sub2', 'sub3']
|
['sub1', 'sub4', 'sub2', 'sub3']
|
||||||
>>> view.moveToTop(('sub2',))
|
>>> view.move_top(('sub2',))
|
||||||
>>> c1.keys()
|
>>> c1.keys()
|
||||||
['sub2', 'sub1', 'sub4', 'sub3']
|
['sub2', 'sub1', 'sub4', 'sub3']
|
||||||
>>> view.moveDown(('sub2',), 2)
|
>>> view.move_down(('sub2',), 2)
|
||||||
>>> c1.keys()
|
>>> c1.keys()
|
||||||
['sub1', 'sub4', 'sub2', 'sub3']
|
['sub1', 'sub4', 'sub2', 'sub3']
|
||||||
|
|
||||||
The end...
|
|
||||||
==========
|
|
||||||
|
|
||||||
>>> placefulTearDown()
|
|
||||||
|
|
|
@ -5,17 +5,13 @@
|
||||||
xmlns:zope="http://namespaces.zope.org/zope"
|
xmlns:zope="http://namespaces.zope.org/zope"
|
||||||
i18n_domain="zope">
|
i18n_domain="zope">
|
||||||
|
|
||||||
<pages
|
<page
|
||||||
for="zope.app.container.interfaces.IOrderedContainer"
|
for="zope.app.container.interfaces.IOrderedContainer"
|
||||||
|
name="contents.html"
|
||||||
|
template="contents.pt"
|
||||||
class=".ordered.OrderedContainerView"
|
class=".ordered.OrderedContainerView"
|
||||||
permission="zope.ManageContent">
|
permission="zope.ManageContent"
|
||||||
<page name="contents.html" template="contents.pt"
|
|
||||||
menu="zmi_views" title="Contents"
|
menu="zmi_views" title="Contents"
|
||||||
/>
|
/>
|
||||||
<page name="move_down" attribute="moveDown" />
|
|
||||||
<page name="move_up" attribute="moveUp" />
|
|
||||||
<page name="move_bottom" attribute="moveToBottom" />
|
|
||||||
<page name="move_top" attribute="moveToTop" />
|
|
||||||
</pages>
|
|
||||||
|
|
||||||
</configure>
|
</configure>
|
||||||
|
|
|
@ -4,9 +4,8 @@
|
||||||
<div metal:fill-slot="body">
|
<div metal:fill-slot="body">
|
||||||
<div metal:define-macro="contents">
|
<div metal:define-macro="contents">
|
||||||
|
|
||||||
<tal:checkmove define="isMoveAction view/checkMoveAction">
|
<tal:checkmove define="dummy view/checkMoveAction">
|
||||||
|
|
||||||
<tal:showlisting condition="not:isMoveAction">
|
|
||||||
<form name="containerContentsForm" method="post" action="."
|
<form name="containerContentsForm" method="post" action="."
|
||||||
tal:attributes="action request/URL"
|
tal:attributes="action request/URL"
|
||||||
tal:define="container_contents view/listContentInfo">
|
tal:define="container_contents view/listContentInfo">
|
||||||
|
@ -199,7 +198,6 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</tal:showlisting>
|
|
||||||
</tal:checkmove>
|
</tal:checkmove>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,6 @@ class OrderedContainerView(JustContents):
|
||||||
within an ordered container.
|
within an ordered container.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@Lazy
|
|
||||||
def url(self):
|
|
||||||
return zapi.absoluteURL(self.context, self.request)
|
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def orderable(self):
|
def orderable(self):
|
||||||
return len(self.context) > 1
|
return len(self.context) > 1
|
||||||
|
@ -45,36 +41,29 @@ class OrderedContainerView(JustContents):
|
||||||
request = self.request
|
request = self.request
|
||||||
for var in request:
|
for var in request:
|
||||||
if var.startswith('move_'):
|
if var.startswith('move_'):
|
||||||
params = []
|
delta = request.get('delta', 1)
|
||||||
if 'delta' in request:
|
ids = request.get('ids', [])
|
||||||
params.append('delta=' + request['delta'])
|
if ids:
|
||||||
if 'ids' in request:
|
m = getattr(self, var, None)
|
||||||
for id in request['ids']:
|
if m:
|
||||||
params.append('ids:list=' + id)
|
m(ids, delta)
|
||||||
request.response.redirect('%s/%s?%s'
|
return
|
||||||
% (self.url, var, '&'.join(params)))
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def moveDown(self, ids=[], delta=1):
|
def move_down(self, ids=[], delta=1):
|
||||||
self.context.updateOrder(
|
self.context.updateOrder(
|
||||||
moveByDelta(self.context.keys(), ids, int(delta)))
|
moveByDelta(self.context.keys(), ids, int(delta)))
|
||||||
self.request.response.redirect(self.url + '/contents.html')
|
|
||||||
|
|
||||||
def moveUp(self, ids=[], delta=1):
|
def move_up(self, ids=[], delta=1):
|
||||||
self.context.updateOrder(
|
self.context.updateOrder(
|
||||||
moveByDelta(self.context.keys(), ids, -int(delta)))
|
moveByDelta(self.context.keys(), ids, -int(delta)))
|
||||||
self.request.response.redirect(self.url + '/contents.html')
|
|
||||||
|
|
||||||
def moveToBottom(self, ids=[]):
|
def move_bottom(self, ids=[], delta=0):
|
||||||
self.context.updateOrder(
|
self.context.updateOrder(
|
||||||
moveByDelta(self.context.keys(), ids, len(self.context)))
|
moveByDelta(self.context.keys(), ids, len(self.context)))
|
||||||
self.request.response.redirect(self.url + '/contents.html')
|
|
||||||
|
|
||||||
def moveToTop(self, ids=[]):
|
def move_top(self, ids=[], delta=0):
|
||||||
self.context.updateOrder(
|
self.context.updateOrder(
|
||||||
moveByDelta(self.context.keys(), ids, -len(self.context)))
|
moveByDelta(self.context.keys(), ids, -len(self.context)))
|
||||||
self.request.response.redirect(self.url + '/contents.html')
|
|
||||||
|
|
||||||
|
|
||||||
def moveByDelta(objs, toMove, delta):
|
def moveByDelta(objs, toMove, delta):
|
||||||
|
|
Loading…
Add table
Reference in a new issue