Commit 499caee1 authored by 's avatar

Merged bool property updating fix for PropertySheets from 2.2 branch

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