#111 Fixes #10 : Added the subscribed_to stats and Subscribe/Unsubscribe button
Merged 8 years ago by ralph. Opened 8 years ago by devyani7.
devyani7/fedora-hubs subscribed_to  into  develop

file modified
+6 -5
@@ -137,7 +137,7 @@ 

      last_refreshed = sa.Column(sa.DateTime, default=datetime.datetime.utcnow)

      last_edited = sa.Column(sa.DateTime, default=datetime.datetime.utcnow)

  

-     #fas_group = sa.Column(sa.String(32), nullable=False)

+     # fas_group = sa.Column(sa.String(32), nullable=False)

  

      @property

      def days_idle(self):
@@ -168,7 +168,7 @@ 

      @property

      def members(self):

          return [assoc.user for assoc in self.associations

-                 if assoc.role == 'member' or assoc.role =='owner']

+                 if assoc.role == 'member' or assoc.role == 'owner']

  

      @property

      def subscribers(self):
@@ -250,6 +250,7 @@ 

              'subscribers': [u.username for u in self.subscribers],

          }

  

+ 

  def _config_default(context):

      plugin_name = context.current_parameters['plugin']

      plugin = hubs.widgets.registry[plugin_name]
@@ -306,7 +307,6 @@ 

      fullname = sa.Column(sa.Text)

      created_on = sa.Column(sa.DateTime, default=datetime.datetime.utcnow)

  

- 

      def __json__(self, session):

          return {

              'username': self.username,
@@ -315,17 +315,18 @@ 

              'fullname': self.fullname,

              'created_on': self.created_on,

              # We'll need hubs subscribed to, owned, etc..

-             #'hubs': [hub.idx for hub in self.hubx],

+             # 'hubs': [hub.idx for hub in self.hubx],

          }

  

      @property

      def ownerships(self):

          return [assoc.hub for assoc in self.associations

                  if assoc.role == 'owner']

+ 

      @property

      def memberships(self):

          return [assoc.hub for assoc in self.associations

-                 if assoc.role == 'member' or assoc.role =='owner']

+                 if assoc.role == 'member' or assoc.role == 'owner']

  

      @property

      def subscriptions(self):

@@ -16,7 +16,11 @@ 

              u'fedmsgs': 83854,

              u'fedmsgs_text': u'83,854',

              u'source_url': u'/source/fedmsgstats/',

-             u'subscribers': 0,

+             u'subscribers': [],

+             u'subscribed_to': [],

              u'subscribers_text': u'0',

+             u'subscribed_text': u'0',

              u'username': u'ralph',

+             u'hub_subscribe_url': u'/api/hub/ralph/subscribe',

+             u'hub_unsubscribe_url': u'/api/hub/ralph/unsubscribe',

          })

file modified
+21 -5
@@ -3,6 +3,7 @@ 

  

  from hubs.utils import commas

  

+ import flask

  import jinja2

  import requests

  
@@ -16,13 +17,21 @@ 

  <div class="stats-container row">

    <div class="col-sm-7 col-md-12 col-lg-7">

    <table class="stats-table">

-     <tr><th>FedMsgs</th><th>Subscribers</th></tr>

-     <tr class="text-info"><td>{{fedmsgs_text}}</td><td class="text-right">{{subscribers_text}}</td></tr>

+     <tr><th>subscribers</th><th>Subscribed_to</th></tr>

+     <tr class="text-info"><td>{{subscribers_text}}</td><td class="text-center">{{subscribed_text}}</td></tr>

    </table>

    </div>

    <div class="col-sm-5 col-md-12 col-lg-5">

    {% if session['nickname'] != username %}

-   <div class="pull-right"><button class="btn btn-info">Subscribe</button></div>

+     {% if session['nickname'] in subscribers %}

+     <li><form action="{{hub_unsubscribe_url}}" method="POST">

+         <button class="btn btn-info"><span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span> Unsubscribe</button>

+     </form></li>

+     {% else %}

+     <li><form action="{{hub_subscribe_url}}" method="POST">

+         <button class="btn btn-default"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Subscribe</button>

+     </form></li>

+     {% endif %}

    {% endif %}

    </div>

  </div>
@@ -34,12 +43,19 @@ 

      url = url.format(username=username)

      response = requests.get(url)

      fedmsgs = response.json()['total']

+     for assoc in widget.hub.associations:

+         sub_list = [u.name for u in assoc.user.subscriptions]

+     subscribers = [u.username for u in widget.hub.subscribers]

      return dict(

          username=username,

          fedmsgs=fedmsgs,

-         subscribers=len(widget.hub.subscribers),

+         subscribers=subscribers,

+         subscribed_to=sub_list,

          fedmsgs_text=commas(fedmsgs),

-         subscribers_text=commas(len(widget.hub.subscribers)),

+         subscribers_text=commas(len(subscribers)),

+         subscribed_text=commas(len(sub_list)),

+         hub_subscribe_url=flask.url_for('hub_subscribe', hub=widget.hub.name),

+         hub_unsubscribe_url=flask.url_for('hub_unsubscribe', hub=widget.hub.name),

      )

  

  

no initial comment

I think this line can be dropped since user.associations already exists.

I think this line can be dropped since hub.associations already exists.

Can you show a screenshot?

Pull-Request has been rebased

8 years ago

Pull-Request has been rebased

8 years ago

Pull-Request has been updated

8 years ago

Cool :)

It should probably say "Subscribed To" instead of "Subscribed_To" like in the mockup in #10.

Well, we can fix that aftewards. Thanks @devyani7!

Pull-Request has been merged by ralph

8 years ago