Populating a :list variable from the results of a ZSQL method
Hi all, Say I've got a form with this in it <select type="checkbox" name="options:list"> <option value="1">number 1 <option value="2">number 2 <option value="3">number 3 </select> When this is put into an SQL database, the field 'options' is this (string) ['1', '2', '3'] or ['2', '3'] etc. When I get the data back from the database, 'options' comes back as a string, and <dtml-in options> ... </dtml-in> gives errors (basically, it can't iterate over a string). I tried <dtml-call "REQUEST.set('new_options:list', options)"> and then tried iterating over new_options, but the variable didn't exist... Has anyone got any solutions for this? TIA Tone ------ Dr Tony McDonald, Assistant Director, FMCC, http://www.fmcc.org.uk/ The Medical School, Newcastle University Tel: +44 191 222 5116 A Zope list for UK HE/FE http://www.fmcc.org.uk/mailman/listinfo/zope
Tony McDonald wrote:
When this is put into an SQL database, the field 'options' is this (string)
['1', '2', '3'] or ['2', '3'] etc.
So you're storing the sequence as a string of the type shown above... ...ow ;-) Might be best to change your SQL Schema so your store one row per option... Nasty hack external method: def eval_options(self): return eval(self.REQUEST['options']) then you can do: <dtml-in eval_options> ...but be careful with that external method, it could be used to do all sorts of bad things if it gets into the wrong hands. cheers, Chris
tone, How about (untested): where 'dboptions' is the string pulled from the DB, and 'options' is the list needed. <dtml-call "REQUEST.set('options',[])"> <dtml-in "_.string.split(dboptions[1:-1],',')"> <dtml-call "options.append(_.int(_['sequence-item']))"> </dtml-in> This would then give you take the string "['1','2','3']" and turn it into the list [1,2,3]. hth Phil ----- Original Message ----- From: "Tony McDonald" <tony.mcdonald@ncl.ac.uk> To: "Zope List" <zope@zope.org> Sent: Friday, November 10, 2000 10:10 AM Subject: [Zope] Populating a :list variable from the results of a ZSQL method
Hi all, Say I've got a form with this in it
<select type="checkbox" name="options:list"> <option value="1">number 1 <option value="2">number 2 <option value="3">number 3 </select>
When this is put into an SQL database, the field 'options' is this (string)
['1', '2', '3'] or ['2', '3'] etc.
When I get the data back from the database, 'options' comes back as a string, and <dtml-in options> ... </dtml-in> gives errors (basically, it can't iterate over a string).
I tried <dtml-call "REQUEST.set('new_options:list', options)"> and then tried iterating over new_options, but the variable didn't exist...
Has anyone got any solutions for this? TIA Tone ------ Dr Tony McDonald, Assistant Director, FMCC, http://www.fmcc.org.uk/ The Medical School, Newcastle University Tel: +44 191 222 5116 A Zope list for UK HE/FE http://www.fmcc.org.uk/mailman/listinfo/zope
_______________________________________________ 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 )
On 10/11/00 10:52 am, "Phil Harris" <phil.harris@zope.co.uk> wrote:
tone,
How about (untested):
where 'dboptions' is the string pulled from the DB, and 'options' is the list needed.
<dtml-call "REQUEST.set('options',[])"> <dtml-in "_.string.split(dboptions[1:-1],',')"> <dtml-call "options.append(_.int(_['sequence-item']))"> </dtml-in>
This would then give you take the string "['1','2','3']" and turn it into the list [1,2,3].
hth
Phil
Aha! That's just about what I'd come up with before. Ok, well to be honest I actually got as far as the string.split and ended up using a _.string.find() construct to get a pseudo-lookup working :) I suppose to make it more generic, you'd lose the _.int() part. Thanks for the info Phil. ------ Dr Tony McDonald, Assistant Director, FMCC, http://www.fmcc.org.uk/ The Medical School, Newcastle University Tel: +44 191 222 5116 A Zope list for UK HE/FE http://www.fmcc.org.uk/mailman/listinfo/zope
participants (3)
-
Chris Withers -
Phil Harris -
Tony McDonald