[Zope] Delete multiple posts

Tino Wildenhain tino@wildenhain.de
Tue, 03 Apr 2001 14:37:30 +0200


Hi Gitte,

time is on your side if you are with zope :) We brougt up a
complete b2b e-commerce site with 3 not-even-python-knowers
and one well-python-knower (me)
We did not know anything about zope and it was with first
betas of zope 2.0 :) 4 Months later the site was up :)

Ok, you should get a little bit familar with the way the web works,
what is sent by the browser and what in return from the server.

A little page with <dtml-var REQUEST> is also very helpful for
understanding.

Please see the many examples how to work with ZSQL methods, how to 
explicitely pass parameters to them. The loop you got already so its
all you need.

Hint:
Your zsql-method could look like:

DELETE FROM TABLE blah WHERE ItemID=<dtml-sqlvar arg_ItemToDelete
type=string>


So you would call it inside your DTML-Method:

<dtml-call
expr="YourZSQLMethodToDeleteItems(arg_ItemToDelete=_['sequence-item'])">


(Note: the _['sequence-item'] expression is used to get from the
namespace (_) the 
value for the name 'sequence-item'. Sequence-item runs from the
beginning to end of
your sequence (list, array) in the in-tag. NB: sequence-item is unhandy
because
its hypenation and its special meaning in python: hypenation is the
minus-sign.
You can expect a better solution to this soon)

Alternatively:

DELETE FROM TABLE blah WHERE ItmID in 
('<dtml-var "_.string.join(arg_ItemSequence,_.chr(39)+','+_.chr(39))"
sql_quote>')

With the call:

<dtml-call expr="YourZSQLMethodToDeleteAllAtOnce(arg_ItemSequence=ids)">

(in this case no in-tag is required)

However, to understand the above examples please consult the various
documents
all around on python at first and zope in special.

Remember: if you are really in trouble with the shedule and need to get 
things done, consider using professional help. There are now many
companys
and single persons here who would help you. (not me, I dont have the
time ;)

Regards
Tino

Gitte Wange wrote:
> 
> On 03 Apr 2001 11:55:57 +0200, Tino Wildenhain wrote:
> >
> > Hi Gitte,
> >
> > Gitte Wange wrote:
> > >
> > > Well I'm sorry to say this, but it seems a bit more complicated than
> > > what I need. Isn't it possible to make an array out of a select box
> > > (with only the selected items in the array) and just run through this
> > > array to delete the items ?
> >
> > Thats no way complicated. The "list" is the word python people use
> > instead of "array" :-) If you note for your checkbox name
> > a name and :list, zope automatically converts all selected entrys into
> > a list containing the selected entrys. If you dont write :list, it does
> > it anyway if there is more then one selected. To be save, use "ids:list"
> > so the list is called ids. (refering to the example below)
> >
> > As mentioned, you dont have to delete item by item if they are stored
> > in Zope as objects. you only need to pass it to the manage_delObjects
> > method of the folder:
> >
> > <dtml-call expr="yourfolder_with_items.manage_delObjects(ids)">
> >
> > (schould work. Untested)
> >
> > If you have your items in a sql database, you may want to ilterate like
> > this:
> >
> > <dtml-in ids>
> >   <dtml-call
> > expr="dosomethingtodelete(itemtodelete=_['sequence-item'])">
> > </dtml-in>
> 
> well I made the list: NAME="ids:list" in the checkbox line
> When you hit the deletebutton a method is called.
> The code for deletion is here:
> <dtml-in ids>
>         <dtml-call sqlDeleteClips> <-- That's the sqlmethod
> </dtml-in>
> 
> What's funny is that I get an 400 error.
> And I have 3 hidden fiels in the same form - normally they would be
> passed as ActionList=1 etc. etc. but now they are passed as
> ActionList=['1', '1', '1', '1', '1', '1', '1', '1']
> 
> Yes I know I should learn some python but I'm working against time :-)
> 
> Gitte
> >
> > Regards
> > Tino
> > >
> > > Gitte
> > >
> > > On 02 Apr 2001 09:47:41 -0500, Farrell, Troy wrote:
> > > > I use a python script to do this all day :)
> > > > Zope Coolness: You don't have to run through the array.  Pass the array as a
> > > > parameter to manage_delObjects.
> > > > Remember to bind the namespace to _
> > > > The check boxes are listed as follows in a form that calls my script:
> > > >
> > > > <dtml-in expr="objectValues()">
> > > > <li><input type="checkbox" name="ids:list" value="<dtml-var
> > > > name="id">"<dtml-if name="checkall"> checked="checked"</dtml-if> />&nbsp<a
> > > > href="&dtml-absolute_url;?ex=.log"><dtml-var name="title"></a></li>
> > > > </dtml-in>
> > > >
> > > > The Script:
> > > >
> > > > ## Script (Python) "manageLogFiles"
> > > > ##bind container=container
> > > > ##bind context=context
> > > > ##bind namespace=_
> > > > ##bind script=script
> > > > ##bind subpath=traverse_subpath
> > > > ##parameters=
> > > > ##title=
> > > > ##
> > > > if context.REQUEST.has_key('ids') and context.REQUEST.has_key('doThis'):
> > > >   if context.REQUEST.doThis == 'Delete these!':
> > > >     # Delete all selected LogFiles
> > > >     # note the .logs. in the command below
> > > >     context.logs.manage_delObjects(context.REQUEST.ids)
> > > >     context.REQUEST.RESPONSE.redirect(context.REQUEST.SourceURL)
> > > >
> > > >   else :
> > > >     # I don't know what to do
> > > >     raise KeyError
> > > >
> > > > else:
> > > >   # Do this if they didn't check any of the boxes
> > > >   # I used to raise a KeyError, but that is stupid
> > > >   # Nobody wants a computer to tell them that they pushed
> > > >   # a button at the wrong time.  Now, we essentially do
> > > >   # nothing, but send them back to where they came from.
> > > >   # raise KeyError
> > > >   context.REQUEST.RESPONSE.redirect(context.REQUEST.SourceURL)
> > > >
> > > > Troy
> > > >
> > > > -----Original Message-----
> > > > From: Gitte Wange [mailto:gitte@babytux.dk]
> > > > Sent: Monday, April 02, 2001 6:05 AM
> > > > To: zope@zope.org
> > > > Subject: [Zope] Delete multiple posts
> > > >
> > > >
> > > > Hello,
> > > >
> > > > I have a list of items where it should be possible to delete all the
> > > > items you wish.
> > > > Each item have a checkbox with the value equal to them itemid.
> > > >
> > > > I have done this is PHP just by naming these checkboxes "deletearr[]" to
> > > > make an array, then run through the array an delete each item.
> > > > But how do I do the same thing in Zope ?
> > > >
> > > > Or - a more specifik question - can I make an array the same way in Zope
> > > > that I did in PHP ?
> > > >
> > > > Regards,
> > > > --
> > > > ************************
> > > > Gitte Wange Jensen
> > > >
> > > > System Squid Developer
> > > > MMManager Aps
> > > > +45 29 72 79 72
> > > >
> > > > gitte@mmmanager.org
> > > > ************************
> > > >
> > > >
> > > > _______________________________________________
> > > > Zope maillist  -  Zope@zope.org
> > > > http://lists.zope.org/mailman/listinfo/zope
> > > > **   No cross posts or HTML encoding!  **
> > > > (Related lists -
> > > >  http://lists.zope.org/mailman/listinfo/zope-announce
> > > >  http://lists.zope.org/mailman/listinfo/zope-dev )
> > > >
> > > > _______________________________________________
> > > > Zope maillist  -  Zope@zope.org
> > > > http://lists.zope.org/mailman/listinfo/zope
> > > > **   No cross posts or HTML encoding!  **
> > > > (Related lists -
> > > >  http://lists.zope.org/mailman/listinfo/zope-announce
> > > >  http://lists.zope.org/mailman/listinfo/zope-dev )
> > >
> > > _______________________________________________
> > > Zope maillist  -  Zope@zope.org
> > > http://lists.zope.org/mailman/listinfo/zope
> > > **   No cross posts or HTML encoding!  **
> > > (Related lists -
> > >  http://lists.zope.org/mailman/listinfo/zope-announce
> > >  http://lists.zope.org/mailman/listinfo/zope-dev )