Commit 499caee1 authored by 's avatar

Merged bool property updating fix for PropertySheets from 2.2 branch

parent 6926b56c
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""Property management""" """Property management"""
__version__='$Revision: 1.29 $'[11:-2] __version__='$Revision: 1.30 $'[11:-2]
import ExtensionClass, Globals import ExtensionClass, Globals
import ZDOM import ZDOM
...@@ -200,6 +200,13 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes): ...@@ -200,6 +200,13 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes):
return 0 return 0
return 1 return 1
def hasProperty(self, id):
"""Return true if object has a property 'id'"""
for p in self._properties:
if id==p['id']:
return 1
return 0
def getProperty(self, id, d=None): def getProperty(self, id, d=None):
"""Get the property 'id', returning the optional second """Get the property 'id', returning the optional second
argument or None if no such property is found.""" argument or None if no such property is found."""
...@@ -261,13 +268,6 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes): ...@@ -261,13 +268,6 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes):
value=type_converters[proptype](value) value=type_converters[proptype](value)
self._setPropValue(id, value) self._setPropValue(id, value)
def hasProperty(self, id):
"""Return true if object has a property 'id'"""
for p in self._properties:
if id==p['id']:
return 1
return 0
def _delProperty(self, id): def _delProperty(self, id):
if not self.hasProperty(id): if not self.hasProperty(id):
raise ValueError, 'The property %s does not exist' % id raise ValueError, 'The property %s does not exist' % id
...@@ -321,11 +321,11 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes): ...@@ -321,11 +321,11 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes):
get turned off will be ignored. Use manage_changeProperties() get turned off will be ignored. Use manage_changeProperties()
instead for most situations. instead for most situations.
""" """
for prop in self._properties: for prop in self.propertyMap():
name=prop['id'] name=prop['id']
if 'w' in prop.get('mode', 'wd'): if 'w' in prop.get('mode', 'wd'):
value=REQUEST.get(name, '') value=REQUEST.get(name, '')
self._setPropValue(name, value) self._updateProperty(name, value)
return MessageDialog( return MessageDialog(
title ='Success!', title ='Success!',
message='Your changes have been saved', message='Your changes have been saved',
...@@ -339,19 +339,16 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes): ...@@ -339,19 +339,16 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes):
""" """
if REQUEST is None: if REQUEST is None:
props={} props={}
else: else: props=REQUEST
props=REQUEST
if kw: if kw:
for name, value in kw.items(): for name, value in kw.items():
props[name]=value props[name]=value
propdict=self.propdict() propdict=self.propdict()
for name, value in props.items(): for name, value in props.items():
if self.hasProperty(name): if self.hasProperty(name):
if not 'w' in propdict[name].get('mode', 'wd'): if not 'w' in propdict[name].get('mode', 'wd'):
raise 'BadRequest', '%s cannot be changed' % name raise 'BadRequest', '%s cannot be changed' % name
self._setPropValue(name, value) self._updateProperty(name, value)
if REQUEST is not None: if REQUEST is not None:
return MessageDialog( return MessageDialog(
title ='Success!', title ='Success!',
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""Property sheets""" """Property sheets"""
__version__='$Revision: 1.53 $'[11:-2] __version__='$Revision: 1.54 $'[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
...@@ -217,12 +217,6 @@ class PropertySheet(Traversable, Persistent, Implicit): ...@@ -217,12 +217,6 @@ class PropertySheet(Traversable, Persistent, Implicit):
return getattr(self.v_self(), id) return getattr(self.v_self(), id)
return default return default
def _wrapperCheck(self, object):
# Raise an error if an object is wrapped.
if hasattr(object, 'aq_base'):
raise ValueError, 'Invalid property value: wrapped object'
return
def getPropertyType(self, id): def getPropertyType(self, id):
"""Get the type of property 'id', returning None if no """Get the type of property 'id', returning None if no
such property exists""" such property exists"""
...@@ -233,6 +227,12 @@ class PropertySheet(Traversable, Persistent, Implicit): ...@@ -233,6 +227,12 @@ class PropertySheet(Traversable, Persistent, Implicit):
return md.get('type', 'string') return md.get('type', 'string')
return None return None
def _wrapperCheck(self, object):
# Raise an error if an object is wrapped.
if hasattr(object, 'aq_base'):
raise ValueError, 'Invalid property value: wrapped object'
return
def _setProperty(self, id, value, type='string', meta=None): def _setProperty(self, id, value, type='string', meta=None):
# Set a new property with the given id, value and optional type. # Set a new property with the given id, value and optional type.
# Note that different property sets may support different typing # Note that different property sets may support different typing
...@@ -443,11 +443,24 @@ class PropertySheet(Traversable, Persistent, Implicit): ...@@ -443,11 +443,24 @@ class PropertySheet(Traversable, Persistent, Implicit):
if REQUEST is not None: if REQUEST is not None:
return self.manage(self, REQUEST) return self.manage(self, REQUEST)
def manage_editProperties(self, REQUEST):
"""Edit object properties via the web."""
for prop in self.propertyMap():
name=prop['id']
if 'w' in prop.get('mode', 'wd'):
value=REQUEST.get(name, '')
self._updateProperty(name, value)
return MessageDialog(
title ='Success!',
message='Your changes have been saved',
action ='manage')
def manage_changeProperties(self, REQUEST=None, **kw): def manage_changeProperties(self, REQUEST=None, **kw):
"""Change existing object properties by passing either a mapping """Change existing object properties by passing either a mapping
object of name:value pairs {'foo':6} or passing name=value object of name:value pairs {'foo':6} or passing name=value
parameters.""" parameters."""
if REQUEST is None: props={} if REQUEST is None:
props={}
else: props=REQUEST else: props=REQUEST
if kw: if kw:
for name, value in kw.items(): for name, value in kw.items():
...@@ -455,6 +468,8 @@ class PropertySheet(Traversable, Persistent, Implicit): ...@@ -455,6 +468,8 @@ class PropertySheet(Traversable, Persistent, Implicit):
propdict=self._propdict() propdict=self._propdict()
for name, value in props.items(): for name, value in props.items():
if self.hasProperty(name): if self.hasProperty(name):
if not 'w' in propdict[name].get('mode', 'wd'):
raise 'BadRequest', '%s cannot be changed' % name
self._updateProperty(name, value) self._updateProperty(name, value)
if REQUEST is not None: if REQUEST is not None:
return MessageDialog( return MessageDialog(
...@@ -462,18 +477,6 @@ class PropertySheet(Traversable, Persistent, Implicit): ...@@ -462,18 +477,6 @@ class PropertySheet(Traversable, Persistent, Implicit):
message='Your changes have been saved.', message='Your changes have been saved.',
action ='manage') action ='manage')
def manage_editProperties(self, REQUEST):
"""Edit object properties via the web."""
for prop in self.propertyMap():
name=prop['id']
if REQUEST.has_key(name):
value=REQUEST.get(name)
self._updateProperty(name, value)
return MessageDialog(
title ='Success!',
message='Your changes have been saved',
action ='manage')
def manage_delProperties(self, ids=None, REQUEST=None): def manage_delProperties(self, ids=None, REQUEST=None):
"""Delete one or more properties specified by 'ids'.""" """Delete one or more properties specified by 'ids'."""
if ids is None: if ids is None:
...@@ -644,7 +647,6 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs): ...@@ -644,7 +647,6 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs):
return r return r
def get(self, name, default=None): def get(self, name, default=None):
# pdb.set_trace()
for propset in self.__propsets__(): for propset in self.__propsets__():
if propset.id==name or propset.xml_namespace()==name: if propset.id==name or propset.xml_namespace()==name:
return propset.__of__(self) return propset.__of__(self)
......
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