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