#72 WIP : Initial commit for hub_badges widget
Closed 8 years ago by ralph. Opened 8 years ago by devyani7.
devyani7/fedora-hubs hub_badges  into  develop

file modified
+4
@@ -17,6 +17,10 @@ 

      openid = 'http://%s.id.fedoraproject.org/' % value

      return not hubs.models.User.by_openid(session, openid) is None

  

+ def tag(session, value):

+     # TODO : WIP -- verify that this is a valid badge tag.

+     return value

+ 

  def fmn_context(session, value):

      # TODO get this from the fedmsg config.

      return value in [

@@ -5,6 +5,7 @@ 

  from hubs.widgets import about

  from hubs.widgets import avatar

  from hubs.widgets import badges

+ from hubs.widgets import hub_badges

  from hubs.widgets import fedmsgs

  from hubs.widgets import fedmsgstats

  from hubs.widgets import feed
@@ -26,6 +27,7 @@ 

      'about': about,

      'avatar': avatar,

      'badges': badges,

+     'hub_badges': hub_badges,

      'fedmsgs': fedmsgs,

      'fedmsgstats': fedmsgstats,

      'feed': feed,

@@ -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

file modified
+4 -1
@@ -12,7 +12,7 @@ 

  

  users = ['mrichard', 'duffy', 'ryanlerch', 'gnokii', 'nask0',

           'abompard', 'decause', 'ralph', 'lmacken', 'croberts', 'mattdm',

-          'pravins']

+          'pravins', 'devyani7']

  for username in users:

      fullname = 'Full Name Goes Here'

      openid = '%s.id.fedoraproject.org' % username
@@ -200,6 +200,9 @@ 

  widget = hubs.models.Widget(plugin='dummy', index=3, left=True)

  hub.widgets.append(widget)

  

+ widget = hubs.models.Widget(plugin='hub_badges', index=4, left=True,

+                             _config=json.dumps({'tag': tag, }))

+ hub.widgets.append(widget)

  

  hub.subscribe(session, hubs.models.User.by_openid(session, 'ralph.id.fedoraproject.org'), 'owner')

  hub.subscribe(session, hubs.models.User.by_openid(session, 'abompard.id.fedoraproject.org'), 'owner')

no initial comment

Cool. Let's wait to merge this until after we write the new pieces for the tahrir API (so we can test it).

@ralph setting up tahrir. will try my luck with the API ! :)

OK, @devyani7. Let's close this PR for now until the tahrir stuff is in place.

Once that's working, please re-open this. Thanks!