| |
@@ -1,79 +0,0 @@
|
| |
- from __future__ import unicode_literals
|
| |
-
|
| |
- import flask
|
| |
- from fedmsg.meta import msg2usernames
|
| |
- from fedmsg.meta.base import BaseConglomerator as BC
|
| |
-
|
| |
- import hubs.models
|
| |
- from hubs.utils import get_fedmsg_config
|
| |
- from hubs.widgets import validators
|
| |
- from hubs.widgets.base import Widget
|
| |
- from hubs.widgets.view import RootWidgetView
|
| |
- from hubs.widgets.caching import CachedFunction
|
| |
-
|
| |
-
|
| |
- fedmsg_config = get_fedmsg_config()
|
| |
-
|
| |
-
|
| |
- class Subscriptions(Widget):
|
| |
-
|
| |
- name = "subscriptions"
|
| |
- position = "right"
|
| |
- display_title = "Hubs"
|
| |
- hidden_if_empty = True
|
| |
- parameters = [
|
| |
- dict(
|
| |
- name="username",
|
| |
- label="Username",
|
| |
- default=None,
|
| |
- validator=validators.Username,
|
| |
- help="A FAS username.",
|
| |
- )]
|
| |
- hub_types = ['user']
|
| |
-
|
| |
-
|
| |
- class BaseView(RootWidgetView):
|
| |
-
|
| |
- def get_context(self, instance, *args, **kwargs):
|
| |
- context = {}
|
| |
- get_subs = GetSubs(instance)
|
| |
- context.update(get_subs())
|
| |
- return context
|
| |
-
|
| |
-
|
| |
- # function hyperlinks the hubs in the subscription widget
|
| |
- def manage_subscriptions(items):
|
| |
- return [
|
| |
- '<a href="{link}">{item}</a>'.format(
|
| |
- link=flask.url_for('hub', name=item),
|
| |
- item=item,
|
| |
- ) for index, item in enumerate(items[0:3])
|
| |
- ]
|
| |
-
|
| |
-
|
| |
- class GetSubs(CachedFunction):
|
| |
-
|
| |
- def execute(self):
|
| |
- username = self.instance.config["username"]
|
| |
- user = hubs.models.User.by_username(username)
|
| |
- 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_list),
|
| |
- subscriptions_text=BC.list_to_series(subscriptions_list),
|
| |
- )
|
| |
-
|
| |
- def should_invalidate(self, message):
|
| |
- if not message['topic'].endswith('hubs.associate'):
|
| |
- return False
|
| |
- username = self.instance.config['username']
|
| |
- users = msg2usernames(message, **fedmsg_config)
|
| |
- return username in users
|
| |
implement my hubs widget as per the mockup
a rework of the hubs widget to match the mockup, including a
rename from "subscriptions" to "my_hubs"
fixes #436