But presumably the myButton() function does not have its own view given 
that it was originally written to always redirect to another URL. In that 
case, why not just make the myButton.html view render the search results as 
desired? If you want a search_results.html view to be used from multiple 
functions, that's no problem either -- here are three options:

def search_results(resultSet):
    div = DIV(.....)
    response.view = 'default/search_results.html'
    return dict(div=div)

So, any time the search_results() function is called by another function, 
it sets the view to search_results.html. Or, you can set the view within 
the calling function:

def myButton():
    someId = request.args(0)
    resultSet = db(....)
    response.view = 'default/search_results.html'
    return search_results(resultSet)

Or you could include the search_results view in another view. For example, 
in myButton.html, you can do:

{{extend 'layout.html'}}
{{include 'default/search_results.html'}}

Anthony
 

On Thursday, May 23, 2013 4:02:29 PM UTC-4, brac...@gmail.com wrote:
>
> search_results() will have to be exposed since I want to display the 
> results on a different page (in search_results.html). I think returning the 
> div using your suggestion would still be on the same page?
>
>
>
> On Thursday, May 23, 2013 3:38:17 PM UTC-4, Anthony wrote:
>>
>> Why do you need to redirect at all? You can just call the 
>> search_results() function directly from the myButton() function:
>>
>> def search_results(resultSet):
>>     div = DIV(.....)
>>     return dict(div=div)
>>
>> def myButton():
>>     someId = request.args(0)
>>     resultSet = db(....)
>>     return search_results(resultSet)
>>
>> If the search_results() function is needed in other controllers, you 
>> could define it in a model file or in a module and import it. Note, 
>> functions that take arguments (as search_results does above) are not 
>> exposed as actions accessible via URL -- they are for internal use only 
>> (same for a function that begins with a double underscore, even if it 
>> doesn't take any arguments).
>>
>> Anthony
>>
>> On Thursday, May 23, 2013 2:51:24 PM UTC-4, brac...@gmail.com wrote:
>>>
>>> In my views, I have:
>>>
>>> {{=A('click for more information', _href=URL("myCallback", args=[1]))}}
>>>
>>>
>>> When the anchor button is clicked, my callback will do some lookup and 
>>> processing in the db, and then will redirect to a new page populated with 
>>> the new information:
>>>
>>> def search_results():
>>>     resultSet = request.args(0)
>>>     # Build HTML helpers using resultSet
>>>     div = DIV(.....)
>>>
>>>     return dict(div=div)
>>>
>>> def myButton():
>>>      # Figure out the id from the request
>>>      someId = request.args(0)
>>>
>>>      # get some data from db using the id
>>>      resultSet = db(....)
>>>
>>>
>>>      # want to redirect to another page with the new data in the 
>>> resultSet
>>>     redirect(URL('search_results', args=resultSet))
>>>
>>> But doing the redirect with the resultSet args will screw up the URL and 
>>> I'll end up with an invalid request. 
>>>
>>> I've thought of two ways around this:
>>>
>>> 1) Create a temporary session variable and store the resultSet there. 
>>> Once I'm done with the data, I'll explicitly clear it.
>>>
>>> 2) Instead of doing the database logic in the callback, pass the id to 
>>> the search_results() and do the database logic there.
>>>
>>> I'm hesitant to adopt the first option because it seems messy to create 
>>> a bunch of session variables for temporary things (unless this is standard 
>>> practice?).
>>>
>>> The second option seems okay, but I'm afraid that the code will become 
>>> too specific to that particular anchor tag. That is, if I create a new 
>>> anchor tag to do some other search, the database logic may be different 
>>> than the one inside the search_results(). For this, I guess the better 
>>> question should be if the database logic code should live in the callback 
>>> function or in the target redirect controller function?
>>>
>>>
>>> In spite of this, what would be the clean or proper way of sending data 
>>> with a redirect from a callback function?
>>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to