]>
git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - webapp/handlers_accounts.py
6 from handlers_base
import *
8 class AccountsAvatarHandler(BaseHandler
):
10 # Get the desired size of the avatar file
11 size
= self
.get_argument("size", 0)
15 except (TypeError, ValueError):
19 cache_handle
= "accounts-avatar-%s-%s" % (who
, size
or 0)
20 avatar
= self
.memcached
.get(cache_handle
)
23 logging
.debug("Querying for avatar of %s" % who
)
25 account
= self
.backend
.accounts
.get_by_uid(who
)
27 raise tornado
.web
.HTTPError(404)
29 avatar
= account
.get_avatar(size
)
31 # Save the avatar to cache for 6 hours
33 self
.memcached
.set(cache_handle
, avatar
, 6 * 3600)
35 # Otherwise redirect to gravatar
37 avatar
= account
.get_gravatar_url(size
)
39 if avatar
.startswith("http://"):
40 return self
.redirect(avatar
)
42 self
.set_header("Cache-Control", "public,max-age=300")
43 self
.set_header("Content-Disposition", "inline; filename=\"%s.jpg\"" % who
)
44 self
.set_header("Content-Type", "image/jpeg")