>From View, I am calling server side controller function via web2py's
ajax function with ':eval'
So far, so good.

Further I need to return a dict from this ajax controller (in addition
to "return js"),
Then access this dict in View & process it.
Finally, return dict to another controller for server side processing.

++++++++++++++++++++++++++++++++++++++
I am doing it like this.

def func1():
    D = ({1:'a', 2:'b'}, {3:'c', 4:'d'})
    cPickle.dump(D, open( "my_pkcl.p", "wb"))
    return dict()

This D is accessed in 'View' and processed.

#### (Why I am not using   return dict(D=D)?
#### It is explained at the end.)

{{newD = cPickle.load(open( "my_pkcl.p", "rb" ))}}
{{for i in newD:}}
.......processing statements.......
{{pass}}

After processing newD, it is again pickled with same filename.
{{cPickle.dump(newD, open( "my_pkcl.p", "wb" ) )}}

Then ajax function is called--
ajax("{{=URL('func2)}}", [], ":eval");

def func2():
# access the D which has been changed by 'View' code
    changedD = cPickle.load( open( "my_pkcl.p", "rb" ) )
    ...
    ...
    process changedD as per requirement

++++++++++++++++++++++++++++++++++++++
Why I am not using return dict(D=D)?
While calling 'func2' via web2py's ajax function, I can't pass the
Dict (or any other python object) as argument or vars.
So I resorted to cPickle it.
+++++++++++++++++++
My question is:--
I am cPickling in controller & loading (unpickling) in View.
After processing in view, cPickling it & again loading (unpickling) in
controller.

Is it OK or is it weired / horrible (considering speed & good coding
practice) ?
If not OK, how do I do it with any alternative method ?

Thanks,

Vineet

Reply via email to