Commit 56ea1fc9 authored by 's avatar

Implemented getId() in SimpleItem; got rid of direct refs to object.id

in OFS package
parent 7371b1c6
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
# #
############################################################################## ##############################################################################
__doc__="""Copy interface""" __doc__="""Copy interface"""
__version__='$Revision: 1.57 $'[11:-2] __version__='$Revision: 1.58 $'[11:-2]
import sys, string, Globals, Moniker, tempfile, ExtensionClass import sys, string, Globals, Moniker, tempfile, ExtensionClass
from marshal import loads, dumps from marshal import loads, dumps
...@@ -207,7 +207,7 @@ class CopyContainer(ExtensionClass.Base): ...@@ -207,7 +207,7 @@ class CopyContainer(ExtensionClass.Base):
# Copy operation # Copy operation
for ob in oblist: for ob in oblist:
if not ob.cb_isCopyable(): if not ob.cb_isCopyable():
raise CopyError, eNotSupported % absattr(ob.id) raise CopyError, eNotSupported % ob.getId()
try: ob._notifyOfCopyTo(self, op=0) try: ob._notifyOfCopyTo(self, op=0)
except: raise CopyError, MessageDialog( except: raise CopyError, MessageDialog(
title='Copy Error', title='Copy Error',
...@@ -215,7 +215,7 @@ class CopyContainer(ExtensionClass.Base): ...@@ -215,7 +215,7 @@ class CopyContainer(ExtensionClass.Base):
action ='manage_main') action ='manage_main')
ob=ob._getCopy(self) ob=ob._getCopy(self)
ob.manage_afterClone(ob) ob.manage_afterClone(ob)
id=self._get_id(absattr(ob.id)) id=self._get_id(ob.getId())
ob._setId(id) ob._setId(id)
self._setObject(id, ob) self._setObject(id, ob)
...@@ -226,7 +226,7 @@ class CopyContainer(ExtensionClass.Base): ...@@ -226,7 +226,7 @@ class CopyContainer(ExtensionClass.Base):
if op==1: if op==1:
# Move operation # Move operation
for ob in oblist: for ob in oblist:
id=absattr(ob.id) id=ob.getId()
if not ob.cb_isMoveable(): if not ob.cb_isMoveable():
raise CopyError, eNotSupported % id raise CopyError, eNotSupported % id
try: ob._notifyOfCopyTo(self, op=1) try: ob._notifyOfCopyTo(self, op=1)
...@@ -312,7 +312,7 @@ class CopyContainer(ExtensionClass.Base): ...@@ -312,7 +312,7 @@ class CopyContainer(ExtensionClass.Base):
def manage_clone(self, ob, id, REQUEST=None): def manage_clone(self, ob, id, REQUEST=None):
# Clone an object, creating a new object with the given id. # Clone an object, creating a new object with the given id.
if not ob.cb_isCopyable(): if not ob.cb_isCopyable():
raise CopyError, eNotSupported % absattr(ob.id) raise CopyError, eNotSupported % ob.getId()
try: self._checkId(id) try: self._checkId(id)
except: raise CopyError, MessageDialog( except: raise CopyError, MessageDialog(
title='Invalid Id', title='Invalid Id',
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""DTML Document objects.""" """DTML Document objects."""
__version__='$Revision: 1.38 $'[11:-2] __version__='$Revision: 1.39 $'[11:-2]
from DocumentTemplate.DT_Util import InstanceDict, TemplateDict from DocumentTemplate.DT_Util import InstanceDict, TemplateDict
from ZPublisher.Converters import type_converters from ZPublisher.Converters import type_converters
from Globals import HTML, HTMLFile, MessageDialog from Globals import HTML, HTMLFile, MessageDialog
...@@ -158,7 +158,7 @@ class DTMLDocument(PropertyManager, DTMLMethod): ...@@ -158,7 +158,7 @@ class DTMLDocument(PropertyManager, DTMLMethod):
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw): def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
"""Render the document given a client object, REQUEST mapping, """Render the document given a client object, REQUEST mapping,
Response, and key word arguments.""" Response, and key word arguments."""
kw['document_id'] =self.id kw['document_id'] =self.getId()
kw['document_title']=self.title kw['document_title']=self.title
if hasattr(self, 'aq_explicit'): if hasattr(self, 'aq_explicit'):
bself=self.aq_explicit bself=self.aq_explicit
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""DTML Method objects.""" """DTML Method objects."""
__version__='$Revision: 1.53 $'[11:-2] __version__='$Revision: 1.54 $'[11:-2]
import History import History
from Globals import HTML, HTMLFile, MessageDialog from Globals import HTML, HTMLFile, MessageDialog
...@@ -156,7 +156,7 @@ class DTMLMethod(HTML, Acquisition.Implicit, RoleManager, ...@@ -156,7 +156,7 @@ class DTMLMethod(HTML, Acquisition.Implicit, RoleManager,
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw): def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
"""Render the document given a client object, REQUEST mapping, """Render the document given a client object, REQUEST mapping,
Response, and key word arguments.""" Response, and key word arguments."""
kw['document_id'] =self.id kw['document_id'] =self.getId()
kw['document_title']=self.title kw['document_title']=self.title
security=getSecurityManager() security=getSecurityManager()
...@@ -180,7 +180,7 @@ class DTMLMethod(HTML, Acquisition.Implicit, RoleManager, ...@@ -180,7 +180,7 @@ class DTMLMethod(HTML, Acquisition.Implicit, RoleManager,
if self.__dict__.has_key('content_type'): if self.__dict__.has_key('content_type'):
c=self.content_type c=self.content_type
else: else:
c, e=guess_content_type(self.__name__, r) c, e=guess_content_type(self.getId(), r)
RESPONSE.setHeader('Content-Type', c) RESPONSE.setHeader('Content-Type', c)
return decapitate(r, RESPONSE) return decapitate(r, RESPONSE)
......
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
# #
############################################################################## ##############################################################################
__doc__="""Find support""" __doc__="""Find support"""
__version__='$Revision: 1.20 $'[11:-2] __version__='$Revision: 1.21 $'[11:-2]
import sys, os, string, time, Globals, ExtensionClass import sys, os, string, time, Globals, ExtensionClass
...@@ -170,7 +170,7 @@ class FindSupport(ExtensionClass.Base): ...@@ -170,7 +170,7 @@ class FindSupport(ExtensionClass.Base):
else: bs=ob else: bs=ob
if ( if (
(not obj_ids or absattr(bs.id) in obj_ids) (not obj_ids or absattr(bs.getId()) in obj_ids)
and and
(not obj_metatypes or (hasattr(bs, 'meta_type') and (not obj_metatypes or (hasattr(bs, 'meta_type') and
bs.meta_type in obj_metatypes)) bs.meta_type in obj_metatypes))
...@@ -262,7 +262,7 @@ class FindSupport(ExtensionClass.Base): ...@@ -262,7 +262,7 @@ class FindSupport(ExtensionClass.Base):
else: bs=ob else: bs=ob
if ( if (
(not obj_ids or absattr(bs.id) in obj_ids) (not obj_ids or absattr(bs.getId()) in obj_ids)
and and
(not obj_metatypes or (hasattr(bs, 'meta_type') and (not obj_metatypes or (hasattr(bs, 'meta_type') and
bs.meta_type in obj_metatypes)) bs.meta_type in obj_metatypes))
......
...@@ -84,9 +84,9 @@ ...@@ -84,9 +84,9 @@
############################################################################## ##############################################################################
__doc__="""Object Manager __doc__="""Object Manager
$Id: ObjectManager.py,v 1.108 2000/08/17 20:17:24 shane Exp $""" $Id: ObjectManager.py,v 1.109 2000/09/05 20:52:47 brian Exp $"""
__version__='$Revision: 1.108 $'[11:-2] __version__='$Revision: 1.109 $'[11:-2]
import App.Management, Acquisition, Globals, CopySupport, Products import App.Management, Acquisition, Globals, CopySupport, Products
import os, App.FactoryDispatcher, ts_regex, Products import os, App.FactoryDispatcher, ts_regex, Products
...@@ -483,8 +483,7 @@ class ObjectManager( ...@@ -483,8 +483,7 @@ class ObjectManager(
RESPONSE=None): RESPONSE=None):
"""Exports an object to a file and returns that file.""" """Exports an object to a file and returns that file."""
if not id: if not id:
id=self.id id=self.getId()
if callable(id): id=id()
ob=self ob=self
else: ob=self._getOb(id) else: ob=self._getOb(id)
...@@ -530,8 +529,7 @@ class ObjectManager( ...@@ -530,8 +529,7 @@ class ObjectManager(
ob=connection.importFile( ob=connection.importFile(
file, customImporters=customImporters) file, customImporters=customImporters)
if REQUEST: self._verifyObjectPaste(ob, validate_src=0) if REQUEST: self._verifyObjectPaste(ob, validate_src=0)
id=ob.id id=ob.getId()
if hasattr(id, 'im_func'): id=id()
self._setObject(id, ob, set_owner=set_owner) self._setObject(id, ob, set_owner=set_owner)
# try to make ownership implicit if possible in the context # try to make ownership implicit if possible in the context
...@@ -619,38 +617,41 @@ class ObjectManager( ...@@ -619,38 +617,41 @@ class ObjectManager(
Globals.default__class_init__(ObjectManager) Globals.default__class_init__(ObjectManager)
class PUTer(Acquisition.Explicit):
"""Class to support the HTTP PUT protocol.""" ## This isnt used anymore - NullResource now handles PUTs.
def __init__(self, parent, id): ## class PUTer(Acquisition.Explicit):
self.id=id ## """Class to support the HTTP PUT protocol."""
self.__parent__=parent
self.__roles__ =parent.PUT__roles__ ## def __init__(self, parent, id):
## self.id=id
def PUT(self, REQUEST, RESPONSE): ## self.__parent__=parent
"""Adds a document, image or file to the folder when a PUT ## self.__roles__ =parent.PUT__roles__
request is received."""
name=self.id ## def PUT(self, REQUEST, RESPONSE):
type=REQUEST.get_header('content-type', None) ## """Adds a document, image or file to the folder when a PUT
body=REQUEST.get('BODY', '') ## request is received."""
if type is None: ## name=self.id
type, enc=mimetypes.guess_type(name) ## type=REQUEST.get_header('content-type', None)
if type is None: ## body=REQUEST.get('BODY', '')
if content_types.find_binary(body) >= 0: ## if type is None:
type='application/octet-stream' ## type, enc=mimetypes.guess_type(name)
else: type=content_types.text_type(body) ## if type is None:
type=lower(type) ## if content_types.find_binary(body) >= 0:
if type in ('text/html', 'text/xml', 'text/plain'): ## type='application/octet-stream'
self.__parent__.manage_addDTMLDocument(name, '', body) ## else: type=content_types.text_type(body)
elif type[:6]=='image/': ## type=lower(type)
ob=Image(name, '', body, content_type=type) ## if type in ('text/html', 'text/xml', 'text/plain'):
self.__parent__._setObject(name, ob) ## self.__parent__.manage_addDTMLDocument(name, '', body)
else: ## elif type[:6]=='image/':
ob=File(name, '', body, content_type=type) ## ob=Image(name, '', body, content_type=type)
self.__parent__._setObject(name, ob) ## self.__parent__._setObject(name, ob)
RESPONSE.setStatus(201) ## else:
RESPONSE.setBody('') ## ob=File(name, '', body, content_type=type)
return RESPONSE ## self.__parent__._setObject(name, ob)
## RESPONSE.setStatus(201)
def __str__(self): ## RESPONSE.setBody('')
return self.id ## return RESPONSE
## def __str__(self):
## return self.id
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""Property sheets""" """Property sheets"""
__version__='$Revision: 1.55 $'[11:-2] __version__='$Revision: 1.56 $'[11:-2]
import time, string, App.Management, Globals import time, string, App.Management, Globals
from ZPublisher.Converters import type_converters from ZPublisher.Converters import type_converters
...@@ -110,7 +110,7 @@ class View(App.Management.Tabs, Base): ...@@ -110,7 +110,7 @@ class View(App.Management.Tabs, Base):
''' '''
RESPONSE.redirect(URL1+'/manage') RESPONSE.redirect(URL1+'/manage')
def tpURL(self): return self.id def tpURL(self): return self.getId()
def manage_options(self): def manage_options(self):
"""Return a manage option data structure for me instance """Return a manage option data structure for me instance
...@@ -189,6 +189,9 @@ class PropertySheet(Traversable, Persistent, Implicit): ...@@ -189,6 +189,9 @@ class PropertySheet(Traversable, Persistent, Implicit):
self.id=id self.id=id
self._md=md or {} self._md=md or {}
def getId(self):
return self.id
def xml_namespace(self): def xml_namespace(self):
# Return a namespace string usable as an xml namespace # Return a namespace string usable as an xml namespace
# for this property set. # for this property set.
...@@ -630,7 +633,7 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs): ...@@ -630,7 +633,7 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs):
def __bobo_traverse__(self, REQUEST, name=None): def __bobo_traverse__(self, REQUEST, name=None):
for propset in self.__propsets__(): for propset in self.__propsets__():
if propset.id==name: if propset.getId()==name:
return propset.__of__(self) return propset.__of__(self)
return getattr(self, name) return getattr(self, name)
...@@ -653,7 +656,7 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs): ...@@ -653,7 +656,7 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs):
def get(self, name, default=None): def get(self, name, default=None):
for propset in self.__propsets__(): for propset in self.__propsets__():
if propset.id==name or propset.xml_namespace()==name: if propset.getId()==name or propset.xml_namespace()==name:
return propset.__of__(self) return propset.__of__(self)
return default return default
...@@ -672,7 +675,7 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs): ...@@ -672,7 +675,7 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs):
def delPropertySheet(self, name): def delPropertySheet(self, name):
result=[] result=[]
for propset in self.aq_parent.__propsets__: for propset in self.aq_parent.__propsets__:
if propset.id != name and propset.xml_namespace() != name: if propset.getId() != name and propset.xml_namespace() != name:
result.append(propset) result.append(propset)
self.parent.__propsets__=tuple(result) self.parent.__propsets__=tuple(result)
......
...@@ -89,8 +89,8 @@ Aqueduct database adapters, etc. ...@@ -89,8 +89,8 @@ Aqueduct database adapters, etc.
This module can also be used as a simple template for implementing new This module can also be used as a simple template for implementing new
item types. item types.
$Id: SimpleItem.py,v 1.78 2000/06/12 19:49:48 shane Exp $''' $Id: SimpleItem.py,v 1.79 2000/09/05 20:52:47 brian Exp $'''
__version__='$Revision: 1.78 $'[11:-2] __version__='$Revision: 1.79 $'[11:-2]
import regex, sys, Globals, App.Management, Acquisition, App.Undo import regex, sys, Globals, App.Management, Acquisition, App.Undo
import AccessControl.Role, AccessControl.Owned, App.Common import AccessControl.Role, AccessControl.Owned, App.Common
...@@ -123,12 +123,25 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -123,12 +123,25 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
def manage_beforeDelete(self, item, container): pass def manage_beforeDelete(self, item, container): pass
def manage_afterClone(self, item): pass def manage_afterClone(self, item): pass
# The name of this object and the name used to traverse to thie # Direct use of the 'id' attribute is deprecated - use getId()
# object in a URL:
id='' id=''
getId__roles__=None
def getId(self):
"""Return the id of the object as a string. This method
should be used in preference to accessing an id attribute
of an object directly. The getId method is public."""
name=getattr(self, 'id', None)
if callable(name):
return name()
if name is not None:
return name
if hasattr(self, '__name__'):
return self.__name__
raise AttributeError, 'This object has no id'
# Alias id to __name__, which will make tracebacks a good bit nicer: # Alias id to __name__, which will make tracebacks a good bit nicer:
__name__=ComputedAttribute(lambda self: self.id) __name__=ComputedAttribute(lambda self: self.getId())
# Name, relative to SOFTWARE_URL of icon used to display item # Name, relative to SOFTWARE_URL of icon used to display item
# in folder listings. # in folder listings.
...@@ -164,10 +177,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -164,10 +177,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
if callable(title): if callable(title):
title=title() title=title()
if title: return title if title: return title
id=self.id return self.getId()
if callable(id):
id=id()
return id
def title_and_id(self): def title_and_id(self):
""" """
...@@ -178,9 +188,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -178,9 +188,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
title=self.title title=self.title
if callable(title): if callable(title):
title=title() title=title()
id=self.id id = self.getId()
if callable(id):
id=id()
return title and ("%s (%s)" % (title,id)) or id return title and ("%s (%s)" % (title,id)) or id
def this(self): def this(self):
...@@ -189,9 +197,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -189,9 +197,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
def tpURL(self): def tpURL(self):
# My URL as used by tree tag # My URL as used by tree tag
url=self.id return self.getId()
if hasattr(url,'im_func'): url=url()
return url
def tpValues(self): def tpValues(self):
# My sub-objects as used by the tree tag # My sub-objects as used by the tree tag
...@@ -326,8 +332,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -326,8 +332,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
ob=ob.aq_parent ob=ob.aq_parent
stat=marshal.loads(self.manage_FTPstat(REQUEST)) stat=marshal.loads(self.manage_FTPstat(REQUEST))
if callable(self.id): id=self.id() id = self.getId()
else: id=self.id
return marshal.dumps((id,stat)) return marshal.dumps((id,stat))
def __len__(self): def __len__(self):
......
...@@ -84,8 +84,8 @@ ...@@ -84,8 +84,8 @@
############################################################################## ##############################################################################
'''This module implements a mix-in for traversable objects. '''This module implements a mix-in for traversable objects.
$Id: Traversable.py,v 1.4 2000/08/15 17:52:53 evan Exp $''' $Id: Traversable.py,v 1.5 2000/09/05 20:52:47 brian Exp $'''
__version__='$Revision: 1.4 $'[11:-2] __version__='$Revision: 1.5 $'[11:-2]
import Acquisition import Acquisition
...@@ -128,7 +128,7 @@ class Traversable: ...@@ -128,7 +128,7 @@ class Traversable:
later, for example in a copy/paste operation. getPhysicalRoot() later, for example in a copy/paste operation. getPhysicalRoot()
and getPhysicalPath() are designed to operate together. and getPhysicalPath() are designed to operate together.
''' '''
path = (self.id,) path = (self.getId(),)
p = getattr(self,'aq_inner', None) p = getattr(self,'aq_inner', None)
if p is not None: if p is not None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment