I only now saw that Fabian's app even existed! -- otherwise I may not
have written one at all. I took a look and really like it but there
are a couple of things to mention. His seems to have a bit wider
scope in mind, with the restful view functions and whatnot whereas
mine is purely aimed at adapting Django's own Python/Json serializers
to work with dojo data stores. I don't see anywhere in his code that
deals with '_reference' items and FK/M2Ms, which I definitely find
useful. Also, using <app name>.<model>__<pk> as the identifier saves
space in the store and allows to resolve the store item into a Django
model object at the same time, instead of having separate (optional)
fields for those.
My ideal serializer would take a queryset or any iterable that yields
Django model objects and format them in ItemFileRead/WriteStore
structure including hierarchy and '_reference's (ModelStore already
does the '_reference' bit. The interface should look a lot like
Django's forms.Form implementation, where the same class produces the
store and validates/saves it. Getting objects back from json is a
tricky bit because Django's DeserializedObject instances are not
actually in the database. For instance, if you produce a store that
has three items:
{}&&
{ identifier: '_id_', label: 'name', items: [
{_id_: 'auth.user__1', name: 'Joe'},
{_id_: 'auth.user__2', name: 'Bob'},
{_id_: 'auth.user__3', name: 'Mary'}
]}
When items in this store get deserialized into DeserializedObject
instances, the are not checked for reference integrity or validation
or anything -- so you basically have to do a big loop full of
get_or_create() on the item identifier otherwise you might overwrite
other objects in your database if you just blindly call save() on the
deserialized object, which can be a major security issue. Plus, any
malicious user can arbitrarily add fields to a store item, which will
get populated by Django's deserializer -- so you still have to check
that the only fields coming back to python are the ones you put in
there in the first place, (that's where the forms.Form implementation
looks appealing.)
I'll keep working on this and see if I can get it close to what I had
in mind and get some tests going. I'd love to join forces with Fabian
to get a killer dojo datastore app for Django out there, (i even gave
a thought to implementing a new dojo store altogether with Django as
the focus. Some interesting things could definitely be done with
jsonrpc -- installing automatic connections to setValue etc. that
calls back to a Django method that updates the db realtime, rather
than after a save() or saveCustom() .. just thoughts for now.)
Ben