Changes between Version 55 and Version 56 of S3REST


Ignore:
Timestamp:
08/21/10 13:09:55 (11 years ago)
Author:
Fran Boon
Comment:

Passing information between main Controller & Prep

Legend:

Unmodified
Added
Removed
Modified
  • S3REST

    v55 v56  
    151151There is also a '''post-processing hook''' (response.s3.postp) that allows you to execute something directly after the REST request has been executed, but before the shn_rest_controller returns. The post-hook function will be called with the current S3RESTRequest and the output dict of its execution as arguments.
    152152
     153==== Passing information between main Controller & Prep ====
     154Scope normally means that these 2 sections can only talk to each other via globals or the Request object.
     155
     156If you need to pass data between them, you can use this trick:
     157{{{
     158vars = {} # the surrounding dict
     159def prep(r, vars):
     160    vars.update(x=y) # the actual variable to pass is x
     161    return True
     162
     163response.s3.prep = lambda r, vars=vars: prep(r, vars)
     164
     165output = shn_rest_controller(module, resource)
     166
     167x = vars.get(x, None)
     168}}}
     169
     170An example usage is in {{{controllers/gis.py}}} for location()
    153171== S3RESTRequest ==
    154172