From 4d879275c640efb9886aa923aac137eb8546ac0c Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Jun 04 2015 20:24:28 +0000 Subject: Add an avatar widget. --- diff --git a/hubs/models.py b/hubs/models.py index 7653c2e..6c4bacf 100644 --- a/hubs/models.py +++ b/hubs/models.py @@ -108,7 +108,12 @@ class Hub(BASE): 'text': 'TODO -- put a fancy graph here..', })) hub.widgets.append(widget) - widget = Widget(plugin='sticky', index=0, + widget = Widget(plugin='avatar', index=0, + _config=json.dumps({ + 'username': username, + })) + hub.widgets.append(widget) + widget = Widget(plugin='sticky', index=1, _config=json.dumps({ 'text': 'TODO -- your feed goes here.', })) diff --git a/hubs/templates/hubs.html b/hubs/templates/hubs.html index 0bbfc90..829b51c 100644 --- a/hubs/templates/hubs.html +++ b/hubs/templates/hubs.html @@ -48,6 +48,7 @@ $.each(widgets, function(i, widget) { }, 100); }, error: function() { + $('#widget-' + widget).html('Got an error retrieving this widget. Sorry :('); console.log('error'); console.trace(); }, diff --git a/hubs/validators.py b/hubs/validators.py index 9525da1..1079234 100644 --- a/hubs/validators.py +++ b/hubs/validators.py @@ -1,9 +1,15 @@ import kitchen.text.converters +import hubs.models -def text(value): + +def text(session, value): return kitchen.text.converters.to_unicode(value) -def link(value): +def link(session, value): # TODO -- verify that this is actually a link return value + +def username(session, value): + openid = 'http://%s.id.fedoraproject.org/' % value + return not hubs.models.User.by_openid(session, openid) is None diff --git a/hubs/widgets/__init__.py b/hubs/widgets/__init__.py index f2268e7..044849e 100644 --- a/hubs/widgets/__init__.py +++ b/hubs/widgets/__init__.py @@ -3,6 +3,7 @@ from hubs.widgets import stats from hubs.widgets import rules from hubs.widgets import sticky from hubs.widgets import about +from hubs.widgets import avatar from hubs.widgets.base import AGPLv3, smartcache @@ -12,6 +13,7 @@ registry = { 'rules': rules, 'sticky': sticky, 'about': about, + 'avatar': avatar, } diff --git a/hubs/widgets/avatar.py b/hubs/widgets/avatar.py new file mode 100644 index 0000000..7360773 --- /dev/null +++ b/hubs/widgets/avatar.py @@ -0,0 +1,38 @@ +from hashlib import sha256 + +from hubs.widgets.base import argument + +import jinja2 + +from six.moves.urllib_parse import urlencode + +import hubs.validators as validators + + +template = jinja2.Template(""" + +""") + +#from hubs.widgets.chrome import panel +#chrome = panel("About") + + +@argument(name="username", + default=None, + validator=validators.username, + help="A FAS username.") +def data(session, widget, username): + + query = urlencode({ + 'd': 'retro', + 's': 312, + }) + openid = 'http://%s.id.fedoraproject.org/' % username + hash = sha256(openid.encode('utf-8')).hexdigest() + avatar = "https://seccdn.libravatar.org/avatar/%s?%s" % (hash, query) + + return dict(username=username, avatar=avatar) + + +def should_invalidate(message, session, widget): + raise NotImplementedError