On Fri, Apr 10, 2009 at 5:53 AM, annet <[email protected]> wrote:
> The second one:
>
> def byzipcode():
>    form=form_factory(SQLField('postcoderegio',requires=[IS_LENGTH
> (2),IS_NOT_EMPTY()],\
>    widget=lambda self, value:TAG[''](INPUT
> (_id='byzipcode',_name='postcoderegio',_class='ac_input',_type='text'))))
>    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):
>            response.flash='Please provide a valid postcoderegion'
>            redirect(URL(r=request,f='byzipcode'))
>        else:
>            minimum=int(minmax[0].codemin)
>            maximum=int(minmax[0].codemax)
>            clubs=db((db.bedrijf.id==db.adres.bedrijf)&
> (db.bedrijf.id==db.bedrijfinschrijving.bedrijf)&\
>            (db.adres.postcode_cijferdeel>=minimum)&
> (db.adres.postcode_cijferdeel<=maximum)\
>            &(db.adres.adressoort=='vestigingsadres')&
> (db.bedrijfinschrijving.inschrijving=='fitnessclub'))\
>            .select
> (db.bedrijf.id,db.bedrijf.bedrijfsnaam,db.bedrijf.status,db.adres.straat,
> \
>            db.adres.plaats,orderby=db.bedrijf.status|
> db.bedrijf.bedrijfsnaam)
>    elif form.errors:
>      response.flash='form has errors'
>    else:
>      response.flash='please fill the form'
>      clubs=[]
>    return dict(form=form,clubs=clubs)
>
>
> Executes alright if I enter a valid postcoderegio (zipcoderegion),
> however, when the auto-complete field is empty or contains a value
> with a length other than 2 it doesn't display an error message, it
> displays please fill the form in the flash.

>>> len(123)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object of type 'int' has no len()
>>> len(str(123))
3

You can't see "length" of integer values.

> Then when the value in the auto-complete passes validation, but minmax
> is empty, I expect the message in the flash to be: please provide a
> valid postalcoderegion.

The flash is set and it's OK, but you REDIRECT the user to other page
- in that page flash isn't set. So, you have to DO NOT set
response.flash and pass an arg to the page user will be redirected to,
like:

redirect(URL(r=request, f='byzipcode', args='error: bla bla bla'))

-- 
 Álvaro Justen
 Peta5 - Telecomunicações e Software Livre
 21 3021-6001 / 9898-0141
 http://www.peta5.com.br/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to