Re: [Zope] How to Delete ZClass Instances programmatically??
Jean Jordaan writes:
I've found the "How-To: Adding ZClass Instances Programmatically", but now I'm looking for the *Deleting ZClass Instances* one!
I'm trying this as a beginning (hacked from the Zope management interface):: .... <dtml-if "AUTHENTICATED_USER.has_role('ContentManager')"> <input type="submit" name="manage_delObjects:method" value="Delete"> </form> </dtml-if>
Problems:
- it sends me to the management screen afterwards, and I'm calling it from the public interface. This means, you want to look at the source of "manage_delObjects" (-> "OFS.ObjectManager") to see, how it sends you to the management interface.
You will see, that it contains: if REQUEST is not None: return self.manage_main(self,REQUEST,update_menu) Thus, do not pass it a REQUEST. This implies, that you do not call it directly from the form, but call a dtml method from the form, that then calls "manage_delObjects" with the "ids" and no REQUEST. It may be necessary to set a proxy role for this method.
- I don't necessarily want to give the 'ContentManager' rights to delete objects; I'd rather manage this through a delete method with the appropriate proxy role. Then, this should get your method mentioned above.
Dieter
Dieter Maurer wrote:
- it sends me to the management screen afterwards, and I'm calling it from the public interface. This means, you want to look at the source of "manage_delObjects" (-> "OFS.ObjectManager") to see, how it sends you to the management interface.
You will see, that it contains:
if REQUEST is not None: return self.manage_main(self,REQUEST,update_menu)
Thus, do not pass it a REQUEST.
It's this kindof hackiness which I really hope MJ's work eventually gets rid of. This is the sort of thing I was talking about when I said "using bits of the management interface in other contexts" a while back. what do other people think? How do we go about making progress on this? cheers, Chris
Chris Withers wrote:
Dieter Maurer wrote:
- it sends me to the management screen afterwards, and I'm calling it from the public interface. This means, you want to look at the source of "manage_delObjects" (-> "OFS.ObjectManager") to see, how it sends you to the management interface.
You will see, that it contains:
if REQUEST is not None: return self.manage_main(self,REQUEST,update_menu)
Thus, do not pass it a REQUEST.
It's this kindof hackiness which I really hope MJ's work eventually gets rid of.
This is the sort of thing I was talking about when I said "using bits of the management interface in other contexts" a while back.
what do other people think?
How do we go about making progress on this?
A simple but effective approach would be to split up every manage_* method into two methods: - manage_do_* does the work. - manage_* calls manage_do_* then returns HTML. Perhaps this could be added to the "clean up the core" proposal. Shane
participants (3)
-
Chris Withers -
Dieter Maurer -
Shane Hathaway