Commit b8c4aeaa authored by Hanno Schlichting's avatar Hanno Schlichting

Stop using id() methods and define proper getId methods

parent c8b7bcbe
......@@ -82,7 +82,7 @@ class Application(ApplicationDefaultPermissions,
self.__allow_groups__ = uf
self._setObject('acl_users', uf)
def id(self):
def getId(self):
try:
return self.REQUEST['SCRIPT_NAME'][1:]
except (KeyError, TypeError):
......
......@@ -141,9 +141,6 @@ class File(Persistent, Implicit, PropertyManager,
content_type=self._get_content_type(file, data, id, content_type)
self.update_data(data, content_type, size)
def id(self):
return self.__name__
def _if_modified_since_request_handler(self, REQUEST, RESPONSE):
# HTTP If-Modified-Since header handling: return True if
# we can handle this request by returning a 304 response
......
......@@ -91,7 +91,7 @@ class Item(Base,
manage_afterClone.__five_method__ = True
# Direct use of the 'id' attribute is deprecated - use getId()
id=''
id = ''
security.declarePublic('getId')
def getId(self):
......@@ -100,17 +100,13 @@ class Item(Base,
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()
name = self.id
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.getId())
__name__ = ComputedAttribute(lambda self: self.id)
# Meta type used for selecting all objects of a given type.
meta_type='simple item'
......@@ -377,7 +373,6 @@ InitializeClass(Item)
class Item_w__name__(Item):
"""Mixin class to support common name/id functions"""
implements(IItemWithName)
......@@ -411,12 +406,10 @@ class Item_w__name__(Item):
getPhysicalRoot() and getPhysicalPath() are designed to operate
together.
"""
path = (self.__name__,)
path = (self.__name__, )
p = aq_parent(aq_inner(self))
if p is not None:
path = p.getPhysicalPath() + path
return path
......
......@@ -29,17 +29,17 @@ class ApplicationTests(unittest.TestCase):
def test_id_no_request(self):
app = self._makeOne()
self.assertEqual(app.id(), 'Zope')
self.assertEqual(app.getId(), 'Zope')
def test_id_w_request_no_SCRIPT_NAME(self):
app = self._makeOne()
app.REQUEST = {}
self.assertEqual(app.id(), 'Zope')
self.assertEqual(app.getId(), 'Zope')
def test_id_w_request_w_SCRIPT_NAME(self):
app = self._makeOne()
app.REQUEST = {'SCRIPT_NAME': '/Dummy'}
self.assertEqual(app.id(), 'Dummy')
self.assertEqual(app.getId(), 'Dummy')
def test_title_and_id_plus_title_or_id(self):
app = self._makeOne()
......
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