[web2py] Re: Multiple form flash problem.

2011-03-09 Thread annet
Hi David,

 Sorry if anything here is impractical, but here's a couple of
 thoughts...

I very much appreciate you sharing your thoughts with me, they are
helpful and they add to range of possible solutions to implement
things.

The reason I implemented things the way I did is that I am building
this web application for a psychologist and he insisted on
implementing it this way for cognitive ergonomic reasons.


Kind regards,

Annet.


[web2py] Re: Multiple form flash problem.

2011-03-09 Thread villas
Glad to help and sounds like an interesting project.

 I am building this web application for a psychologist
 and he insisted on implementing it this way for
 cognitive ergonomic reasons.

Hmm, I thought 'cognitive ergonomic reasons' was just an excuse for
lying on the couch!

:-) D


[web2py] Re: Multiple form flash problem.

2011-03-06 Thread annet
@Jonathan,

Thanks for the link, indeed the first reply is very useful.


@David,

Thanks for posting your idea.

 It wasn't obvious to me why you needed two forms. Why not use one and
 test to see what has been filled in?

Because I could not figure out how to test what has been filled in.

I am working on a sort of back-office part of a cms. The back-office
user should be able to search for company data entering either the
company name and city of residence or the two part registration number
at the Chamber of Commerce or the two part postal code. Since
'either .. or' has to be clear and for example the sub-dossier-number
of the CoC registration and the numeric part of a postal code are both
four characters long, I couldn't think of anything else than using
three forms.

Kind regards,

Annet.


[web2py] Re: Multiple form flash problem.

2011-03-06 Thread villas
Sorry if anything here is impractical, but here's a couple of
thoughts...

If you wish to limit the user to make one search only...

* Make an input box to enter the search value, and a drop-down box to
specify the search type.

* If using several input boxes,  you could use JS.  When user starts
typing in one search box,  JS blanks the others.  And/or,  on form
accepts make an onvalidation function and return false if more than
one box completed.

You may also wish to consider allowing the user to specify multiple
searches at the same time.  If he fills in 3 boxes,  do 3 searches and
list all the results.

Regards, D

On Mar 6, 8:11 am, annet annet.verm...@gmail.com wrote:
 @Jonathan,

 Thanks for the link, indeed the first reply is very useful.

 @David,

 Thanks for posting your idea.

  It wasn't obvious to me why you needed two forms. Why not use one and
  test to see what has been filled in?

 Because I could not figure out how to test what has been filled in.

 I am working on a sort of back-office part of a cms. The back-office
 user should be able to search for company data entering either the
 company name and city of residence or the two part registration number
 at the Chamber of Commerce or the two part postal code. Since
 'either .. or' has to be clear and for example the sub-dossier-number
 of the CoC registration and the numeric part of a postal code are both
 four characters long, I couldn't think of anything else than using
 three forms.

 Kind regards,

 Annet.


[web2py] Re: Multiple form flash problem.

2011-03-05 Thread annet
Denes and Jonathan,

Thank you both for your replies, now I do understand the logic of the
function.

@Denes,
So, in Python you can only simulate a CASE statement using if's? Could
you provide me with an example?


Kind regards,

Annet


Re: [web2py] Re: Multiple form flash problem.

2011-03-05 Thread Jonathan Lundell
On Mar 5, 2011, at 8:44 AM, annet wrote:
 
 So, in Python you can only simulate a CASE statement using if's? Could
 you provide me with an example?

The first reply here is useful: 
http://stackoverflow.com/questions/594442/choosing-between-different-switch-case-replacements-in-python-dictionary-or-if

[web2py] Re: Multiple form flash problem.

2011-03-05 Thread villas
Hi Annet,
It wasn't obvious to me why you needed two forms. Why not use one and
test to see what has been filled in?  Just another idea.
Regards, David

On Mar 5, 4:44 pm, annet annet.verm...@gmail.com wrote:
 Denes and Jonathan,

 Thank you both for your replies, now I do understand the logic of the
 function.

 @Denes,
 So, in Python you can only simulate a CASE statement using if's? Could
 you provide me with an example?

 Kind regards,

 Annet


[web2py] Re: Multiple form flash problem.

2011-03-02 Thread annet
Hi Denes,

Thanks for your reply, removing the else: ... solved the problem. I
followed the if: .. elif: .. else: .. pattern used in the chapter on
forms and validators in the web2py manual. Why does it work in a
single form function and why doesn't it work in a multiple form
function?


 Since you are not redirecting after an accepts it just comes back to
 the same controller, creating new forms and resetting the
 response.flash messages.

Should I redirect after an accepts? The view has a two column layout,
the left column contains a search form the right column displays the
search results.


Hi Jonathan,

Thanks for your reply. I added the response.flash='Fill in form' line
of code before the first call to accepts, the actual text contains
more than just the 'Fill in form' directive.


Kind regards,

Annet.


[web2py] Re: Multiple form flash problem.

2011-03-02 Thread DenesL


On Mar 2, 3:27 am, annet annet.verm...@gmail.com wrote:
 Hi Denes,

 Thanks for your reply, removing the else: ... solved the problem. I
 followed the if: .. elif: .. else: .. pattern used in the chapter on
 forms and validators in the web2py manual. Why does it work in a
 single form function and why doesn't it work in a multiple form
 function?

For it to work the same you would have to nest the IFs differently,
simulating a CASE statement from other languages.

  Since you are not redirecting after an accepts it just comes back to
  the same controller, creating new forms and resetting the
  response.flash messages.

 Should I redirect after an accepts? The view has a two column layout,
 the left column contains a search form the right column displays the
 search results.

That depends on your app's logical flow.

 Hi Jonathan,

 Thanks for your reply. I added the response.flash='Fill in form' line
 of code before the first call to accepts, the actual text contains
 more than just the 'Fill in form' directive.

 Kind regards,

 Annet.

On Mar 2, 3:27 am, annet annet.verm...@gmail.com wrote:
 Hi Denes,

 Thanks for your reply, removing the else: ... solved the problem. I
 followed the if: .. elif: .. else: .. pattern used in the chapter on
 forms and validators in the web2py manual. Why does it work in a
 single form function and why doesn't it work in a multiple form
 function?

  Since you are not redirecting after an accepts it just comes back to
  the same controller, creating new forms and resetting the
  response.flash messages.

 Should I redirect after an accepts? The view has a two column layout,
 the left column contains a search form the right column displays the
 search results.

 Hi Jonathan,

 Thanks for your reply. I added the response.flash='Fill in form' line
 of code before the first call to accepts, the actual text contains
 more than just the 'Fill in form' directive.

 Kind regards,

 Annet.


Re: [web2py] Re: Multiple form flash problem.

2011-03-02 Thread Jonathan Lundell
On Mar 2, 2011, at 12:27 AM, annet wrote:
 
 Hi Denes,
 
 Thanks for your reply, removing the else: ... solved the problem. I
 followed the if: .. elif: .. else: .. pattern used in the chapter on
 forms and validators in the web2py manual. Why does it work in a
 single form function and why doesn't it work in a multiple form
 function?

While you can put as many forms as you like on the page, the user can submit 
only one at a time. The else clause is invoked when you see a form that hasn't 
been submitted. 

So if the user submits your first form, you'll put something appropriate in 
response.flash, but you'll execute the else cause for the second form and 
clobber it.

 
 
 Since you are not redirecting after an accepts it just comes back to
 the same controller, creating new forms and resetting the
 response.flash messages.
 
 Should I redirect after an accepts? The view has a two column layout,
 the left column contains a search form the right column displays the
 search results.

Don't redirect unless the flow of your logic requires it. But go over your 
logic keeping in mind that at most only one form at a time will be submitted.


 
 
 Hi Jonathan,
 
 Thanks for your reply. I added the response.flash='Fill in form' line
 of code before the first call to accepts, the actual text contains
 more than just the 'Fill in form' directive.
 
 
 Kind regards,
 
 Annet.




[web2py] Re: Multiple form flash problem.

2011-03-01 Thread DenesL
Hi Annet,

just remove the

else:
response.flash='Fill in form'

parts from your code.

Since you are not redirecting after an accepts it just comes back to
the same controller, creating new forms and resetting the
response.flash messages.



On Mar 1, 8:07 am, annet annet.verm...@gmail.com wrote:
 I implemented a one form search function:

 def search():
     rows=[]
     form=SQLFORM.factory(
         Field('company',length=54,requires=IS_NOT_EMPTY())
     if form.accepts(request.vars,session):
         rows=db(..).select(..)
         if rows:
             response.flash='Search result:'
         else:
             response.flash='No search result!'
     elif form.errors:
         response.flash='Form contains errors'
     else:
         response.flash='Fill in form'
     return dict(form=form,rows=rows)

 This code works as expected. Now when I make it a two form search
 function:

 def search():
     rows=[]
     form1=SQLFORM.factory(
         Field('company',length=54,requires=IS_NOT_EMPTY())
      form2=SQLFORM.factory(
         Field('city',length=54,requires=IS_NOT_EMPTY())
     if form1.accepts(request.vars,session,formname='form1'):
         rows=db(..).select(..)
         if rows:
             response.flash='Search result:'
         else:
             response.flash='No search result!'
     elif form1.errors:
         response.flash='Form contains errors'
     else:
         response.flash='Fill in form'
      if form2.accepts(request.vars,session,formname='form2'):
         rows=db(..).select(..)
         if rows:
             response.flash='Search result:'
         else:
             response.flash='No search result!'
     elif form2.errors:
         response.flash='Form contains errors'
     else:
         response.flash='Fill in form'
     return dict(form1=form1,form2=form2,rows=rows)

 ... the flash no longer displays correctly i.e. when the form first
 displays, the flash displays the 'Fill in form' message and after form
 submission and rows containing company objects, instead of displaying
 'Search result' the flash still displays the 'Fill in form' message.

 How should I change the code for the flash to display correctly.

 Kind regards,

 Annet


Re: [web2py] Re: Multiple form flash problem.

2011-03-01 Thread Jonathan Lundell
On Mar 1, 2011, at 7:04 AM, DenesL wrote:
 
 just remove the
 
else:
response.flash='Fill in form'
 
 parts from your code.
 
 Since you are not redirecting after an accepts it just comes back to
 the same controller, creating new forms and resetting the
 response.flash messages.

This 'else' case isn't very useful anyway; I think of it as a placeholder. If 
you really *do* want a flash message for this case, just set it directly as the 
default response.flash before the first call to accepts.