#54 Fixed issue #53: Added clickable links for subscribed hubs
Merged 8 years ago by ralph. Opened 8 years ago by devyani7.
devyani7/fedora-hubs subscribe_link  into  develop

file modified
+15 -4
@@ -1,4 +1,4 @@ 

- #from hubs.hinting import hint, prefixed as _

+ # from hubs.hinting import hint, prefixed as _

  from hubs.widgets.base import argument

  from hubs.widgets.chrome import panel

  
@@ -8,13 +8,14 @@ 

  

  from fedmsg.meta.base import BaseConglomerator as BC

  

+ import flask

  import jinja2

  

  chrome = panel('Hubs', key='associations')

  template = jinja2.Template("""

  {% if associations %}

      {% if memberships %}

-         <p><strong>Belongs to: </strong>{{memberships_text}}</p>

+         <p><strong>Belongs to: </strong> {{memberships_text}}</p>

      {% endif %}

      <hr/>

      {% if subscriptions %}
@@ -33,16 +34,26 @@ 

      ownerships = [u.name for u in user.ownerships]

      memberships = [u.name for u in user.memberships]

      subscriptions = [u.name for u in user.subscriptions]

+     subscriptions_list = manage_subscriptions(subscriptions)

+     memberships_list = manage_subscriptions(memberships)

      return dict(

          associations=memberships + ownerships,

          ownerships=ownerships,

          memberships=memberships,

          subscriptions=subscriptions,

          ownerships_text=BC.list_to_series(ownerships),

-         memberships_text=BC.list_to_series(memberships),

-         subscriptions_text=BC.list_to_series(subscriptions),

+         memberships_text=BC.list_to_series(memberships_list),

+         subscriptions_text=BC.list_to_series(subscriptions_list),

      )

  

  

+ # function hyperlinks the hubs in the subscription widget

+ def manage_subscriptions(items):

+     for index, item in enumerate(items[0:3]):

+         link = '<a href="{link}">{item}</a>'.format(link=flask.url_for(

+             'hub', name=item), item=item)

+         yield link

+ 

+ 

  def should_invalidate(message, session, widget):

      raise NotImplementedError()

no initial comment

Is subscriptions_text no longer used? If so, should we also remove the code that generates it?

Did that code do anything special when generating subscriptions_text?

@ralph it just had the extra and in between the hub names. Nothing more it seems.

i meant, an extra "and" in between the hub names.

A couple things here.

  • First, there's a lot of one-letter variable names here. Can you rewrite it to use full words to help with readability? Perhaps items instead of s and index instead of j and item instead of i.

  • Second, I think this is modifying the contents of the original memberships and descriptions data structures, such that the JSON associated with the widget is going partially contain links. Maybe instead of modifying s here, you could use a generator pattern to avoid manipulating the list.

Metadata