Add a generic WebAPI app to Djblets
Review Request #221 — Created Feb. 7, 2008 and submitted
Moved much of our Review Board JSON code to Djblets and changed it to be more generic. While it only outputs JSON right now, it will be updated in an upcoming change to output XML files, if specified. We'll be able to include our webapi urls.py twice, once with a JSON path and once with an XML path, and we should be able to access the data both ways. To make this more generic, we no longer hard-code an object encoder. Now we use the ones specified in the project's settings.py file, using the WEB_API_ENCODERS variable. There's a base WebAPIEncoder class that can be overridden to provide custom encoders. We provide a BasicAPIEncoder, but projects can include their own and add it to the WEB_API_ENCODERS list. The serializer code will iterate through all registered encoders, trying to find a suitable encoder for the particular object.
Updated Review Board to use these new classes. It appears to be working so far.
Looks good. I wonder if we could maybe move some of the encoder logic into the models themselves. Do something like admin/meta and have a "class WebAPI" that defined a method to encode itself. This way the basic encoder could check that, and you'd keep model-related smarts closer to the model.