espeed/bulbs — pull request #22 by reydelamirienda (2012-01-15 22:38:23+00:00)
Title: Vertex data as dictionary, and some other enhancements

One drawback of the current implementation of models is that if you load a Model that has more properties than what declared in the model class, Model.save() will delete them. There is also no possibility to add new properties, nor to inherit properties from base classes.

I have modified my branch (and broken the API on the way). Now data is stored in a dictionary in the Element, and can be accessed as if Element was a dict().

Model properties can still be accessed with getattr (although the new implementation does not yet support custom fget/fset as it's not one of my feature priorities), but are redirected to the dictionary, with type checking and coercing. It is possible to access the property data as done for Vertex (dict-like) to bypass the type mangling.

It is possible to extend models (cls._properties gets shallow-copied in the metaclass __init__). It's quite crude now, I can't "get_all()" from "animals" and get the "cats" and "dogs" subclasses, but in the future, with the help of indexes I may add support for polymorphic queries and even multiple inheritance.

cheers