From 5a98296e97f8ccacb58df2a50f8e202347c3cff6 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: May 04 2016 13:27:31 +0000 Subject: Drop the change for the avatar Now all the avatar work is done in one location instead of two. --- diff --git a/hubs/app.py b/hubs/app.py index 2037a04..1a77545 100755 --- a/hubs/app.py +++ b/hubs/app.py @@ -6,7 +6,6 @@ import os import flask import flask.json import munch -import requests import six from flask.ext.openid import OpenID @@ -24,7 +23,7 @@ app = flask.Flask(__name__) def days_since(then): return (datetime.datetime.utcnow() - then).days app.template_filter('days_since')(days_since) -app.template_filter('avatar')(hubs.widgets.base.avatar) +app.template_filter('avatar')(username2avatar) logging.basicConfig() @@ -79,21 +78,6 @@ def index(): return flask.redirect(flask.url_for('hub', name=flask.g.auth.nickname)) -@app.route('/_avatar/') -def avatar(username): - favicon = os.path.join( - app.static_folder, 'cache', '%s.png' % username) - if not os.path.exists(favicon): - req = requests.get(hubs.utils.username2avatar(username, s=32)) - if req: - with open(favicon, 'w') as stream: - stream.write(req.content) - - return flask.redirect( - flask.url_for('static', filename='cache/%s.png' % username) - ) - - @app.route('/groups') def groups(): if not flask.g.auth.logged_in: diff --git a/hubs/models.py b/hubs/models.py index d228464..49a9503 100755 --- a/hubs/models.py +++ b/hubs/models.py @@ -41,6 +41,7 @@ import fedmsg.utils import hubs.defaults import hubs.widgets +from hubs.utils import username2avatar class HubsBase(object): @@ -227,7 +228,7 @@ class Hub(BASE): @classmethod def create_user_hub(cls, session, username, fullname): hub = cls(name=username, summary=fullname, - avatar=hubs.widget.base.avatar(username), + avatar=username2avatar(username), user_hub=True) session.add(hub) @@ -241,7 +242,7 @@ class Hub(BASE): def create_group_hub(cls, session, name, summary, **extra): hub = cls(name=name, summary=summary, # TODO -- do something else, smarter for group avatars - avatar=hubs.widget.base.avatar(username), + avatar=username2avatar(username), user_hub=False) session.add(hub) @@ -348,7 +349,7 @@ class User(BASE): return { 'username': self.username, 'openid': self.openid, - 'avatar': hubs.widget.base.avatar(self.username), + 'avatar': username2avatar(self.username), 'fullname': self.fullname, 'created_on': self.created_on, # We'll need hubs subscribed to, owned, etc.. diff --git a/hubs/widgets/base.py b/hubs/widgets/base.py index e8efbdc..91d3931 100755 --- a/hubs/widgets/base.py +++ b/hubs/widgets/base.py @@ -96,7 +96,3 @@ def wraps(original): subsequent.widget_arguments = getattr(original, 'widget_arguments', []) return subsequent return decorator - - -def avatar(username, size=32): - return flask.url_for('avatar', username=username) diff --git a/hubs/widgets/rules.py b/hubs/widgets/rules.py index d0bfad7..edf141a 100755 --- a/hubs/widgets/rules.py +++ b/hubs/widgets/rules.py @@ -2,8 +2,9 @@ from collections import OrderedDict as ordereddict from hubs.hinting import hint, prefixed as _ from hubs.widgets.chrome import panel -from hubs.widgets.base import argument, avatar +from hubs.widgets.base import argument from hubs.widgets import templating +from hubs.utils import username2avatar from hubs import validators chrome = panel() @@ -25,7 +26,9 @@ position = 'both' help="Link to meeting minutes from past meetings..") def data(session, widget, link, schedule_text, schedule_link, minutes_link): owners = widget.hub.owners - owners = ordereddict([(o.username, avatar(o.username)) for o in owners]) + owners = ordereddict([ + (o.username, username2avatar(o.username)) for o in owners + ]) return dict(owners=owners, link=link, schedule_text=schedule_text, schedule_link=schedule_link,