Commit c33f3a26 authored by Jim Fulton's avatar Jim Fulton

*** empty log message ***

parent b973ce26
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""Property sheets""" """Property sheets"""
__version__='$Revision: 1.10 $'[11:-2] __version__='$Revision: 1.11 $'[11:-2]
import time, string, App.Management import time, string, App.Management
from ZPublisher.Converters import type_converters from ZPublisher.Converters import type_converters
...@@ -131,18 +131,20 @@ class PropertySheet(Persistent, Implicit): ...@@ -131,18 +131,20 @@ class PropertySheet(Persistent, Implicit):
provide a web interface for managing its properties.""" provide a web interface for managing its properties."""
_properties=() _properties=()
_extensible=1
def property_extensible_schema__(self): return self._extensible
def __init__(self, id, md=None): def __init__(self, id, md=None):
# Create a new property set, using the given id and namespace # Create a new property set, using the given id and namespace
# string. The namespace string should be usable as an xml name- # string. The namespace string should be usable as an xml name-
# space identifier. # space identifier.
self.id=id self.id=id
self.md=md or {} self._md=md or {}
def xml_namespace(self): def xml_namespace(self):
# Return a namespace string usable as an xml namespace # Return a namespace string usable as an xml namespace
# for this property set. # for this property set.
return self.md.get('xmlns', '') return self._md.get('xmlns', '')
def v_self(self): def v_self(self):
return self return self
...@@ -175,8 +177,15 @@ class PropertySheet(Persistent, Implicit): ...@@ -175,8 +177,15 @@ class PropertySheet(Persistent, Implicit):
# Note that different property sets may support different typing # Note that different property sets may support different typing
# systems. # systems.
if not self.valid_property_id(id): if not self.valid_property_id(id):
raise 'Bad Request', 'Invalid property id.' raise 'Bad Request', 'Invalid property id, %s.' % id
if not self.property_extensible_schema__():
raise 'Bad Request', (
'Properties cannot be added to this property sheet')
self=self.v_self() self=self.v_self()
if hasattr(aq_base(self),id):
raise 'Bad Request', (
'Invalid property id, %s. It is in use.' % id)
if meta is None: meta={} if meta is None: meta={}
prop={'id':id, 'type':type, 'meta':meta} prop={'id':id, 'type':type, 'meta':meta}
self._properties=self._properties+(prop,) self._properties=self._properties+(prop,)
...@@ -198,7 +207,7 @@ class PropertySheet(Persistent, Implicit): ...@@ -198,7 +207,7 @@ class PropertySheet(Persistent, Implicit):
for prop in self.v_self()._properties: for prop in self.v_self()._properties:
if prop['id']==id: prop['meta']=meta if prop['id']==id: prop['meta']=meta
props.append(prop) props.append(prop)
self.v_self()._properties=props self.v_self()._properties=tuple(props)
setattr(self.v_self(), id, value) setattr(self.v_self(), id, value)
def _delProperty(self, id): def _delProperty(self, id):
...@@ -235,7 +244,7 @@ class PropertySheet(Persistent, Implicit): ...@@ -235,7 +244,7 @@ class PropertySheet(Persistent, Implicit):
# Return a tuple of mappings, giving meta-data for properties. # Return a tuple of mappings, giving meta-data for properties.
return self.v_self()._properties return self.v_self()._properties
def propdict(self): def _propdict(self):
dict={} dict={}
for p in self.propertyMap(): for p in self.propertyMap():
dict[p['id']]=p dict[p['id']]=p
...@@ -280,7 +289,7 @@ class PropertySheet(Persistent, Implicit): ...@@ -280,7 +289,7 @@ class PropertySheet(Persistent, Implicit):
result=join(result, '\n') result=join(result, '\n')
return propstat % (result, '200 OK', '') return propstat % (result, '200 OK', '')
else: else:
propdict=self.propdict() propdict=self._propdict()
xml_id=self.xml_namespace() xml_id=self.xml_namespace()
for name, ns in names: for name, ns in names:
if ns==xml_id: if ns==xml_id:
...@@ -309,6 +318,7 @@ class PropertySheet(Persistent, Implicit): ...@@ -309,6 +318,7 @@ class PropertySheet(Persistent, Implicit):
manage_propertiesForm=HTMLFile('properties', globals()) manage_propertiesForm=HTMLFile('properties', globals())
def manage_addProperty(self, id, value, type, REQUEST=None): def manage_addProperty(self, id, value, type, REQUEST=None):
"""Add a new property via the web. Sets a new property with """Add a new property via the web. Sets a new property with
the given id, type, and value.""" the given id, type, and value."""
...@@ -327,7 +337,7 @@ class PropertySheet(Persistent, Implicit): ...@@ -327,7 +337,7 @@ class PropertySheet(Persistent, Implicit):
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()
vself=self.v_self() vself=self.v_self()
for name, value in props.items(): for name, value in props.items():
if self.hasProperty(name): if self.hasProperty(name):
...@@ -347,7 +357,7 @@ class PropertySheet(Persistent, Implicit): ...@@ -347,7 +357,7 @@ class PropertySheet(Persistent, Implicit):
title='No property specified', title='No property specified',
message='No properties were specified!', message='No properties were specified!',
action ='./manage_propertiesForm',) action ='./manage_propertiesForm',)
propdict=self.propdict() propdict=self._propdict()
vself=self.v_self() vself=self.v_self()
if hasattr(vself, '_reserved_names'): if hasattr(vself, '_reserved_names'):
nd=vself._reserved_names nd=vself._reserved_names
...@@ -365,7 +375,6 @@ class PropertySheet(Persistent, Implicit): ...@@ -365,7 +375,6 @@ class PropertySheet(Persistent, Implicit):
if REQUEST is not None: if REQUEST is not None:
return self.manage_propertiesForm(self, REQUEST) return self.manage_propertiesForm(self, REQUEST)
class Virtual: class Virtual:
def __init__(self): def __init__(self):
...@@ -380,14 +389,14 @@ class DefaultProperties(Virtual, PropertySheet): ...@@ -380,14 +389,14 @@ class DefaultProperties(Virtual, PropertySheet):
its owner.""" its owner."""
id='default' id='default'
md={'xmlns': 'http://www.zope.org/propsets/default'} _md={'xmlns': 'http://www.zope.org/propsets/default'}
class DAVProperties(Virtual, PropertySheet): class DAVProperties(Virtual, PropertySheet):
"""WebDAV properties""" """WebDAV properties"""
id='webdav' id='webdav'
md={'xmlns': 'DAV:'} _md={'xmlns': 'DAV:'}
pm=({'id':'creationdate', 'mode':'r'}, pm=({'id':'creationdate', 'mode':'r'},
{'id':'displayname', 'mode':'r'}, {'id':'displayname', 'mode':'r'},
{'id':'resourcetype', 'mode':'r'}, {'id':'resourcetype', 'mode':'r'},
...@@ -506,10 +515,20 @@ class PropertySheets(Implicit): ...@@ -506,10 +515,20 @@ class PropertySheets(Implicit):
def __getitem__(self, n): def __getitem__(self, n):
return self.__propsets__()[n].__of__(self) return self.__propsets__()[n].__of__(self)
def items(self): def values(self):
propsets=self.__propsets__() propsets=self.__propsets__()
return map(lambda n, s=self: n.__of__(s), propsets) return map(lambda n, s=self: n.__of__(s), propsets)
def items(self):
propsets=self.__propsets__()
r=[]
for n in propsets:
if hasattr(n,'id'): id=n.id
else: id=''
r.append((id, n.__of__(self)))
return r
def get(self, name, default=None): def get(self, name, default=None):
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:
...@@ -538,6 +557,28 @@ class PropertySheets(Implicit): ...@@ -538,6 +557,28 @@ class PropertySheets(Implicit):
def __len__(self): def __len__(self):
return len(self.__propsets__()) return len(self.__propsets__())
class FixedSchema(PropertySheet):
def __init__(self, id, base, md=None):
FixedSchema.inheritedAttribute('')(self, id, md)
self._base=base
def propertyMap(self):
# Return a tuple of mappings, giving meta-data for properties.
r=[]
for d in self._base.propertyMap():
mode=d.get('mode', 'wd')
if 'd' in mode:
dd={}
dd.update(d)
d=dd
d['mode']=filter(lambda c: c != 'd', mode)
r.append(d)
return tuple(r)+self.v_self()._properties
def property_extensible_schema__(self): return self._base._extensible
class vps(Base): class vps(Base):
...@@ -552,8 +593,6 @@ class vps(Base): ...@@ -552,8 +593,6 @@ class vps(Base):
parent=parent.aq_base parent=parent.aq_base
return self.c(parent) return self.c(parent)
def absattr(attr): def absattr(attr):
if callable(attr): if callable(attr):
return attr() return attr()
......
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