[Zope] Restatement of list problem

Phil Harris phil@harris-family.info
Fri, 21 Jun 2002 14:20:54 +0100


You need to use the Python type() function:

if type(your_list) is type([]):
  do something here

or the Zope same_type() function:

t=[]

if same_type(your_list,t):
  do something here

see http://www.zopelabs.com/cookbook/995873707 for more info

hth



On Fri, 21 Jun 2002 09:10:52 -0400
"Schmidt, Allen J." <aschmidt@nv.cc.va.us> wrote:

> So then is there ANY way to definitively determine that something is a list
> or not?
>
> Have not tried but on first look it seems Dieter's solution would blow up if
> not a list, correct?
>
>
>
> -----Original Message-----
> From: Jens Vagelpohl [mailto:jens@zope.com]
> Sent: Friday, June 21, 2002 8:53 AM
> To: Schmidt, Allen J.
> Cc: 'zope@zope.org'
> Subject: Re: [Zope] Restatement of list problem
>
>
> string.find will blow up if this is really a list. if it is a string it
> will be OK. however, the dtmlin will blow up if you have a string. it will
> be fine if you have a list.
>
> jens
>
>
> On Friday, June 21, 2002, at 08:35 , Schmidt, Allen J. wrote:
>
> > You are correct in how the hidden fields were set up.
> > In your example, what if 'br' comes in as a single...not a list? Won't the
> > dtml-in throw an error if it's not a list??
>
> > My thought was to try this (semi-pseudo code):
>
> > <if br>
> >  <if string.find(br,'[')>  //then it's a list
> >   <in br>
> >     type=hidden name=sequence-item
> >   </in>
> >  <else> // not a list but a single
> >     type=hidden name=br
> >  </if>
> > </if>
>
>
> > Won't using the string.find expose the list so the dtml-in won't blow up?
>
>
> > Thanks!!
>
> > -Allen
>
>
> > -----Original Message-----
> > From: Dieter Maurer [mailto:dieter@handshake.de]
> > Sent: Wednesday, June 19, 2002 1:49 PM
> > To: Schmidt, Allen J.
> > Cc: 'zope@zope.org'
> > Subject: Re: [Zope] Restatement of list problem
>
>
> > Schmidt, Allen J. writes:
> >> Maybe I over-complicated my original request.
> >>
> >> I have a form field that is a list:
> >> ['2 DR CONVERTIBLE','2 DR COUPE','2 DR HATCHBACK']
> >>
> >> The URL looks like this:
> >> vehicleList?bt=2+DR+CONVERTIBLE&bt=2+DR+COUPE&bt=2+DR+HATCHBACK
> >>
> >> When I pick for years 2002 and 2001 for the above body types, the URL
> >> changes a bit:
> >>
>
> vehicleList?yr%3Alist=2002&yr%3Alist=2001&bt%3Alist=%5B%272+DR+CONVERTIBLE%2
> >> 7%2C+%272+DR+COUPE%27%2C+%272+DR+HATCHBACK%27%5D
> > This looks as if you would have your list in a hidden variable
> > of the form
>
> >    <input name="bt:list" type="hidden" value="&dtml-bt;">
>
> > When this arrives at the Zope server, you will get a list with
> > one string that respresents the former list as a string.
>
> > You need instead:
>
> >    <dtml-in br>
> >      <input name="bt:list" type="hidden" value="&dtml-sequence-item;">
> >    </dtml-else>
> >      <input name="bt:tokens" type="hidden" value="">
> >    </dtml-in>
>
> >    i.e. each list element must gets its one "input" control.
>
>
> > Dieter
>
>
> > _______________________________________________
> > 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 )
>