Hi Annet,

On Apr 10, 1:51 am, jmverm...@xs4all.nl wrote:
> Denes,
>
> > OK but you should check if minmax is not empty first.
>
> I thought this wouldn't be necessary since the input comes from an
> auto-complete or drop-box, and these contain values that are in the
> zipcoderegions table for sure.
>
> However, that's my logic, now that you mention checking if minmax is
> not empty, I recall from my Java programming modules, never to take
> these things for granted and always check.

The auto-complete part was not mentioned in this thread but it should
be OK as per your logic, except for the extreme case where the
selected postcoderegio is deleted while the form is being shown.

>
> In Python will this do:
>
> form=form_factory()
> if form.accepts(request.vars,session):
>     minmax=db(db.postcoderegio.regio==request.vars.postcoderegio).\
>     select(db.postcoderegio.codemin,db.postcoderegio.codemax)
>         if not len(minmax):
>             redirect:(URL(r=request,f='byzipcode'))
>         else:
>             minimum=int(minmax[0].codemin)
>             maximum=int(minmax[0].codemax)
>             clubs=db().select()
>     elif form.errors:
>       response.flash='form has errors'
>     else:
>       response.flash='please fill the form'
>       clubs=[]
>     return dict(form=form,clubs=clubs)
>
> Or is there an other way to test id minmax is empty?

In Python the following are considered to be False:
1) None
2) False
3) zero of any numeric type, for example, 0, 0L, 0.0, 0j
4) any empty sequence, for example, '', (), []
5) any empty mapping, for example, {}
6) instances of user-defined classes, if the class defines a
__nonzero__() or __len__() method, when that method returns the
integer zero or bool value False

so you could check minmax's "emptyness" using:
if minmax:
  # it is not empty
else:
  # it is empty (see 4 above)

but your code using len() is fine too.

>
> Kind regards,
>
> Annet.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to