Commit 94603fc9 authored by Andreas Jung's avatar Andreas Jung

- Collector #1058: Several fixes for PropertySheets when used

       outside ZClasses
parent 31af7fe6
...@@ -8,6 +8,9 @@ Zope Changes ...@@ -8,6 +8,9 @@ Zope Changes
Bugs fixed Bugs fixed
- Collector #1058: Several fixes for PropertySheets when used
outside ZClasses
- Collector #1053: parseIndexRequest turned empty sequence of search - Collector #1053: parseIndexRequest turned empty sequence of search
terms into unrestricted search. terms into unrestricted search.
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
"""Property sheets""" """Property sheets"""
__version__='$Revision: 1.89 $'[11:-2] __version__='$Revision: 1.90 $'[11:-2]
import time, App.Management, Globals import time, App.Management, Globals
from webdav.WriteLockInterface import WriteLockInterface from webdav.WriteLockInterface import WriteLockInterface
...@@ -30,6 +30,11 @@ from AccessControl import getSecurityManager ...@@ -30,6 +30,11 @@ from AccessControl import getSecurityManager
from webdav.common import isDavCollection from webdav.common import isDavCollection
from cgi import escape from cgi import escape
# DM: we would like to import this from somewhere
BadRequestException= 'Bad Request'
class View(App.Management.Tabs, Base): class View(App.Management.Tabs, Base):
"""A view of an object, typically used for management purposes """A view of an object, typically used for management purposes
...@@ -600,6 +605,9 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs): ...@@ -600,6 +605,9 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs):
) )
# optionally to be overridden by derived classes
PropertySheetClass= PropertySheet
webdav =DAVProperties() webdav =DAVProperties()
def _get_defaults(self): def _get_defaults(self):
return (self.webdav,) return (self.webdav,)
...@@ -639,12 +647,14 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs): ...@@ -639,12 +647,14 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs):
return propset.__of__(self) return propset.__of__(self)
return default return default
def manage_addPropertySheet(self, id, ns): def manage_addPropertySheet(self, id, ns, REQUEST=None):
""" """ """ """
md={'xmlns':ns} md={'xmlns':ns}
ps=PropertySheet(id, md) ps= self.PropertySheetClass(id, md)
self.addPropertySheet(ps) self.addPropertySheet(ps)
return 'OK' if REQUEST is None: return ps
ps= self.get(id)
REQUEST.RESPONSE.redirect('%s/manage' % ps.absolute_url())
def addPropertySheet(self, propset): def addPropertySheet(self, propset):
propsets=self.aq_parent.__propsets__ propsets=self.aq_parent.__propsets__
...@@ -658,6 +668,25 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs): ...@@ -658,6 +668,25 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs):
result.append(propset) result.append(propset)
self.aq_parent.__propsets__=tuple(result) self.aq_parent.__propsets__=tuple(result)
## DM: deletion support
def isDeletable(self,name):
'''currently, we say that *name* is deletable when it is not a
default sheet. Later, we may further restrict deletability
based on an instance attribute.'''
ps= self.get(name)
if ps is None: return 0
if ps in self._get_defaults(): return 0
return 1
def manage_delPropertySheets(self, ids=(), REQUEST=None):
'''delete all sheets identified by *ids*.'''
for id in ids:
if not self.isDeletable(id):
raise BadRequestException, 'attempt to delete undeletable property sheet: ' + id
self.delPropertySheet(id)
if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage' % self.absolute_url())
def __len__(self): def __len__(self):
return len(self.__propsets__()) return len(self.__propsets__())
...@@ -677,7 +706,7 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs): ...@@ -677,7 +706,7 @@ class PropertySheets(Traversable, Implicit, App.Management.Tabs):
if r is None: if r is None:
pre='../' pre='../'
else: else:
pre=r['URL'] pre=r['URLPATH0']
for i in (1,2): for i in (1,2):
l=pre.rfind('/') l=pre.rfind('/')
if l >= 0: if l >= 0:
......
...@@ -41,6 +41,7 @@ property values, edit the values and click "Save Changes". ...@@ -41,6 +41,7 @@ property values, edit the values and click "Save Changes".
</tr> </tr>
<dtml-in propertyMap mapping> <dtml-in propertyMap mapping>
<dtml-let type="not _.has_key('type') and 'string' or type">
<tr> <tr>
<td align="left" valign="top" width="16"> <td align="left" valign="top" width="16">
<dtml-if "'d' in _['sequence-item'].get('mode', 'awd')"> <dtml-if "'d' in _['sequence-item'].get('mode', 'awd')">
...@@ -156,6 +157,7 @@ property values, edit the values and click &quot;Save Changes&quot;. ...@@ -156,6 +157,7 @@ property values, edit the values and click &quot;Save Changes&quot;.
</div> </div>
</td> </td>
</tr> </tr>
</dtml-let>
</dtml-in> </dtml-in>
<tr> <tr>
<td colspan="2">&nbsp;</td> <td colspan="2">&nbsp;</td>
......
...@@ -4,12 +4,15 @@ ...@@ -4,12 +4,15 @@
<form action="&dtml-URL1;" method="post"> <form action="&dtml-URL1;" method="post">
<table cellspacing="0" cellpadding="2" border="0"> <table cellspacing="0" cellpadding="2" border="0">
<dtml-in items sort> <dtml-in items sort>
<dtml-with "_(REQUEST=REQUEST, item=_['sequence-item'].aq_base)" only> <dtml-with "_(REQUEST=REQUEST, item=_['sequence-item'].aq_base, isDeletable=isDeletable)" only>
<dtml-with item> <dtml-with item>
<dtml-if id> <dtml-if id>
<tr> <tr>
<td align="left" valign="top"> <td align="left" valign="top">
<a href="&dtml-id;">&dtml-id; (&dtml-xml_namespace;)</a> <dtml-if expr="isDeletable(id)"><input type=checkbox name="ids:list" value="&dtml-id;"></dtml-if>
</td>
<td align="left" valign="top">
<a href="&dtml-id;/manage">&dtml-id; <dtml-if xml_namespace>(<dtml-var xml_namespace>)</dtml-if></a>
<dtml-if locked_in_session> <dtml-if locked_in_session>
<dtml-if modified_in_session> <dtml-if modified_in_session>
<img src="&dtml-BASEPATH1;/p_/locked" <img src="&dtml-BASEPATH1;/p_/locked"
...@@ -25,18 +28,24 @@ ...@@ -25,18 +28,24 @@
</dtml-with> </dtml-with>
</dtml-with> </dtml-with>
</dtml-in> </dtml-in>
</table>
<table cellspacing="0" cellpadding="2" border="0">
<tr> <tr>
<td align="left" valign="top"> <td colspan=2>
</td> <input type="submit" name="manage_delPropertySheets:method"
<td align="left" valign="top"> class="form-element" value="Delete">
<input type="submit" name="manage_addPropertySheetForm:method"
class="form-element" value="Add">
</td> </td>
</tr> </tr>
</table> </table>
<table cellpadding=5>
<tr>
<td><span class="form-label">Name:</span> <input name="id"></td>
<td><span class="form-label">Namespace:</span> <input name="ns"></td>
<td>
<input type="submit" name="manage_addPropertySheet:method"
class="form-element" value="Add">
</td>
</tr>
</table>
</form> </form>
<dtml-var manage_page_footer> <dtml-var manage_page_footer>
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