Re: [web2py] Re: storeing a db set in a storage for a map plugin

2011-07-20 Thread Manuele Pesenti

On 20/07/2011 00:34, Anthony wrote:

Objects defined in your models and controllers do not survive from
request to request (unless, of course, you store them somewhere, like
the session). In your code, the Set object is created when you visit
/default/index, but the select happens when you visit
/plugin_openplayers/index, which happens in a different request, so the
Set object no longer exists.


ok, in this case I need to pass a db set that cannot be stored in 
session (right?)... what's the right way to do that?


thanks

Manuele


Anthony





Re: [web2py] Re: storeing a db set in a storage for a map plugin

2011-07-20 Thread Manuele Pesenti

On 20/07/2011 08:44, Manuele Pesenti wrote:


ok, in this case I need to pass a db set that cannot be stored in
session (right?)... what's the right way to do that?


would it be the case to use tha global declaretion such as is 
explained here for example?


http://effbot.org/pyfaq/how-do-you-set-a-global-variable-in-a-function.htm



thanks

 Manuele




Re: [web2py] Re: storeing a db set in a storage for a map plugin

2011-07-20 Thread Anthony
No, the Set object has to be defined during the same request as the select, 
so you should either define it in a model file (as in the plugin_gmap 
example), or in the /plugin_openplayers/index function (where the select 
happens). Alternatively, you could define a function that does the work of 
/plugin_openplayers/index and put the function in a model file or in a 
module, and then call that function from /default/index after you define the 
Set there (note, if you put the function in a module, you must import it to 
use it, and in order to reference the request variables, you either have to 
pass them explicitly as an argument to the function, or your module has to 
import the 'current' object, and your module code can then reference 
current.request.vars).
 
Anthony

On Wednesday, July 20, 2011 5:52:08 AM UTC-4, Manuele wrote:

 On 20/07/2011 08:44, Manuele Pesenti wrote:
 
  ok, in this case I need to pass a db set that cannot be stored in
  session (right?)... what's the right way to do that? 

 would it be the case to use tha global declaretion such as is 
 explained here for example? 

 http://effbot.org/pyfaq/how-do-you-set-a-global-variable-in-a-function.htm 

 
  thanks
 
   Manuele 

  

[web2py] Re: storeing a db set in a storage for a map plugin

2011-07-19 Thread Anthony
Objects defined in your models and controllers do not survive from request 
to request (unless, of course, you store them somewhere, like the session). 
In your code, the Set object is created when you visit /default/index, but 
the select happens when you visit /plugin_openplayers/index, which happens 
in a different request, so the Set object no longer exists.
 
Anthony

On Tuesday, July 19, 2011 5:13:18 PM UTC-4, Manuele wrote:

 Hi *: 

 I'm trying to implement an essential version of a plugin_openlayers 
 starting from the job made by Massimo with plugin_gmap but I don't 
 understand how the db set is passed from a controller to the plugin_* 
 controller, well even if it seams clear setting the data set in a 
 storage defined in a model seams not to work and I obtains: 

File 
 /home/manuele/Dropbox/sviluppo/web2py-1.96.4/applications/wind2pow2/controllers/plugin_openlayers.py,
  

 line 8, in index
  rows = plugin_openlayers.set.select()
 AttributeError: 'NoneType' object has no attribute 'select' 

 so it seams that when I fix the new value in the plugin_openlayers 
 storage in my controller function it does not change the value in the 
 storage defined in model. 

 I hope to be clear
 can you help me please? 


 I leave you here under some example code... 

 models/plugin_openlayers.py 

 from gluon.storage import Storage
 plugin_openlayers=Storage()
  

 controllers/plugin_openlayers.py 

 def index():
  width = request.vars.width or 400
  height = request.vars.height or 300 

  rows = plugin_openlayers.set.select() 

  return dict(width=width, height=height, rows=rows)
  

 controllers/default.py 

 def index():
  site_id = request.vars.item_id
  plugin_openlayers.set = db(db.site.id==site_id)
  return dict()
  

 thank you very much 

 Manuele