[Zope-CVS] CVS: Products/PageDesign - ReferencedElement.py:1.1.2.1 ISlotProvider.py:1.1.2.2 PageDesign.py:1.2.2.6 Slot.py:1.1.2.5 SlotElementClipboardSource.py:1.1.2.3 SlotElementClipboardTarget.py:1.1.2.3 SlotElementTraverser.py:1.1.2.4 SlotProvider.py:1.1.2.3
Shane Hathaway
shane@cvs.zope.org
Thu, 8 Aug 2002 22:58:47 -0400
Update of /cvs-repository/Products/PageDesign
In directory cvs.zope.org:/tmp/cvs-serv16878
Modified Files:
Tag: page-redesign-branch
ISlotProvider.py PageDesign.py Slot.py
SlotElementClipboardSource.py SlotElementClipboardTarget.py
SlotElementTraverser.py SlotProvider.py
Added Files:
Tag: page-redesign-branch
ReferencedElement.py
Log Message:
Drag and drop is working.
=== Added File Products/PageDesign/ReferencedElement.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import Acquisition
from Acquisition import aq_base, aq_get, aq_inner, aq_parent
from Persistence import Persistent
from OFS.Traversable import Traversable
from IPageElement import IPageElement
class ReferencedElement (Persistent, Acquisition.Explicit, Traversable):
__implements__ = IPageElement
def __init__(self, ob):
self._path = ob.getPhysicalPath()
def _deref(self):
root = self.getPhysicalRoot()
return root.restrictedTraverse(self._path)
def render(self, design, editable, index):
"""Returns a string.
"""
ob = self._deref()
if getattr(aq_base(ob), 'isDocTemp', 0):
# DTML
s = ob(self, aq_get(self, 'REQUEST'),
editable=editable, index=index)
elif hasattr(ob, '__call__'):
# Other kinds of callable objects
s = ob(editable=editable, index=index)
else:
s = str(ob)
return s
def getTitle(self):
"""Returns the title of this element.
"""
ob = self._deref()
# It's altogether silly to have to look at four attributes. :-)
if hasattr(aq_base(ob), 'Title'):
s = ob.Title()
else:
s = getattr(ob, 'title', '')
if s:
return str(s)
if hasattr(aq_base(ob), 'getId'):
return ob.getId()
return str(ob.id)
def getEditURL(self):
"""Returns the URL for editing this element.
Returns None or a blank string if it is not editable.
"""
return None
=== Products/PageDesign/ISlotProvider.py 1.1.2.1 => 1.1.2.2 ===
--- Products/PageDesign/ISlotProvider.py:1.1.2.1 Sat Aug 3 15:58:03 2002
+++ Products/PageDesign/ISlotProvider.py Thu Aug 8 22:58:46 2002
@@ -23,10 +23,8 @@
The slot might be created on the fly and not stored.
"""
- def _makeSlot(name):
- """Creates a slot if it doesn't exist.
-
- Returns the slot object.
+ def _persistSlot(slot):
+ """Ensures the slot is linked into the database.
"""
def _isEditable():
=== Products/PageDesign/PageDesign.py 1.2.2.5 => 1.2.2.6 ===
--- Products/PageDesign/PageDesign.py:1.2.2.5 Wed Aug 7 23:57:06 2002
+++ Products/PageDesign/PageDesign.py Thu Aug 8 22:58:46 2002
@@ -37,6 +37,7 @@
from RawFile import RawFile
from SlotProvider import SlotProvider
+from ReferencedElement import ReferencedElement
from ISlotProvider import ISlotProvider
from IClipboardSource import IClipboardSource
from IClipboardTarget import IClipboardTarget
@@ -148,7 +149,7 @@
If the slot already exists, does nothing.
"""
- self.slots._makeSlot(name)
+ self.slots._persistSlot(self.slots[name])
security.declareProtected(change_page_designs, 'delSlot')
@@ -191,7 +192,7 @@
source, source, 'cut', source.cut)
element = source.cut()
else:
- element = ElementReference(source)
+ element = ReferencedElement(source)
elements.append(element)
target = self.getPhysicalRoot().restrictedTraverse(target_path)
=== Products/PageDesign/Slot.py 1.1.2.4 => 1.1.2.5 ===
--- Products/PageDesign/Slot.py:1.1.2.4 Wed Aug 7 23:57:06 2002
+++ Products/PageDesign/Slot.py Thu Aug 8 22:58:46 2002
@@ -77,8 +77,8 @@
alt="Add element to slot: %(slot_name)s"
title="Add element to slot: %(slot_name)s" /></a></div>'''
- element_html = '''<div class="design-element"
- id="%(clipboard_path)s">%(text)s</div>'''
+ element_html = '''<div class="design-element" id="%(clipboard_path)s">
+ <div class="design-element-titlebar">%(title)s</div>%(text)s</div>'''
def __init__(self, id):
@@ -149,10 +149,11 @@
))
try:
- text = e.render(design=design, editable=editable, index=index)
+ text = e.render(design, editable, index)
except:
# Show the exception.
- text = escape(('%s: %s' % (sys.exc_info()[:2]))[:80])
+ text = "<i>%s</i>" % (
+ escape(('%s: %s' % (sys.exc_info()[:2]))[:80]))
if editable:
path = '%s/elementSources/%d' % (phys_path, index)
@@ -183,6 +184,9 @@
def getElement(self, index):
return self.contents[index]
+ def beforeChange(self):
+ aq_parent(aq_inner(self))._persistSlot(self)
+
def insertBefore(self, before_element, elements):
# Verify none of the elements are already inserted.
# An element can only be in one place at a time.
@@ -191,6 +195,7 @@
raise ValueError, 'Not a page element'
if e in self.contents:
raise ValueError, 'Already inserted'
+ self.beforeChange()
if before_element is None:
# append.
self.contents = self.contents + tuple(elements)
@@ -202,6 +207,7 @@
def remove(self, element):
lst = list(self.contents)
lst.remove(element)
+ self.beforeChange()
self.contents = tuple(lst)
Globals.InitializeClass(Slot)
=== Products/PageDesign/SlotElementClipboardSource.py 1.1.2.2 => 1.1.2.3 ===
--- Products/PageDesign/SlotElementClipboardSource.py:1.1.2.2 Wed Aug 7 23:57:06 2002
+++ Products/PageDesign/SlotElementClipboardSource.py Thu Aug 8 22:58:46 2002
@@ -19,6 +19,7 @@
from AccessControl import ClassSecurityInfo
from IClipboardSource import IClipboardSource
from IIndexedSlot import IIndexedSlot
+from IPageElement import IPageElement
# Permission name
change_page_designs = 'Change Page Designs'
@@ -30,16 +31,18 @@
security = ClassSecurityInfo()
- def __init__(self, index):
+ def init(self, index):
index = int(index)
slot = aq_parent(aq_inner(self))
- assert IIndexedSlot.isImplementedBy(slot)
- self.element = slot.getElement(index)
+ assert IIndexedSlot.isImplementedBy(slot), `slot`
+ element = aq_base(slot.getElement(index))
+ assert IPageElement.isImplementedBy(element), `element`
+ self.element = aq_base(element)
+ return self
security.declareProtected(change_page_designs, 'cut')
def cut(self):
slot = aq_parent(aq_inner(self))
- assert IIndexedSlot.isImplementedBy(slot)
element = aq_base(self.element)
slot.remove(element)
return element
=== Products/PageDesign/SlotElementClipboardTarget.py 1.1.2.2 => 1.1.2.3 ===
--- Products/PageDesign/SlotElementClipboardTarget.py:1.1.2.2 Wed Aug 7 23:57:06 2002
+++ Products/PageDesign/SlotElementClipboardTarget.py Thu Aug 8 22:58:46 2002
@@ -17,6 +17,8 @@
from Acquisition import aq_base, aq_inner, aq_parent
from AccessControl import ClassSecurityInfo
from IClipboardTarget import IClipboardTarget
+from IIndexedSlot import IIndexedSlot
+from IPageElement import IPageElement
# Permission name
change_page_designs = 'Change Page Designs'
@@ -26,12 +28,18 @@
__implements__ = IClipboardTarget
+ __roles__ = None # ugh
+
security = ClassSecurityInfo()
- def __init__(self, index):
+ def init(self, index):
index = int(index)
slot = aq_parent(aq_inner(self))
- self.before_element = slot.getElement(index)
+ assert IIndexedSlot.isImplementedBy(slot), `slot`
+ before_element = aq_base(slot.getElement(index))
+ assert IPageElement.isImplementedBy(before_element), `before_element`
+ self.before_element = before_element
+ return self
security.declareProtected(change_page_designs, 'paste')
def paste(self, elements):
@@ -52,6 +60,7 @@
security.declareProtected(change_page_designs, 'paste')
def paste(self, elements):
slot = aq_parent(aq_inner(self))
+ assert IIndexedSlot.isImplementedBy(slot), `slot`
slot.insertBefore(None, elements)
Globals.InitializeClass(SlotElementClipboardLastTarget)
=== Products/PageDesign/SlotElementTraverser.py 1.1.2.3 => 1.1.2.4 ===
--- Products/PageDesign/SlotElementTraverser.py:1.1.2.3 Wed Aug 7 23:57:06 2002
+++ Products/PageDesign/SlotElementTraverser.py Thu Aug 8 22:58:46 2002
@@ -13,6 +13,7 @@
##############################################################################
import Acquisition
+from Acquisition import aq_inner, aq_parent
import Globals
from AccessControl import ClassSecurityInfo
from OFS.Traversable import Traversable
@@ -23,6 +24,8 @@
security = ClassSecurityInfo()
security.setDefaultAccess('allow')
+ __roles__ = None
+
def __init__(self, id, item_factory):
self.id = id
self._item_factory = item_factory
@@ -31,7 +34,8 @@
return self.id
def __getitem__(self, name):
- return self._item_factory(name).__of__(self)
+ slot = aq_parent(aq_inner(self))
+ return self._item_factory().__of__(slot).init(name)
Globals.InitializeClass(SlotElementTraverser)
=== Products/PageDesign/SlotProvider.py 1.1.2.2 => 1.1.2.3 ===
--- Products/PageDesign/SlotProvider.py:1.1.2.2 Mon Aug 5 21:28:27 2002
+++ Products/PageDesign/SlotProvider.py Thu Aug 8 22:58:46 2002
@@ -13,6 +13,7 @@
##############################################################################
import Acquisition
+from Acquisition import aq_base
import Globals
from AccessControl import ClassSecurityInfo
from OFS.Traversable import Traversable
@@ -37,16 +38,17 @@
def getId(self):
return self.id
- def _makeSlot(self, name):
- self.__getitem__(name, 1)
+ def _persistSlot(self, slot):
+ slots = self.aq_parent._slots
+ name = slot.getId()
+ if not slots.has_key(name):
+ slots[name] = aq_base(slot)
- def __getitem__(self, name, add=0):
+ def __getitem__(self, name):
slots = self.aq_parent._slots
slot = slots.get(name)
if slot is None:
slot = Slot(name)
- if add:
- slots[name] = slot
return slot.__of__(self)
def _isEditable(self):