Closed samuelcolvin closed 9 years ago
This is an excellent idea, but I'd suggest generalising it a little:
serialize_meta
, which opens the doors to people using a non-JSON encoding, and puts it into the public namespace of the class.deserialize_meta
, which is a hook for turning it back into a dict again. Use this method instead of json.loads in the SearchEntry body.serialize_meta
implementation. This takes care of datetimes, I believe, which is nice.I'm not sure that tests are needed, as the current test suite already checks that meta can be saved and loaded.
will do.
On a related note, I don't think meta
is documented anywhere. Maybe worth adding to the wiki.
Ok, sorry for delay, I think this is done. Django's DjangoJSONEncoder
isn't as powerful as one might hope, so I've extended it to cope with a few more types, code partially borrowed from raven-python.
This looks pretty sweet.
One last question: do you think that the serialize/deserialize meta methods belong on SearchAdapter or SearchEngine? Overriding them on SearchAdapter would seem to be easier for the majority of users, since overriding SearchEngine is a bit more arcane.
yes, i thought that when i was making the change but didn't want to change any more than I had to.
I'll move both methods to the adapter.
Wonderful! Thanks for your patience in getting this just right. :)
currently if you want to customise the behaviour of the json dump method you would have to either:
_update_obj_index_iter
return json.loads(json.dumps(meta, cls=CustomerEncoder))
at the end ofget_meta
.This is particularly useful for things like lazy translations or
Decimal
s where customer encoders can be very helpful in JSONifying data.If you think this makes sense, I can also add: