Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
da476c61
Commit
da476c61
authored
Aug 14, 1998
by
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added multiple copy, paste, rename
parent
ee6c5127
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
474 additions
and
301 deletions
+474
-301
lib/python/OFS/CopySupport.py
lib/python/OFS/CopySupport.py
+321
-190
lib/python/OFS/Folder.py
lib/python/OFS/Folder.py
+4
-3
lib/python/OFS/Moniker.py
lib/python/OFS/Moniker.py
+26
-22
lib/python/OFS/ObjectManager.py
lib/python/OFS/ObjectManager.py
+40
-70
lib/python/OFS/main.dtml
lib/python/OFS/main.dtml
+19
-16
lib/python/OFS/renameForm.dtml
lib/python/OFS/renameForm.dtml
+64
-0
No files found.
lib/python/OFS/CopySupport.py
View file @
da476c61
"""Copy interface"""
__doc__
=
"""Copy interface"""
__version__
=
'$Revision: 1.18 $'
[
11
:
-
2
]
__version__
=
'$Revision: 1.17 $'
[
11
:
-
2
]
import
Globals
,
Moniker
,
rPickle
,
tempfile
import
sys
,
Globals
,
Moniker
,
rPickle
,
tempfile
from
cPickle
import
loads
,
dumps
from
urllib
import
quote
,
unquote
from
App.Dialogs
import
MessageDialog
rPickle
.
register
(
'OFS.Moniker'
,
'Moniker'
,
Moniker
.
Moniker
)
CopyError
=
'Copy Error'
class
CopyContainer
:
# Interface for containerish objects which allow
# objects to be copied into them.
# Interface for containerish objects which allow cut/copy/paste
def
manage_cutObjects
(
self
,
ids
,
REQUEST
=
None
):
"""Put a reference to the objects named in ids in the clip board"""
if
type
(
ids
)
is
type
(
''
):
ids
=
[
ids
]
oblist
=
[]
for
id
in
ids
:
ob
=
getattr
(
self
,
id
)
if
not
ob
.
cb_isMoveable
():
raise
CopyError
,
eNotSupported
%
id
m
=
Moniker
.
Moniker
(
ob
)
oblist
.
append
((
m
.
jar
,
m
.
ids
))
cp
=
(
1
,
oblist
)
cp
=
quote
(
dumps
(
cp
))
if
REQUEST
is
not
None
:
resp
=
REQUEST
[
'RESPONSE'
]
resp
.
setCookie
(
'__cp'
,
cp
,
path
=
'%s'
%
REQUEST
[
'SCRIPT_NAME'
])
return
self
.
manage_main
(
self
,
REQUEST
,
cb_dataValid
=
1
)
return
cp
def
manage_copyObjects
(
self
,
ids
,
REQUEST
=
None
,
RESPONSE
=
None
):
"""Put a reference to the objects named in ids in the clip board"""
if
type
(
ids
)
is
type
(
''
):
ids
=
[
ids
]
oblist
=
[]
for
id
in
ids
:
ob
=
getattr
(
self
,
id
)
if
not
ob
.
cb_isCopyable
():
raise
CopyError
,
eNotSupported
%
id
m
=
Moniker
.
Moniker
(
ob
)
oblist
.
append
((
m
.
jar
,
m
.
ids
))
cp
=
(
0
,
oblist
)
cp
=
quote
(
dumps
(
cp
))
if
REQUEST
is
not
None
:
resp
=
REQUEST
[
'RESPONSE'
]
resp
.
setCookie
(
'__cp'
,
cp
,
path
=
'%s'
%
REQUEST
[
'SCRIPT_NAME'
])
return
self
.
manage_main
(
self
,
REQUEST
,
cb_dataValid
=
1
)
return
cp
def
manage_pasteObjects
(
self
,
cb_copy_data
=
None
,
REQUEST
=
None
):
"""Paste previously copied objects into the current object.
If calling manage_pasteObjects from python code, pass
the result of a previous call to manage_cutObjects or
manage_copyObjects as the first argument."""
cp
=
None
if
cb_copy_data
is
not
None
:
cp
=
cb_copy_data
else
:
if
REQUEST
and
REQUEST
.
has_key
(
'__cp'
):
cp
=
REQUEST
[
'__cp'
]
if
cp
is
None
:
raise
CopyError
,
eNoData
try
:
cp
=
rPickle
.
loads
(
unquote
(
cp
))
except
:
raise
CopyError
,
eInvalid
oblist
=
[]
m
=
Moniker
.
Moniker
()
op
=
cp
[
0
]
for
j
,
d
in
cp
[
1
]:
m
.
jar
=
j
m
.
ids
=
d
try
:
ob
=
m
.
bind
()
except
:
raise
CopyError
,
eNotFound
self
.
_verifyObjectPaste
(
ob
,
REQUEST
)
try
:
ob
.
_notifyOfCopyTo
(
self
,
op
=
op
)
except
:
raise
CopyError
,
MessageDialog
(
title
=
'Copy Error'
,
message
=
sys
.
exc_value
,
action
=
'manage_main'
)
oblist
.
append
(
ob
)
if
op
==
0
:
# Copy operation
for
ob
in
oblist
:
if
not
ob
.
cb_isCopyable
():
raise
CopyError
,
eNotSupported
%
absattr
(
ob
.
id
)
id
=
_get_id
(
self
,
absattr
(
ob
.
id
))
ob
=
ob
.
_getCopy
(
self
)
ob
.
_setId
(
id
)
self
.
_setObject
(
id
,
ob
)
ob
=
ob
.
__of__
(
self
)
ob
.
_postCopy
(
self
,
op
=
0
)
if
REQUEST
is
not
None
:
return
self
.
manage_main
(
self
,
REQUEST
,
update_menu
=
1
,
cb_dataValid
=
1
)
if
op
==
1
:
# Move operation
for
ob
in
oblist
:
id
=
absattr
(
ob
.
id
)
if
not
ob
.
cb_isMoveable
():
raise
CopyError
,
eNotSupported
%
id
ob
.
aq_parent
.
_delObject
(
id
)
if
hasattr
(
ob
,
'aq_base'
):
ob
=
ob
.
aq_base
id
=
_get_id
(
self
,
id
)
self
.
_setObject
(
id
,
ob
)
ob
=
ob
.
__of__
(
self
)
ob
.
_setId
(
id
)
ob
.
_postCopy
(
self
,
op
=
1
)
if
REQUEST
is
not
None
:
REQUEST
[
'RESPONSE'
].
setCookie
(
'cp_'
,
'deleted'
,
path
=
'%s'
%
REQUEST
[
'SCRIPT_NAME'
],
expires
=
'Wed, 31-Dec-97 23:59:59 GMT'
)
return
self
.
manage_main
(
self
,
REQUEST
,
update_menu
=
1
,
cb_dataValid
=
0
)
return
''
pasteDialog
=
Globals
.
HTMLFile
(
'pasteDialog'
,
globals
())
def
_getMoniker
(
self
):
# Ask an object to return a moniker for itself.
return
Moniker
.
Moniker
(
self
)
manage_renameForm
=
Globals
.
HTMLFile
(
'renameForm'
,
globals
())
def
validClipData
(
self
):
# Return true if clipboard data is valid.
try
:
moniker
=
rPickle
.
loads
(
unquote
(
self
.
REQUEST
[
'clip_data'
]))
def
manage_renameObject
(
self
,
id
,
new_id
,
REQUEST
=
None
):
"""Rename a particular sub-object"""
try
:
self
.
_checkId
(
new_id
)
except
:
raise
CopyError
,
MessageDialog
(
title
=
'Invalid Id'
,
message
=
sys
.
exc_value
,
action
=
'manage_main'
)
ob
=
getattr
(
self
,
id
)
if
not
ob
.
cb_isMoveable
():
raise
CopyError
,
eNotSupported
%
id
self
.
_verifyObjectPaste
(
ob
,
REQUEST
)
try
:
ob
.
_notifyOfCopyTo
(
self
,
op
=
1
)
except
:
raise
CopyError
,
MessageDialog
(
title
=
'Rename Error'
,
message
=
sys
.
exc_value
,
action
=
'manage_main'
)
self
.
_delObject
(
id
)
if
hasattr
(
ob
,
'aq_base'
):
ob
=
ob
.
aq_base
self
.
_setObject
(
new_id
,
ob
)
ob
=
ob
.
__of__
(
self
)
ob
.
_setId
(
new_id
)
ob
.
_postCopy
(
self
,
op
=
1
)
if
REQUEST
is
not
None
:
return
self
.
manage_main
(
self
,
REQUEST
,
update_menu
=
1
)
return
None
def
manage_clone
(
self
,
ob
,
id
,
REQUEST
=
None
):
"""Clone an object, creating a new object with the given id."""
if
not
ob
.
cb_isCopyable
():
raise
CopyError
,
eNotSupported
%
absattr
(
ob
.
id
)
try
:
self
.
_checkId
(
id
)
except
:
raise
CopyError
,
MessageDialog
(
title
=
'Invalid Id'
,
message
=
sys
.
exc_value
,
action
=
'manage_main'
)
self
.
_verifyObjectPaste
(
ob
,
REQUEST
)
try
:
ob
.
_notifyOfCopyTo
(
self
,
op
=
0
)
except
:
raise
CopyError
,
MessageDialog
(
title
=
'Rename Error'
,
message
=
sys
.
exc_value
,
action
=
'manage_main'
)
ob
=
ob
.
_getCopy
(
self
)
ob
.
_setId
(
id
)
self
.
_setObject
(
id
,
ob
)
ob
=
ob
.
__of__
(
self
)
ob
.
_postCopy
(
self
,
op
=
0
)
return
ob
def
cb_dataValid
(
self
):
# Return true if clipboard data seems valid.
try
:
data
=
rPickle
.
loads
(
unquote
(
self
.
REQUEST
[
'__cp'
]))
except
:
return
0
# Check for old versions of cookie so users dont need to
# restart browser after upgrading - just expire the old
# cookie.
if
not
hasattr
(
moniker
,
'op'
):
self
.
REQUEST
[
'RESPONSE'
].
setCookie
(
'clip_data'
,
'deleted'
,
path
=
'%s'
%
self
.
REQUEST
[
'SCRIPT_NAME'
],
expires
=
'Wed, 31-Dec-97 23:59:59 GMT'
)
self
.
REQUEST
[
'validClipData'
]
=
0
return
0
v
=
self
.
REQUEST
[
'validClipData'
]
=
moniker
.
assert
()
return
v
def
_verifyCopySource
(
self
,
src
,
REQUEST
):
if
not
hasattr
(
src
,
'meta_type'
):
raise
'Invalid copy source'
,
(
'''You cannot copy this object, because
the typ of the source object is unknown.<p>
'''
)
mt
=
src
.
meta_type
return
1
def
cb_dataItems
(
self
):
try
:
cp
=
rPickle
.
loads
(
unquote
(
self
.
REQUEST
[
'__cp'
]))
except
:
return
[]
oblist
=
[]
m
=
Moniker
.
Moniker
()
op
=
cp
[
0
]
for
j
,
d
in
cp
[
1
]:
m
.
jar
=
j
m
.
ids
=
d
oblist
.
append
(
m
.
bind
())
return
oblist
validClipData
=
cb_dataValid
def
_verifyObjectPaste
(
self
,
ob
,
REQUEST
):
if
not
hasattr
(
ob
,
'meta_type'
):
raise
CopyError
,
MessageDialog
(
title
=
'Not Supported'
,
message
=
'The object <EM>%s</EM> does not support this '
\
'operation'
%
absattr
(
ob
.
id
),
action
=
'manage_main'
)
mt
=
ob
.
meta_type
if
not
hasattr
(
self
,
'all_meta_types'
):
raise
'Invalid Copy Destination'
,
(
'''You cannot copy objects to this destination because
it is an invalid destination.<p>
'''
)
raise
CopyError
,
MessageDialog
(
title
=
'Not Supported'
,
message
=
'Cannot paste into this object.'
,
action
=
'manage_main'
)
method_name
=
None
meta_types
=
self
.
all_meta_types
(
)
meta_types
=
absattr
(
self
.
all_meta_types
)
for
d
in
meta_types
:
if
d
[
'name'
]
==
mt
:
method_name
=
d
[
'action'
]
break
if
method_name
is
not
None
:
if
hasattr
(
self
,
method_name
):
meth
=
getattr
(
self
,
method_name
)
...
...
@@ -68,180 +223,156 @@ class CopyContainer:
if
(
not
hasattr
(
user
,
'hasRole'
)
or
not
user
.
hasRole
(
None
,
roles
)):
raise
'Unauthorized'
,
(
'''
You are not authorized to perform this
operation.<p>
'''
)
"""
You are not authorized to perform this
operation."""
)
return
raise
'Invalid copy source'
,
(
'''You cannot copy this object, because
the type of the source object is unrecognized.<p>
'''
)
def
pasteFromClipboard
(
self
,
clip_id
=
''
,
clip_data
=
''
,
REQUEST
=
None
):
""" """
if
not
clip_data
:
return
eNoData
try
:
moniker
=
rPickle
.
loads
(
unquote
(
clip_data
))
except
:
return
eInvalid
if
not
clip_id
:
return
self
.
pasteDialog
(
self
,
REQUEST
,
bad
=
0
,
moniker
=
(
moniker
,))
try
:
self
.
_checkId
(
clip_id
)
except
:
return
self
.
pasteDialog
(
self
,
REQUEST
,
bad
=
1
,
moniker
=
(
moniker
,))
return
self
.
manage_paste
(
moniker
,
clip_id
,
REQUEST
)
def
manage_paste
(
self
,
moniker
,
clip_id
,
REQUEST
=
None
):
try
:
obj
=
moniker
.
bind
()
except
:
return
eNotFound
self
.
_verifyCopySource
(
obj
,
REQUEST
)
if
moniker
.
op
==
0
:
# Copy operation
obj
=
obj
.
_getCopy
(
self
)
obj
.
_setId
(
clip_id
)
self
.
_setObject
(
clip_id
,
obj
)
obj
=
obj
.
__of__
(
self
)
obj
.
_postCopy
(
self
)
if
REQUEST
is
not
None
:
return
self
.
manage_main
(
self
,
REQUEST
,
update_menu
=
1
)
return
''
if
moniker
.
op
==
1
:
# Move operation
prev_id
=
Moniker
.
absattr
(
obj
.
id
)
# Check for special object!
try
:
r
=
obj
.
aq_parent
.
_reserved_names
except
:
r
=
()
if
prev_id
in
r
:
raise
'NotSupported'
,
Globals
.
MessageDialog
(
title
=
'Not Supported'
,
message
=
'This item cannot be cut and pasted'
,
action
=
'manage_main'
)
obj
.
aq_parent
.
_delObject
(
prev_id
)
if
hasattr
(
obj
,
'aq_base'
):
obj
=
obj
.
aq_base
self
.
_setObject
(
clip_id
,
obj
)
obj
=
obj
.
__of__
(
self
)
obj
.
_setId
(
clip_id
)
obj
.
_postMove
(
self
)
if
REQUEST
is
not
None
:
# Remove cookie after a move
REQUEST
[
'RESPONSE'
].
setCookie
(
'clip_data'
,
'deleted'
,
path
=
'%s'
%
REQUEST
[
'SCRIPT_NAME'
],
expires
=
'Wed, 31-Dec-97 23:59:59 GMT'
)
return
self
.
manage_main
(
self
,
REQUEST
,
update_menu
=
1
,
validClipData
=
0
)
return
''
def
manage_clone
(
self
,
obj
,
clip_id
,
REQUEST
=
None
):
"""Clone an object
By creating a new object with a different given id.
"""
self
.
_verifyCopySource
(
obj
,
REQUEST
)
obj
=
obj
.
_getCopy
(
self
)
obj
.
_setId
(
clip_id
)
self
.
_setObject
(
clip_id
,
obj
)
obj
=
obj
.
__of__
(
self
)
obj
.
_postCopy
(
self
)
return
obj
raise
CopyError
,
MessageDialog
(
title
=
'Not Supported'
,
message
=
'The object <EM>%s</EM> does not support this '
\
'operation'
%
absattr
(
ob
.
id
),
action
=
'manage_main'
)
Globals
.
default__class_init__
(
CopyContainer
)
class
CopySource
:
# Interface for objects which allow themselves to be copied.
def
_getMoniker
(
self
):
# Ask an object to return a moniker for itself.
return
Moniker
.
Moniker
(
self
)
def
_notifyOfCopyTo
(
self
,
container
):
# Overide this to be pickly about where you go!
# If you don't want to go there, then raise an exception.
def
_canCopy
(
self
,
op
=
0
):
# Called to make sure this object is copyable. The op var
# is 0 for a copy, 1 for a move.
return
1
def
_notifyOfCopyTo
(
self
,
container
,
op
=
0
):
# Overide this to be pickly about where you go! If you dont
# want to go there, raise an exception. The op variable is
# 0 for a copy, 1 for a move.
pass
def
_getCopy
(
self
,
container
):
# Ask an object for a new copy of itself.
self
.
_notifyOfCopyTo
(
container
)
f
=
tempfile
.
TemporaryFile
()
self
.
_p_jar
.
export_file
(
self
,
f
)
f
.
seek
(
0
)
r
=
container
.
_p_jar
.
import_file
(
f
)
ob
=
container
.
_p_jar
.
import_file
(
f
)
f
.
close
()
return
r
return
ob
def
_postCopy
(
self
,
container
):
# Called after the copy is finished to accomodate special cases
def
_postCopy
(
self
,
container
,
op
=
0
):
# Called after the copy is finished to accomodate special cases.
# The op var is 0 for a copy, 1 for a move.
pass
def
_postMove
(
self
,
container
):
# Called after a move is finished to accomodate special cases
pass
def
_setId
(
self
,
id
):
# Called to set the new id of a copied object.
self
.
id
=
id
def
copyToClipboard
(
self
,
REQUEST
):
""" """
# Set a cookie containing pickled moniker
try
:
m
=
self
.
_getMoniker
()
except
:
return
eNotSupported
m
.
op
=
0
REQUEST
[
'RESPONSE'
].
setCookie
(
'clip_data'
,
quote
(
dumps
(
m
,
1
)),
path
=
'%s'
%
REQUEST
[
'SCRIPT_NAME'
])
def
cutToClipboard
(
self
,
REQUEST
):
""" """
# Set a cookie containing pickled moniker
try
:
m
=
self
.
_getMoniker
()
except
:
return
eNotSupported
m
.
op
=
1
REQUEST
[
'RESPONSE'
].
setCookie
(
'clip_data'
,
quote
(
dumps
(
m
,
1
)),
path
=
'%s'
%
REQUEST
[
'SCRIPT_NAME'
])
# Predefined errors
eNoData
=
Globals
.
MessageDialog
(
def
cb_isCopyable
(
self
):
if
not
(
hasattr
(
self
,
'_canCopy'
)
and
self
.
_canCopy
(
0
)):
return
0
if
hasattr
(
self
,
'_p_jar'
)
and
self
.
_p_jar
is
None
:
return
0
return
1
def
cb_isMoveable
(
self
):
if
not
(
hasattr
(
self
,
'_canCopy'
)
and
self
.
_canCopy
(
1
)):
return
0
if
hasattr
(
self
,
'_p_jar'
)
and
self
.
_p_jar
is
None
:
return
0
try
:
n
=
self
.
aq_parent
.
_reserved_names
except
:
n
=
()
if
absattr
(
self
.
id
)
in
n
:
return
0
return
1
def
absattr
(
attr
):
if
callable
(
attr
):
return
attr
()
return
attr
def
_get_id
(
ob
,
id
):
try
:
ob
=
ob
.
aq_base
except
:
pass
n
=
0
if
id
[
8
:]
==
'copy_of_'
:
n
=
1
while
(
hasattr
(
ob
,
id
)):
id
=
'copy%s_of_%s'
%
(
n
and
n
+
1
or
''
,
id
)
n
=
n
+
1
return
id
fMessageDialog
=
Globals
.
HTML
(
"""
<HTML>
<HEAD>
<TITLE><!--#var title--></TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<FORM ACTION="<!--#var action-->" METHOD="GET"
<!--#if target-->
TARGET="<!--#var target-->"
<!--#/if target-->>
<TABLE BORDER="0" WIDTH="100%%" CELLPADDING="10">
<TR>
<TD VALIGN="TOP">
<BR>
<CENTER><B><FONT SIZE="+6" COLOR="#77003B">!</FONT></B></CENTER>
</TD>
<TD VALIGN="TOP">
<BR><BR>
<CENTER>
<!--#var message-->
</CENTER>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">
</TD>
<TD VALIGN="TOP">
<CENTER>
<INPUT TYPE="SUBMIT" VALUE=" Ok ">
</CENTER>
</TD>
</TR>
</TABLE>
</FORM>
</BODY></HTML>"""
,
target
=
''
,
action
=
'manage_main'
,
title
=
'Changed'
)
eNoData
=
MessageDialog
(
title
=
'No Data'
,
message
=
'No clipboard data
to be pasted
'
,
action
=
'
./
manage_main'
,)
message
=
'No clipboard data
found.
'
,
action
=
'manage_main'
,)
eInvalid
=
Globals
.
MessageDialog
(
eInvalid
=
MessageDialog
(
title
=
'Clipboard Error'
,
message
=
'Clipboard data could not be read '
\
'or is not supported in this installation'
,
action
=
'./manage_main'
,)
message
=
'The data in the clipboard could not be read, possibly due '
\
'to cookie data being truncated by your web browser. Try copying '
\
'fewer objects.'
,
action
=
'manage_main'
,)
eNotFound
=
MessageDialog
(
title
=
'Item Not Found'
,
message
=
'One or more items referred to in the clipboard data was '
\
'not found. The item may have been moved or deleted after you '
\
'copied it.'
,
action
=
'manage_main'
,)
eNotSupported
=
fMessageDialog
(
title
=
'Not Supported'
,
message
=
'The item <EM>%s</EM> does not support this operation.'
,
action
=
'manage_main'
,)
eNotFound
=
Globals
.
MessageDialog
(
title
=
'Clipboard Error'
,
message
=
'The item referenced by the '
\
'clipboard data was not found'
,
action
=
'./manage_main'
,)
eNotSupported
=
Globals
.
MessageDialog
(
title
=
'Not Supported'
,
message
=
'Operation not supported for the selected item'
,
action
=
'./manage_main'
,)
##############################################################################
#
# $Log: CopySupport.py,v $
# Revision 1.18 1998/08/14 16:46:35 brian
# Added multiple copy, paste, rename
#
lib/python/OFS/Folder.py
View file @
da476c61
"""Folder object
$Id: Folder.py,v 1.5
0 1998/08/05 21:04:04
brian Exp $"""
$Id: Folder.py,v 1.5
1 1998/08/14 16:46:35
brian Exp $"""
__version__
=
'$Revision: 1.5
0
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.5
1
$'
[
11
:
-
2
]
from
Globals
import
HTMLFile
...
...
@@ -71,7 +71,8 @@ class Folder(ObjectManager,RoleManager,DocumentHandler,
(
'View management screens'
,
(
'manage'
,
'manage_menu'
,
'manage_main'
,
'manage_copyright'
,
'manage_tabs'
,
'manage_propertiesForm'
,
'manage_UndoForm'
,
'manage_copyObject'
,
'manage_pasteObject'
,
'manage_cutObjects'
,
'manage_copyObjects'
,
'manage_pasteObjects'
,
'manage_renameForm'
,
'manage_renameObject'
,
'manage_findFrame'
,
'manage_findForm'
,
'manage_findAdv'
,
'manage_findResult'
,
'manage_findOpt'
)),
(
'Access contents information'
,
...
...
lib/python/OFS/Moniker.py
View file @
da476c61
"""
Object monikers
"""Object monikers
An object moniker is an intelligent reference to a
persistent object. A moniker can be turned back into
...
...
@@ -7,30 +6,25 @@ Object monikers
and aquisition relationships via a simple interface.
"""
__version__
=
'$Revision: 1.4 $'
[
11
:
-
2
]
__version__
=
'$Revision: 1.5 $'
[
11
:
-
2
]
import
Globals
class
Moniker
:
""" """
def
__init__
(
self
,
ob
j
=
None
,
op
=
0
):
if
ob
j
is
None
:
return
pd
=
[]
ob
=
obj
def
__init__
(
self
,
ob
=
None
):
if
ob
is
None
:
return
self
.
jar
=
ob
.
_p_jar
.
name
self
.
ids
=
[]
while
1
:
if
not
hasattr
(
ob
,
'_p_oid'
):
break
pd
.
append
(
ob
.
_p_oid
)
self
.
ids
.
append
(
ob
.
_p_oid
)
if
not
hasattr
(
ob
,
'aq_parent'
):
break
ob
=
ob
.
aq_parent
pd
.
reverse
()
self
.
pd
=
pd
self
.
jr
=
obj
.
_p_jar
.
name
self
.
op
=
op
self
.
ids
.
reverse
()
def
id
(
self
):
return
absattr
(
self
.
bind
().
id
)
...
...
@@ -40,33 +34,43 @@ class Moniker:
def
assert
(
self
):
# Return true if the named object exists
if
self
.
jr
is
None
:
jar
=
Globals
.
Bobobase
.
_jar
else
:
jar
=
Globals
.
SessionBase
[
self
.
jr
].
jar
for
n
in
self
.
pd
:
if
self
.
j
a
r
is
None
:
jar
=
Globals
.
Bobobase
.
_jar
else
:
jar
=
Globals
.
SessionBase
[
self
.
j
a
r
].
jar
for
n
in
self
.
ids
:
if
not
jar
.
has_key
(
n
):
return
0
return
1
def
bind
(
self
):
# Return the real object named by this moniker
if
self
.
jr
is
None
:
jar
=
Globals
.
Bobobase
.
_jar
else
:
jar
=
Globals
.
SessionBase
[
self
.
jr
].
jar
if
self
.
j
a
r
is
None
:
jar
=
Globals
.
Bobobase
.
_jar
else
:
jar
=
Globals
.
SessionBase
[
self
.
j
a
r
].
jar
ob
=
None
for
n
in
self
.
pd
:
for
n
in
self
.
ids
:
o
=
jar
[
n
]
if
ob
is
not
None
:
o
=
o
.
__of__
(
ob
)
ob
=
o
return
ob
def
exact
(
self
,
o
ther
):
def
exact
(
self
,
o
b
):
# Check against another moniker to see if it
# refers to the exact same object in the exact
# same acquisition context.
return
self
.
j
r
==
other
.
jr
and
self
.
pd
==
other
.
pd
return
self
.
j
ar
==
ob
.
jar
and
self
.
ids
==
ob
.
ids
def
absattr
(
attr
):
if
callable
(
attr
):
return
attr
()
return
attr
##############################################################################
#
# $Log: Moniker.py,v $
# Revision 1.5 1998/08/14 16:46:36 brian
# Added multiple copy, paste, rename
#
lib/python/OFS/ObjectManager.py
View file @
da476c61
__doc__
=
"""Object Manager
$Id: ObjectManager.py,v 1.4
4 1998/08/03 13:32:00 jim
Exp $"""
$Id: ObjectManager.py,v 1.4
5 1998/08/14 16:46:36 brian
Exp $"""
__version__
=
'$Revision: 1.4
4
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.4
5
$'
[
11
:
-
2
]
import
Persistence
,
App
.
Management
,
Acquisition
,
App
.
Undo
,
Globals
import
App.FactoryDispatcher
...
...
@@ -106,15 +106,29 @@ class ObjectManager(
return
()
def
_setObject
(
self
,
id
,
object
,
roles
=
None
,
user
=
None
):
self
.
_checkId
(
id
)
setattr
(
self
,
id
,
object
)
try
:
t
=
object
.
meta_type
except
:
t
=
None
self
.
_objects
=
self
.
_objects
+
({
'id'
:
id
,
'meta_type'
:
t
},)
# This is a nasty hack that provides a workaround for any
# existing customers with the acl_users/__allow_groups__
# bug. Basically when you add an object, we'll do the check
# an make the fix if necessary.
have
=
self
.
__dict__
.
has_key
if
have
(
'__allow_groups__'
)
and
(
not
have
(
'acl_users'
)):
delattr
(
self
,
'__allow_groups__'
)
def
_delObject
(
self
,
id
):
delattr
(
self
,
id
)
if
id
==
'acl_users'
:
# Yikes - acl_users is referred to by two names and
# must be treated as a special case!
try
:
delattr
(
self
,
'__allow_groups__'
)
except
:
pass
self
.
_objects
=
tuple
(
filter
(
lambda
i
,
n
=
id
:
i
[
'id'
]
!=
n
,
self
.
_objects
))
def
objectIds
(
self
,
spec
=
None
):
...
...
@@ -284,80 +298,33 @@ class ObjectManager(
manage_addProduct
=
App
.
FactoryDispatcher
.
ProductDispatcher
()
def
manage_cutObject
(
self
,
ids
,
REQUEST
=
None
):
"""Put a reference to an object, with the given id, in the clip board
The object is marked for deletion on paste. This is essentially
the first step in a move.
"""
if
type
(
ids
)
is
not
type
(
''
):
if
len
(
ids
)
!=
1
:
return
MessageDialog
(
title
=
'Invalid Selection'
,
message
=
'Please select one and only one item to move'
,
action
=
'./manage_main'
,)
ids
=
ids
[
0
]
obj
=
getattr
(
self
,
ids
)
err
=
obj
.
cutToClipboard
(
REQUEST
)
return
err
or
self
.
manage_main
(
self
,
REQUEST
,
validClipData
=
1
)
def
manage_copyObject
(
self
,
ids
,
REQUEST
=
None
):
"""Put a reference to an object, with the given id, in the clip board
"""
if
type
(
ids
)
is
not
type
(
''
):
if
len
(
ids
)
!=
1
:
return
MessageDialog
(
title
=
'Invalid Selection'
,
message
=
'Please select one and only one item to move'
,
action
=
'./manage_main'
,)
ids
=
ids
[
0
]
obj
=
getattr
(
self
,
ids
)
err
=
obj
.
copyToClipboard
(
REQUEST
)
return
err
or
self
.
manage_main
(
self
,
REQUEST
,
validClipData
=
1
)
def
manage_pasteObject
(
self
,
clip_id
=
''
,
clip_data
=
''
,
REQUEST
=
None
):
"""Paste from the clip board into the current object."""
return
self
.
pasteFromClipboard
(
clip_id
,
clip_data
,
REQUEST
)
def
manage_delObjects
(
self
,
ids
=
[],
submit
=
'Delete'
,
clip_id
=
''
,
clip_data
=
''
,
REQUEST
=
None
):
def
manage_delObjects
(
self
,
ids
=
[],
REQUEST
=
None
):
"""Delete a subordinate object
The objects specified in 'ids' get deleted.
"""
if
type
(
ids
)
is
type
(
''
):
ids
=
[
ids
]
if
submit
==
'Delete'
:
if
not
ids
:
return
MessageDialog
(
title
=
'No items specified'
,
message
=
'No items were specified!'
,
action
=
'./manage_main'
,)
try
:
p
=
self
.
_reserved_names
except
:
p
=
()
for
n
in
ids
:
if
n
in
p
:
return
MessageDialog
(
title
=
'Not Deletable'
,
message
=
'<EM>%s</EM> cannot be deleted.'
%
n
,
action
=
'./manage_main'
,)
while
ids
:
id
=
ids
[
-
1
]
if
not
hasattr
(
self
,
id
)
or
not
self
.
__dict__
.
has_key
(
id
):
raise
'BadRequest'
,
'%s does not exist'
%
ids
[
-
1
]
self
.
_delObject
(
id
)
del
ids
[
-
1
]
if
REQUEST
is
not
None
:
if
not
ids
:
return
MessageDialog
(
title
=
'No items specified'
,
message
=
'No items were specified!'
,
action
=
'./manage_main'
,)
try
:
p
=
self
.
_reserved_names
except
:
p
=
()
for
n
in
ids
:
if
n
in
p
:
return
MessageDialog
(
title
=
'Not Deletable'
,
message
=
'<EM>%s</EM> cannot be deleted.'
%
n
,
action
=
'./manage_main'
,)
while
ids
:
id
=
ids
[
-
1
]
if
not
hasattr
(
self
,
id
)
or
not
self
.
__dict__
.
has_key
(
id
):
raise
'BadRequest'
,
'%s does not exist'
%
ids
[
-
1
]
self
.
_delObject
(
id
)
del
ids
[
-
1
]
if
REQUEST
is
not
None
:
return
self
.
manage_main
(
self
,
REQUEST
,
update_menu
=
1
)
elif
submit
==
'Cut'
:
return
self
.
manage_cutObject
(
id
,
REQURST
)
elif
submit
==
'Copy'
:
return
self
.
manage_copyObject
(
id
,
REQURST
)
elif
submit
==
'Paste'
:
return
self
.
pasteFromClipboard
(
clip_id
,
clip_data
,
REQUEST
)
def
_setProperty
(
self
,
id
,
value
,
type
=
'string'
):
self
.
_checkId
(
id
)
...
...
@@ -538,6 +505,9 @@ class ObjectManager(
##############################################################################
#
# $Log: ObjectManager.py,v $
# Revision 1.45 1998/08/14 16:46:36 brian
# Added multiple copy, paste, rename
#
# Revision 1.44 1998/08/03 13:32:00 jim
# - Revamped folder security:
#
...
...
lib/python/OFS/main.dtml
View file @
da476c61
...
...
@@ -12,10 +12,10 @@
<FORM ACTION="." METHOD="POST">
<!--#if objectItems-->
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING=
2
>
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING=
"2"
>
<!--#in objectItems sort-->
<TR>
<TD ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT" VALIGN="TOP"
WIDTH="16"
>
<INPUT TYPE="CHECKBOX" NAME="ids:list" VALUE="<!--#var sequence-key-->">
</TD>
<TD ALIGN="LEFT" VALIGN="TOP">
...
...
@@ -42,28 +42,31 @@
</TD>
</TR>
<!--#/in-->
<TR>
<TD></TD>
</TABLE>
<TD COLSPAN="2">
<INPUT TYPE="SUBMIT" NAME="manage_cutObject:method" VALUE="Cut">
<INPUT TYPE="SUBMIT" NAME="manage_copyObject:method" VALUE="Copy">
<!--#if validClipData-->
<INPUT TYPE="SUBMIT" NAME="manage_pasteObject:method" VALUE="Paste">
<!--#/if validClipData-->
<INPUT TYPE="SUBMIT" NAME="manage_delObjects:method" VALUE="Delete">
</TD>
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING=2>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH="16"></TD>
<TD ALIGN="LEFT" VALIGN="TOP">
<INPUT TYPE="SUBMIT" NAME="manage_renameForm:method" VALUE="Rename">
<INPUT TYPE="SUBMIT" NAME="manage_cutObjects:method" VALUE="Cut">
<INPUT TYPE="SUBMIT" NAME="manage_copyObjects:method" VALUE="Copy">
<!--#if cb_dataValid-->
<INPUT TYPE="SUBMIT" NAME="manage_pasteObjects:method" VALUE="Paste">
<!--#/if-->
<INPUT TYPE="SUBMIT" NAME="manage_delObjects:method" VALUE="Delete">
</TD>
</TR>
</TABLE>
<!--#else-->
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING=
2
>
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING=
"2"
>
<TR>
<TD>
There are currently no items in <EM><!--#var title_or_id--></EM>
<P>
<!--#if
validClipData
-->
<INPUT TYPE="SUBMIT" NAME="manage_pasteObject:method" VALUE="Paste">
<!--#/if
validClipData
-->
<!--#if
cb_dataValid
-->
<INPUT TYPE="SUBMIT" NAME="manage_pasteObject
s
:method" VALUE="Paste">
<!--#/if-->
</TD>
</TABLE>
<!--#/if-->
...
...
lib/python/OFS/renameForm.dtml
0 → 100644
View file @
da476c61
<HTML>
<HEAD>
<TITLE>Rename Item</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555">
<!--#if expr="_.hasattr(REQUEST, 'ids') and REQUEST['ids']"-->
<!--#with expr="_.getattr(this(), REQUEST['ids'][0])"-->
<!--#if cb_isMoveable-->
<H2>Rename <!--#var meta_type--></H2>
<P>
<FORM ACTION="." METHOD="POST">
<TABLE CELLSPACING="0">
<TR>
<TD ALIGN="LEFT" VALIGN="TOP">
<IMG SRC="<!--#var SCRIPT_NAME-->/<!--#var icon-->" ALT="" BORDER="0">
</TD>
<TD ALIGN="LEFT" VALIGN="TOP">
<!--#var id-->
</TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP">
<STRONG>to:</STRONG>
</TD>
<TD ALIGN="LEFT" VALIGN="TOP">
<INPUT TYPE="TEXT" NAME="new_id" SIZE="20">
</TD>
</TR>
<TR>
<TD></TD>
<TD>
<INPUT TYPE="HIDDEN" NAME="id" VALUE="<!--#var id-->">
<INPUT TYPE="submit" NAME="manage_renameObject:method" VALUE=" Ok ">
<INPUT TYPE="submit" NAME="manage_main:method" VALUE="Cancel">
</TD>
</TR>
</TABLE>
</FORM>
<!--#else-->
<FORM ACTION="manage_main" METHOD="GET">
<CENTER>
<BR><BR>
The item <EM><!--#var id--></EM> does not support this operation.
<P>
<INPUT TYPE="submit" NAME="submit" VALUE=" Ok ">
</CENTER>
</FORM>
<!--#/if-->
<!--#/with-->
<!--#else-->
<FORM ACTION="manage_main" METHOD="GET">
<CENTER>
<BR><BR>
You must select an item to rename.
<P>
<INPUT TYPE="submit" NAME="submit" VALUE=" Ok ">
</CENTER>
</FORM>
<!--#/if-->
</BODY>
</HTML>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment