[Zope-CVS] CVS: Products/PageDesign - IPalette.py:1.1.2.1 PageDesign.py:1.2.2.5 Slot.py:1.1.2.4 SlotElementClipboardSource.py:1.1.2.2 SlotElementClipboardTarget.py:1.1.2.2 SlotElementTraverser.py:1.1.2.3
Shane Hathaway
shane@cvs.zope.org
Wed, 7 Aug 2002 23:57:07 -0400
Update of /cvs-repository/Products/PageDesign
In directory cvs.zope.org:/tmp/cvs-serv3999
Modified Files:
Tag: page-redesign-branch
PageDesign.py Slot.py SlotElementClipboardSource.py
SlotElementClipboardTarget.py SlotElementTraverser.py
Added Files:
Tag: page-redesign-branch
IPalette.py
Log Message:
- "Acquire" palettes. This might be a good way to work.
- Added various security offerings
=== Added File Products/PageDesign/IPalette.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.
#
##############################################################################
from Interface import Interface
class IPalette (Interface):
"""Palette of objects addable to a page design.
This is mainly a marker interface."""
def objectValues():
"""Returns the palette items.
If an item supports the IClipboardSource interface, it will be
used when adding to the page design; otherwise the page design
will make some kind of reference to the object.
"""
=== Products/PageDesign/PageDesign.py 1.2.2.4 => 1.2.2.5 ===
--- Products/PageDesign/PageDesign.py:1.2.2.4 Tue Aug 6 22:37:22 2002
+++ Products/PageDesign/PageDesign.py Wed Aug 7 23:57:06 2002
@@ -24,20 +24,23 @@
import Globals
import Acquisition
from Acquisition import aq_base, aq_inner, aq_parent
-from AccessControl import ClassSecurityInfo
+from AccessControl import ClassSecurityInfo, getSecurityManager
from AccessControl.Permissions import view
+from AccessControl.ZopeGuards import guarded_getattr
from Interface import Base as Interface
from ZODB import Persistent
from ZODB.PersistentMapping import PersistentMapping
from OFS.SimpleItem import SimpleItem
from OFS.PropertyManager import PropertyManager
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
+from Globals import ImageFile
from RawFile import RawFile
from SlotProvider import SlotProvider
from ISlotProvider import ISlotProvider
from IClipboardSource import IClipboardSource
from IClipboardTarget import IClipboardTarget
+from IPalette import IPalette
# Permission name
change_page_designs = 'Change Page Designs'
@@ -56,14 +59,19 @@
class PageDesignBase (Persistent):
"""Base class for page designs.
"""
- security = ClassSecurityInfo()
-
_slots = None # { slot_name -> (element_id,) }
+ template_id = None
+ default_palette_id = None
+ title = ''
+ _v_rendering = 0
+ slots = SlotProvider()
manage_options = (
{'label': 'Design', 'action': 'manage_main'},
)
+ security = ClassSecurityInfo()
+
security.declareProtected(change_page_designs, 'scripts_js')
scripts_js = RawFile('scripts.js', 'text/javascript', _www)
@@ -79,6 +87,20 @@
security.declareProtected(change_page_designs, 'designTopFrame')
designTopFrame = PageTemplateFile('designTopFrame.pt', _www)
+ security.declareProtected(change_page_designs, 'addElementDialog')
+ addElementDialog = PageTemplateFile('addElementDialog.pt', _www)
+
+ security.declareProtected(change_page_designs, 'object_list_rows')
+ object_list_rows = PageTemplateFile('object_list_rows.pt', _www)
+
+ security.declareProtected(change_page_designs, 'sorted_down')
+ sorted_down = ImageFile('sorted_down.gif', _www)
+ sorted_down.__name__ = 'sorted_down'
+
+ security.declareProtected(change_page_designs, 'sorted_up')
+ sorted_up = ImageFile('sorted_up.gif', _www)
+ sorted_up.__name__ = 'sorted_up'
+
head_html = '''
<!-- Page design scripts and styles -->
<link type="text/css" href="%(design_url)s/pagedesign_css"
@@ -99,9 +121,19 @@
<!-- End page design footer -->
'''
- _v_rendering = 0
-
- slots = SlotProvider()
+ dialog_done_html = '''
+ <html>
+ <body>
+ <script>
+ var main = window.opener;
+ if (main) {
+ main.location.reload();
+ }
+ window.close();
+ </script>
+ </body>
+ </html>
+ '''
def __init__(self, id, title=''):
self._slots = PersistentMapping()
@@ -109,17 +141,6 @@
if title:
self.title = title
- security.declareProtected(change_page_designs, 'getTemplate')
- def getTemplate(self):
- # To be overridden
- raise NotImplementedError
-
-
- security.declareProtected(change_page_designs, 'getPalette')
- def getPalette(self):
- # To be overridden
- raise NotImplementedError
-
security.declareProtected(change_page_designs, 'addSlot')
def addSlot(self, name):
@@ -159,6 +180,31 @@
RESPONSE.redirect(self.absolute_url() + '/editForm')
+ security.declareProtected(change_page_designs, 'addElements')
+ def addElements(self, source_paths=(), target_path='', REQUEST=None):
+ """Add elements to the page design."""
+ elements = []
+ for source_path in source_paths:
+ source = self.getPhysicalRoot().restrictedTraverse(source_path)
+ if IClipboardSource.isImplementedBy(source):
+ getSecurityManager().validate(
+ source, source, 'cut', source.cut)
+ element = source.cut()
+ else:
+ element = ElementReference(source)
+ elements.append(element)
+
+ target = self.getPhysicalRoot().restrictedTraverse(target_path)
+ if not IClipboardTarget.isImplementedBy(target):
+ raise DesignError, 'moveElement: bad or missing target_path'
+ getSecurityManager().validate(target, target,
+ 'paste', target.paste)
+
+ target.paste(elements)
+ if REQUEST is not None:
+ return self.dialog_done_html
+
+
security.declareProtected(change_page_designs, 'getSlotNames')
def getSlotNames(self):
"""Returns the names of all slots filled and declared by the template.
@@ -176,11 +222,47 @@
return res
- security.declareProtected(change_page_designs, 'addElementDialog')
- def addElementDialog(self, target_path):
- """Shows the add element dialog box."""
- palette = self.getPalette()
- return palette.addElementDialog(target_path=target_path)
+ security.declareProtected(change_page_designs, 'getTemplate')
+ def getTemplate(self):
+ id = self.template_id
+ if not id:
+ raise DesignError, 'No template configured'
+ return guarded_getattr(aq_parent(aq_inner(self)), id)
+
+
+ security.declareProtected(change_page_designs, 'getDefaultPaletteId')
+ def getDefaultPaletteId(self):
+ return self.default_palette_id
+
+
+ security.declareProtected(change_page_designs, 'getPaletteIds')
+ def getPaletteIds(self):
+ #meta_types = self.all_meta_types(interfaces=(IPalette,))
+ meta_types = ('Folder',) # Quick hack ;-)
+ values = self.superValues(meta_types)
+ res = {}
+ for v in values:
+ res[v.getId()] = 1
+ res = res.keys()
+ res.sort()
+ return res
+
+
+ security.declareProtected(change_page_designs, 'getPalette')
+ def getPalette(self, id):
+ pal = guarded_getattr(aq_parent(aq_inner(self)), id)
+ #if not IPalette.isImplementedBy(pal):
+ # raise DesignError, 'Not a palette'
+ return pal
+
+
+ security.declareProtected(change_page_designs, 'getPaletteContents')
+ def getPaletteContents(self, palette_id, REQUEST=None):
+ pal = self.getPalette(palette_id)
+ res = pal.objectValues()
+ # TODO: sort and batch based on REQUEST data:
+ # sort_on, sort_order, b_start
+ return res
security.declarePrivate('insertEditScripts')
@@ -267,25 +349,8 @@
_properties = (
{'id': 'title', 'type': 'string', 'mode': 'w'},
{'id': 'template_id', 'type': 'string', 'mode': 'w'},
- {'id': 'palette_id', 'type': 'string', 'mode': 'w'},
+ {'id': 'default_palette_id', 'type': 'string', 'mode': 'w'},
)
- template_id = None
- palette_id = None
- title = ''
-
- security.declareProtected(change_page_designs, 'getTemplate')
- def getTemplate(self):
- id = self.template_id
- if not id:
- raise DesignError, 'No template configured'
- return getattr(aq_parent(aq_inner(self)), id)
-
- security.declareProtected(change_page_designs, 'getPalette')
- def getPalette(self):
- id = self.palette_id
- if not id:
- raise DesignError, 'No palette configured'
- return getattr(aq_parent(aq_inner(self)), id)
security.declareProtected(change_page_designs, 'manage_propertiesForm')
def manage_propertiesForm(self, client=None, REQUEST=None,
=== Products/PageDesign/Slot.py 1.1.2.3 => 1.1.2.4 ===
--- Products/PageDesign/Slot.py:1.1.2.3 Tue Aug 6 22:37:22 2002
+++ Products/PageDesign/Slot.py Wed Aug 7 23:57:06 2002
@@ -61,11 +61,14 @@
security = ClassSecurityInfo()
# Clipboard traversal helpers.
+ security.declarePublic('elementSources', 'elementTargets',
+ 'lastElementTarget')
elementSources = SlotElementTraverser(
'elementSources', SlotElementClipboardSource)
elementTargets = SlotElementTraverser(
'elementTargets', SlotElementClipboardTarget)
- lastElementTarget = SlotElementClipboardLastTarget
+ lastElementTarget = SlotElementClipboardLastTarget()
+
target_html = '''<div class="design-target" align="center"
id="%(clipboard_path)s"><a href="#"
=== Products/PageDesign/SlotElementClipboardSource.py 1.1.2.1 => 1.1.2.2 ===
--- Products/PageDesign/SlotElementClipboardSource.py:1.1.2.1 Sat Aug 3 15:58:03 2002
+++ Products/PageDesign/SlotElementClipboardSource.py Wed Aug 7 23:57:06 2002
@@ -14,21 +14,29 @@
import Acquisition
+import Globals
from Acquisition import aq_base, aq_inner, aq_parent
+from AccessControl import ClassSecurityInfo
from IClipboardSource import IClipboardSource
from IIndexedSlot import IIndexedSlot
+# Permission name
+change_page_designs = 'Change Page Designs'
+
class SlotElementClipboardSource (Acquisition.Explicit):
__implements__ = IClipboardSource
+ security = ClassSecurityInfo()
+
def __init__(self, index):
index = int(index)
slot = aq_parent(aq_inner(self))
assert IIndexedSlot.isImplementedBy(slot)
self.element = slot.getElement(index)
+ security.declareProtected(change_page_designs, 'cut')
def cut(self):
slot = aq_parent(aq_inner(self))
assert IIndexedSlot.isImplementedBy(slot)
@@ -36,3 +44,4 @@
slot.remove(element)
return element
+Globals.InitializeClass(SlotElementClipboardSource)
=== Products/PageDesign/SlotElementClipboardTarget.py 1.1.2.1 => 1.1.2.2 ===
--- Products/PageDesign/SlotElementClipboardTarget.py:1.1.2.1 Sat Aug 3 15:58:03 2002
+++ Products/PageDesign/SlotElementClipboardTarget.py Wed Aug 7 23:57:06 2002
@@ -13,29 +13,46 @@
##############################################################################
import Acquisition
+import Globals
from Acquisition import aq_base, aq_inner, aq_parent
+from AccessControl import ClassSecurityInfo
from IClipboardTarget import IClipboardTarget
+# Permission name
+change_page_designs = 'Change Page Designs'
+
class SlotElementClipboardTarget (Acquisition.Explicit):
__implements__ = IClipboardTarget
+ security = ClassSecurityInfo()
+
def __init__(self, index):
index = int(index)
slot = aq_parent(aq_inner(self))
self.before_element = slot.getElement(index)
+ security.declareProtected(change_page_designs, 'paste')
def paste(self, elements):
slot = aq_parent(aq_inner(self))
slot.insertBefore(aq_base(self.before_element), elements)
+Globals.InitializeClass(SlotElementClipboardTarget)
+
class SlotElementClipboardLastTarget (Acquisition.Explicit):
__implements__ = IClipboardTarget
+ __roles__ = None # ugh
+
+ security = ClassSecurityInfo()
+
+ security.declareProtected(change_page_designs, 'paste')
def paste(self, elements):
slot = aq_parent(aq_inner(self))
slot.insertBefore(None, elements)
+
+Globals.InitializeClass(SlotElementClipboardLastTarget)
=== Products/PageDesign/SlotElementTraverser.py 1.1.2.2 => 1.1.2.3 ===
--- Products/PageDesign/SlotElementTraverser.py:1.1.2.2 Mon Aug 5 21:28:27 2002
+++ Products/PageDesign/SlotElementTraverser.py Wed Aug 7 23:57:06 2002
@@ -13,18 +13,25 @@
##############################################################################
import Acquisition
+import Globals
+from AccessControl import ClassSecurityInfo
from OFS.Traversable import Traversable
class SlotElementTraverser (Acquisition.Explicit, Traversable):
+ security = ClassSecurityInfo()
+ security.setDefaultAccess('allow')
+
def __init__(self, id, item_factory):
self.id = id
- self.item_factory = item_factory
+ self._item_factory = item_factory
def getId(self):
return self.id
def __getitem__(self, name):
- return self.item_factory(name).__of__(self)
+ return self._item_factory(name).__of__(self)
+
+Globals.InitializeClass(SlotElementTraverser)