From 8c4b9da4c039143940e0defcb9af08ac6a31efb2 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Mar 14 2016 15:58:06 +0000 Subject: [PATCH 1/3] Initial stubbing out of the groups page. --- diff --git a/hubs/app.py b/hubs/app.py index 39bea1f..6e4661d 100644 --- a/hubs/app.py +++ b/hubs/app.py @@ -70,6 +70,29 @@ def index(): return flask.redirect(flask.url_for('hub', name=flask.g.auth.nickname)) +@app.route('/groups') +def groups(): + if not flask.g.auth.logged_in: + return flask.redirect(flask.url_for('login_fedora')) + + # Get the list of promoted and non-promoted group hubs from the DB + promoted_names = app.config.get('PROMOTED_GROUPS') + groups = hubs.models.Hub.all_group_hubs(session) + promoted = [g for g in groups if g.name in promoted_names] + secondary = [g for g in groups if g.name not in promoted_names] + + name_of_the_month = app.config.get('HUB_OF_THE_MONTH') + hub_of_the_month = hubs.models.Hub.by_name(session, name_of_the_month) + + return flask.render_template( + 'groups.html', + promoted=promoted, + secondary=secondary, + hub_of_the_month=hub_of_the_month, + session=session, + ) + + @app.route('/') @app.route('//') def hub(name): diff --git a/hubs/default_config.py b/hubs/default_config.py index 39d7fce..a21f138 100644 --- a/hubs/default_config.py +++ b/hubs/default_config.py @@ -1 +1,8 @@ SECRET_KEY = 'changemeforreal' + +PROMOTED_GROUPS = [ + 'infra', + 'i18n', +] + +HUB_OF_THE_MONTH = 'commops' diff --git a/hubs/models.py b/hubs/models.py index ed003e3..cbe6371 100644 --- a/hubs/models.py +++ b/hubs/models.py @@ -209,6 +209,14 @@ class Hub(BASE): get = by_name @classmethod + def all_group_hubs(cls, session): + return session.query(cls).filter_by(user_hub=False).all() + + @classmethod + def all_user_hubs(cls, session): + return session.query(cls).filter_by(user_hub=True).all() + + @classmethod def create_user_hub(cls, session, username, fullname): hub = cls(name=username, summary=fullname, avatar=username2avatar(username), diff --git a/hubs/templates/groups.html b/hubs/templates/groups.html new file mode 100644 index 0000000..4ef9e3d --- /dev/null +++ b/hubs/templates/groups.html @@ -0,0 +1,113 @@ + + + Groups + + + + + + +
+
+ +
+ {% if g.auth.logged_in %} + + {% else %} + Not logged in. Click to login. + {% endif %} +
+
+ +
+ + + + +
+
+
+
+
+ +
+
+
+ +
+

Groups

+
+
+
+
+
+
+ {% for group in promoted %} + {{ group.name }} is a promoted group, and it has {{ group.subscribers | length }} subscribers and {{ group.members | length }} members, and {{group.owners | length }} owners + {% endfor %} +
+
+ +
+ +
+
+ ZOMG - {{ hub_of_the_month.name }} is the Hub Of The Month!
+ It has {{ hub_of_the_month.subscribers | length }} subscribers and {{ hub_of_the_month.members | length }} members, and {{hub_of_the_month.owners | length }} owners +
+
+ +
+ +
+
+ {% for group in secondary %} + {{ group.name }} is not a promoted group + but it has {{ group.subscribers | length }} subscribers and {{ group.members | length }} members, and {{group.owners | length }} owners + {% endfor %} +
+
+
+ + + + diff --git a/hubs/templates/hubs.html b/hubs/templates/hubs.html index 1e87956..3fe5702 100644 --- a/hubs/templates/hubs.html +++ b/hubs/templates/hubs.html @@ -64,6 +64,8 @@
  • {{hub.name}}
  • {% endfor %} + +
  • all
  • {% endif %} From 25abd48ef338097325da65d04ad5696db07edf82 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Mar 14 2016 16:06:21 +0000 Subject: [PATCH 2/3] Show how to display avatar images for each group in the groups layout. --- diff --git a/hubs/app.py b/hubs/app.py index 6e4661d..851e850 100644 --- a/hubs/app.py +++ b/hubs/app.py @@ -17,6 +17,10 @@ from hubs.utils import username2avatar app = flask.Flask(__name__) +# Register a global filter, useful for displaying user images +app.template_filter('avatar')(hubs.widgets.base.avatar) + + logging.basicConfig() diff --git a/hubs/templates/groups.html b/hubs/templates/groups.html index 4ef9e3d..db3ea4c 100644 --- a/hubs/templates/groups.html +++ b/hubs/templates/groups.html @@ -93,6 +93,13 @@
    ZOMG - {{ hub_of_the_month.name }} is the Hub Of The Month!
    It has {{ hub_of_the_month.subscribers | length }} subscribers and {{ hub_of_the_month.members | length }} members, and {{hub_of_the_month.owners | length }} owners +
    group owners
    + {% for owner in hub_of_the_month.owners %} + + {% endfor %}
    From c1b34b045647318bd29fdcb2982ed6ff6a77f678 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Mar 15 2016 14:34:37 +0000 Subject: [PATCH 3/3] Linebreak, as per review. --- diff --git a/hubs/templates/groups.html b/hubs/templates/groups.html index db3ea4c..e3368b0 100644 --- a/hubs/templates/groups.html +++ b/hubs/templates/groups.html @@ -110,6 +110,7 @@ {% for group in secondary %} {{ group.name }} is not a promoted group but it has {{ group.subscribers | length }} subscribers and {{ group.members | length }} members, and {{group.owners | length }} owners +
    {% endfor %}