From ee033f2198969af0a505f19be9d04ce13e929fd6 Mon Sep 17 00:00:00 2001 From: Khanh Ngo Date: Wed, 13 Jul 2016 21:33:21 +0700 Subject: [PATCH] Add Gravatar to display user's avatar --- app/lib/utils.py | 7 +++++++ app/templates/base.html | 6 +++--- app/templates/user_profile.html | 2 +- app/views.py | 5 +++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/lib/utils.py b/app/lib/utils.py index 3498c10..d86e8ec 100644 --- a/app/lib/utils.py +++ b/app/lib/utils.py @@ -3,6 +3,8 @@ import sys import json import requests import urlparse +import hashlib + from app import app from distutils.version import StrictVersion @@ -145,3 +147,8 @@ def pdns_api_extended_uri(version): return "/api/v1" else: return "" + +def email_to_gravatar_url(email, size=100): + hash_string = hashlib.md5(email).hexdigest() + schema = 'https' if app.config['SSL'] else 'http' + return "%s://s.gravatar.com/avatar/%s?s=%s" % (schema, hash_string, size) diff --git a/app/templates/base.html b/app/templates/base.html index fd25cc7..06f239b 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -65,7 +65,7 @@ {% if current_user.avatar %} User Image {% else %} - User Image + User Image {% endif %}