Commit a1fea6ff authored by 's avatar

Merged fixes for deleting of class attribute _owner and missing name

attrs on submit buttons.
parent a593fea8
...@@ -85,8 +85,8 @@ ...@@ -85,8 +85,8 @@
__doc__='''Support for owned objects __doc__='''Support for owned objects
$Id: Owned.py,v 1.4 2000/06/16 19:42:04 srichter Exp $''' $Id: Owned.py,v 1.5 2000/07/10 13:23:15 brian Exp $'''
__version__='$Revision: 1.4 $'[11:-2] __version__='$Revision: 1.5 $'[11:-2]
import Globals, urlparse, SpecialUsers, ExtensionClass, string import Globals, urlparse, SpecialUsers, ExtensionClass, string
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
...@@ -99,6 +99,9 @@ def ownableFilter(self, ...@@ -99,6 +99,9 @@ def ownableFilter(self,
_owner=aq_get(self, '_owner', None, 1) _owner=aq_get(self, '_owner', None, 1)
return _owner is not UnownableOwner return _owner is not UnownableOwner
# Marker to use as a getattr default.
_mark=ownableFilter
class Owned(ExtensionClass.Base): class Owned(ExtensionClass.Base):
__ac_permissions__=( __ac_permissions__=(
...@@ -158,10 +161,8 @@ class Owned(ExtensionClass.Base): ...@@ -158,10 +161,8 @@ class Owned(ExtensionClass.Base):
def changeOwnership(self, user, def changeOwnership(self, user,
aq_get=aq_get, None=None, aq_get=aq_get, None=None,
): ):
"""Change the ownership to the given user. """Change the ownership to the given user, make the
ownership acquired if possible."""
If possible, make the ownership acquired.
"""
new=ownerInfo(user) new=ownerInfo(user)
if new is None: return # Special user! if new is None: return # Special user!
...@@ -169,7 +170,9 @@ class Owned(ExtensionClass.Base): ...@@ -169,7 +170,9 @@ class Owned(ExtensionClass.Base):
if old==new: return if old==new: return
if hasattr(self, '_owner'): # See if there is an _owner in the instance. If it is a
# class attribute we leave it alone.
if self.__dict__.get('_owner', _mark) is not _mark:
# Hm, maybe we can acquire ownership # Hm, maybe we can acquire ownership
del self._owner del self._owner
self.changeOwnership(user) self.changeOwnership(user)
...@@ -198,7 +201,6 @@ class Owned(ExtensionClass.Base): ...@@ -198,7 +201,6 @@ class Owned(ExtensionClass.Base):
raise 'Unauthorized', ( raise 'Unauthorized', (
'manage_takeOwnership was called from an invalid context' 'manage_takeOwnership was called from an invalid context'
) )
self.changeOwnership(security.getUser()) self.changeOwnership(security.getUser())
RESPONSE.redirect(REQUEST['HTTP_REFERER']) RESPONSE.redirect(REQUEST['HTTP_REFERER'])
...@@ -215,13 +217,17 @@ class Owned(ExtensionClass.Base): ...@@ -215,13 +217,17 @@ class Owned(ExtensionClass.Base):
else: else:
if old is None: return if old is None: return
new=aq_get(aq_parent(self), '_owner', None, 1) new=aq_get(aq_parent(self), '_owner', None, 1)
if old is new: del self._owner if old is new and (
self.__dict__.get('_owner', _mark) is not _mark
):
del self._owner
if RESPONSE is not None: RESPONSE.redirect(REQUEST['HTTP_REFERER']) if RESPONSE is not None: RESPONSE.redirect(REQUEST['HTTP_REFERER'])
def _deleteOwnershipAfterAdd(self): def _deleteOwnershipAfterAdd(self):
if hasattr(self, '_owner'): # Only delete _owner if it is an instance attribute.
if self.__dict__.get('_owner', _mark) is not _mark:
del self._owner del self._owner
for object in self.objectValues(): for object in self.objectValues():
...@@ -251,7 +257,7 @@ class Owned(ExtensionClass.Base): ...@@ -251,7 +257,7 @@ class Owned(ExtensionClass.Base):
return None return None
if _owner is UnownableOwner: if _owner is UnownableOwner:
# We want to acquire Unownable oenership! # We want to acquire Unownable ownership!
return self._deleteOwnershipAfterAdd() return self._deleteOwnershipAfterAdd()
else: else:
# Otherwise change the ownership # Otherwise change the ownership
......
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
<form action="manage_changeOwnershipType"> <form action="manage_changeOwnershipType">
<dtml-if explicit> <dtml-if explicit>
<input type="hidden" name="explicit" value=""> <input type="hidden" name="explicit" value="">
<input type="submit" value="Make ownership implicit (acquired)"> <input name="submit" type="submit" value="Make ownership implicit (acquired)">
<dtml-else> <dtml-else>
<input type="hidden" name="explicit" value="y"> <input type="hidden" name="explicit" value="y">
<input type="submit" value="Make ownership explicit"> <input name="submit" type="submit" value="Make ownership explicit">
</dtml-if> </dtml-if>
</form> </form>
</dtml-if> </dtml-if>
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<dtml-if userCanTakeOwnership> <dtml-if userCanTakeOwnership>
<form action="manage_takeOwnership"> <form action="manage_takeOwnership">
<input type="submit" value="Take ownership"> <input name="submit" type="submit" value="Take ownership">
</form> </form>
</dtml-if> </dtml-if>
......
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