| |
@@ -0,0 +1,53 @@
|
| |
+ import operator
|
| |
+
|
| |
+ import requests
|
| |
+
|
| |
+ from hubs.hinting import hint, prefixed as _
|
| |
+ from hubs.widgets.base import argument
|
| |
+
|
| |
+ import jinja2
|
| |
+
|
| |
+
|
| |
+ import hubs.validators as validators
|
| |
+
|
| |
+
|
| |
+ template = jinja2.Template("""
|
| |
+ <div class="flex-container">
|
| |
+ {% for badge in assertions[:10] %}
|
| |
+ <a width="60px" href="https://badges.fedoraproject.org/badge/{{badge['id']}}">
|
| |
+ <img width="60px" src="{{badge['image']}}"/></a>
|
| |
+ {%endfor%}
|
| |
+ </div>
|
| |
+ """)
|
| |
+
|
| |
+ from hubs.widgets.chrome import panel
|
| |
+ chrome = panel("Infrastructure Badges")
|
| |
+
|
| |
+
|
| |
+ @argument(name="tag",
|
| |
+ default=None,
|
| |
+ validator=validators.tag,
|
| |
+ help="A FAS badge tag.")
|
| |
+ def data(session, widget, tag):
|
| |
+ url = "https://badges.fedoraproject.org/hubs/{tag}/json"
|
| |
+ # TODO : WIP - API for Tahrir, badge_tags, url
|
| |
+ url = url.format(tag=tag)
|
| |
+ response = requests.get(url)
|
| |
+ assertions = response.json()['assertions']
|
| |
+ print assertions
|
| |
+ key = operator.itemgetter('issued')
|
| |
+ return dict(assertions=sorted(assertions, key=key, reverse=True))
|
| |
+
|
| |
+
|
| |
+ @hint(topics=[_('hubs.widget.update'), _('fedbadges.badge.award')])
|
| |
+ def should_invalidate(message, session, widget):
|
| |
+ if message['topic'].endswith('hubs.widget.update'):
|
| |
+ if message['msg']['widget']['id'] != widget.id:
|
| |
+ return True
|
| |
+
|
| |
+ # if message['topic'].endswith('fedbadges.badge.award'):
|
| |
+ # username = widget.config['username']
|
| |
+ # if message['msg']['user']['username'] == username:
|
| |
+ # return True
|
| |
+
|
| |
+ return False
|
| |