Changes between Version 8 and Version 9 of ClassBasedViews


Ignore:
Timestamp:
Oct 2, 2010, 12:54:45 PM (14 years ago)
Author:
George Sakkis
Comment:

Syntax sugar for storing state on request through getattr/setattr

Legend:

Unmodified
Added
Removed
Modified
  • ClassBasedViews

    v8 v9  
    3232Pass around the request object via method arguments, store arbitrary state on the request or a special "state" object or dict that is passed around or attached to the request.
    3333
    34 Document that state should be stored on the request, storing it on the view instance is unsafe. Additionally, override __setattr__ or __setattribute__ to make setting state on self raise an error or warning.
     34Document that state should be stored on the request, storing it on the view instance is unsafe. Additionally, override `__setattr__` to make setting state on self raise an error or warning.
     35
     36Alternatively, override `__getattr__/__setattr__` to access `self.request.state` under the hood while on the surface it looks as if the state is stored on the view instance.
    3537
    3638Example usage and view would be the same as shown below in "__call__ and copy()".
     
    4244
    4345Arguments against:
    44  * It's unusual to have a class where you can't store state on self.
     46 * It's unusual to have a class where you can't store state on self while in `__init__`.
    4547
    4648==== !__call!__() and copy() ====
Back to Top