Hey Bryan,
Just to frame the problem again -
I'm working on a device detection pluggable called "device" using
Device Atlas:
http://deviceatlas.com/
Currently I'm offering two methods to add device related information
to the request object - a decorator and a middleware. Both function
the same way:
1) Get the user agent string from request.META['HTTP_USER_AGENT']
2) Do a lookup for the UA string in Device Atlas.
3) Stash the object returned from Device Atlas into request.
For the middleware I'm using the process_request function:
http://www.djangoproject.com/documentation/middleware/#process-request
I decided to use it instead of process_view because it was my
understanding that it's possible that process_view will never be
called in a request. For instance a 404 intreupts the normal request
cycle. However you might still want access to device information to
display in your 404 page.
Bryan you bring up some very good points -
Certainly I should add caching of some sort - but I'm not sure whether
it should be user specific as with sessions. Users may access the same
site with different devices. Perhaps as you suggested, it would be
better to cache the results of the Device Atlas query so that if the
same UA string showed up it could be pulled from the cache.
Cheers,
John