Rational
Avatar are good in helping user to identify entities (like users, parties etc.).
Implementing it in Tryton should take care of minimized the load. This should be solved by sending the proper size for the picture, compress it and caching it on the client side.
Proposal
A new internal model is defined to store avatar for any resource (like the attachment or note). It stores the full size binary data of the image on the filestore
. The base image is converted into jpeg (using configured quality level) and resized/cropped to be a square of maximum 2048px.
We store in a One2Many a version of the image (in filestore
) as cache for a specific size.
A Mixin can be added to any Model which adds a link to the avatar and a Function field that retrieve the image for a defined size. The setter is responsible to set the base image and to clear the cache.
The Mixin provides a method to get a public URL for the avatar without leaking any information. So the identifier of the avatar record is a random string (and not the ID).
A public route serves the avatar and has as parameter for the size. The Mixin provides a method to construct the URL to this route. The hostname is configurable in order to use a CDN and also the cache expiration. The database name will be hidden the same way as in web_shortener
module.
On the client side the <image/>
is extended to have a type
attribute which can be icon
(current and default behavior) or url
. When it is url
, the client get the content using the name as url and cache the result if possible. The size is appended to the url as parameter.
The <image/>
tag is added also to the tree
view.
By default the avatar feature is added to res.user
and web.user
. A module is created to add avatar to party.party
.
Implementation
Future
A similar design could be implemented to manage pictures of products.