In which model file do you put it or you create a new one (if so what is 
the name of the file)?

On Saturday, August 22, 2009 at 5:19:38 AM UTC+2, Ray (a.k.a. Iceberg) 
wrote:
>
> In case you don't know, you can also put functions inside model, so 
> that they are globally available. I think this make your controller 
> and view have less coupling. 
>
> in your model: 
> def helperFunction(a): 
>   return a*a 
>
> in your controller: 
> def index(): 
>   return {} 
>   # much cleaner than return dict(func1=helperFunction, 
> func2=someOtherFunc, ...) 
>
> in your view: 
> {{=helperFunction(5)}} 
>
> On Aug22, 1:48am, Don Lee <[email protected]> wrote: 
> > I found what appears to be an easier way.  I should have thought of it 
> > before.  Everything is an object so: 
> > 
> > in my controller: 
> > ===================================== 
> > def testFunction(a): 
> >     return a*a 
> > 
> > def index(): 
> >     return dict(funct=testFunction) 
> > ===================================== 
> > 
> > in my view: 
> > 
> > ====================================== 
> > {{=funct(5)}} 
> > ====================================== 
> > 
> > results in 25 being printed on the page 
> > 
> > 
> > 
> > On Tue, Aug 11, 2009 at 10:54 AM, mdipierro <[email protected]> 
> wrote: 
> > 
> > > There are two types of frameworks push and pull. 
> > 
> > > In a push framework (like web2py, Django, Rails) the URL is mapped 
> > > into a function, which returns data (in the form of a dictionary) and 
> > > the data is rendered by one view. 
> > 
> > > In a pull framework (like Struts and JBoss) the URL is mapped into a 
> > > view which calls one or more controller functions. 
> > 
> > > From your question I assume you have a pull framework in mind. You can 
> > > mimic a pull framework in web2py in multiple ways. One way is via ajax 
> > > requests: 
> > 
> > > #controller default.py 
> > > def index(): return dict() 
> > > def f1(): return response.render('partial_view1.html',dict()) 
> > > def f2(): return response.render('partial_view2.html',dict()) 
> > 
> > > #view default/index.html 
> > > {{extend 'alyout.html'}} 
> > > <div id="f1"></div> 
> > > <div id="f2"></div> 
> > > <script> 
> > > jQuery(document).ready(funciton(){ 
> > >  ajax('{{=URL(f='f1')}}",[],'f1'); 
> > >  ajax('{{=URL(f='f2')}}",[],'f2'); 
> > > })}; 
> > > </script> 
> > 
> > > #view partial_view1.html 
> > > Hello 
> > 
> > > #view partial_view2.html 
> > > World 
> > 
> > > Hope it makes sense. 
> > 
> > > Massimo 
> > 
> > > On Aug 11, 8:50 am, Don <[email protected]> wrote: 
> > > > I am new to the MVC paradigm, python, and web2py.  I would like to 
> be 
> > > > able to: 
> > 
> > > > 1. create a controller (done) 
> > > > 1. define a series of functions (including index) 
> > > > 2. call any of the function from a single view. 
> > 
> > > > Example.  I have a model that consists of three tables.  My 
> default.py 
> > > > controllers index function returns a dictionary containing rows from 
> a 
> > > > query about vendor names.  I build a table with the vendor names.  I 
> > > > also want to build a subtable listing the products available from 
> each 
> > > > vendor.  For that I would like to define another function that takes 
> > > > the vendor id and returns products related to that vendor id.  But I 
> > > > would have to make another view (if I understand correctly). 
> > 
> > > > I want all the information to appear in a single view.  Is this 
> > > > possible?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to