quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Graham Dumpleton" <grah...@dscpl.com.au>
Subject Re: Clarification on example provided
Date Thu, 07 Dec 2006 21:50:30 GMT
Martin Stoufer wrote ..
> Graham,
>     After pouring over the comments sent by you and Jim regarding my 
> session/class examples, I have a better feel for what is expected in 
> good coding models. Could you make some clarifications on one of the 
> examples you provided:
> 
> class SessionEnabled:
>     def __init__(self, target):
>       self.__target = target
>     def __call__(self):
>       if not hasattr(req, 'session'):
>          req.session = Session.Session(req)
>       return util.apply_fs_data(self.__target, req.form)
> 
>   def _function(req, a, b):
>     return a,b
> 
>   function = SessionEnabled(_function)
> 
> Was the 'req' arg left off the __call__ method by mistake?
> 
> I'm still a bit fuzzy about how the apply_fs_data() properly passes the
> req object down into the target function. My sandbox working example for
> this keeps complaining that no arguments are being provided to the function.

Yes, missed 'req' argument.

     def __call__(self, req):
       if not hasattr(req, 'session'):
          req.session = Session.Session(req)
       return util.apply_fs_data(self.__target, req.form)

Note, this works on basis that mod_python.publisher has already read in form
input and cached form object as req.form.

Graham

Mime
View raw message