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