From: Ian Bicking <ianb@co...> - 2003-11-20 20:19:23
On Nov 20, 2003, at 1:02 PM, Aaron Swartz wrote:
> I'm working on a toolkit for building database-backed websites using
> SQLObject. One of the things I want to do is support static rendering,
> so rendered pages could be stored on disk as HTML files and served up
> normally until they were changed. I want to do this by trapping all
> sets and gets in SQLObject:
> When a page gets rendered it notes down every get the page makes and
> stores that info away. Then, when another page makes a set it sees if
> that set affects any rendered pages and, if so, re-renders them.
> Anyway, I see you can trap the setters and getters for attributes
> pretty easily but I was wondering if there was a way to tap into all
> database sets and gets. (If nothing else, I guess I can just create an
> SQLObject subclass with a nosy getattr and setattr.)
If you want to trap sets you can override, I think, _SO_setValue() and
set() -- all database sets go through one or the other -- maybe
sometimes both if you override a _set_ method, but I'm not sure if I
changed that or not.
For gets it's a little more complicated, but maybe that's not
necessary. An instance can be initialized with column values several
ways. I think _SO_selectInit should catch most of them, and maybe
there's a _SO_getValue for when you have _cacheValues = False.
You can also fiddle with the makeProperties function, which catches all
the getters and setters. __getattr__ and __setattr__ won't work for
you, but __getattribute__ and __setattribute__ will, if you want to be
particularly general about setters.
Ian Bicking | ianb@... | http://blog.ianbicking.org