You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2018/07/09 22:42:39 UTC

[2/2] allura git commit: [#8216] Personal Dashboard - Create Followers Section

[#8216] Personal Dashboard - Create Followers Section


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/ce15220f
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/ce15220f
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/ce15220f

Branch: refs/heads/master
Commit: ce15220f18bc4c4eee30a04d5d6c6c469d5005ef
Parents: 650e181
Author: deshanigtk <de...@cse.mrt.ac.lk>
Authored: Sat Jul 7 00:23:53 2018 +0530
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Mon Jul 9 18:42:20 2018 -0400

----------------------------------------------------------------------
 .../ext/personal_dashboard/config/__init__.py   | 16 ++++++
 .../ext/personal_dashboard/config/resources.py  | 23 ++++++++
 .../ext/personal_dashboard/dashboard_main.py    | 49 ++++++++++++++--
 .../templates/sections/activity.html            | 60 ++++++++++++++++++++
 .../templates/sections/followers.html           | 29 ----------
 .../tests/functional/test_personal_dashboard.py |  2 +-
 Allura/setup.py                                 |  2 +-
 7 files changed, 146 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/ce15220f/Allura/allura/ext/personal_dashboard/config/__init__.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/personal_dashboard/config/__init__.py b/Allura/allura/ext/personal_dashboard/config/__init__.py
new file mode 100644
index 0000000..144e298
--- /dev/null
+++ b/Allura/allura/ext/personal_dashboard/config/__init__.py
@@ -0,0 +1,16 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.

http://git-wip-us.apache.org/repos/asf/allura/blob/ce15220f/Allura/allura/ext/personal_dashboard/config/resources.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/personal_dashboard/config/resources.py b/Allura/allura/ext/personal_dashboard/config/resources.py
new file mode 100644
index 0000000..5d98bd3
--- /dev/null
+++ b/Allura/allura/ext/personal_dashboard/config/resources.py
@@ -0,0 +1,23 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+import pkg_resources
+
+
+def register_ew_resources(manager):
+    manager.register_directory(
+        'activity_js', pkg_resources.resource_filename('forgeactivity', 'widgets/resources/js'))

http://git-wip-us.apache.org/repos/asf/allura/blob/ce15220f/Allura/allura/ext/personal_dashboard/dashboard_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/personal_dashboard/dashboard_main.py b/Allura/allura/ext/personal_dashboard/dashboard_main.py
index d5676b7..16c0fad 100644
--- a/Allura/allura/ext/personal_dashboard/dashboard_main.py
+++ b/Allura/allura/ext/personal_dashboard/dashboard_main.py
@@ -17,13 +17,18 @@
 
 import logging
 
-from pylons import tmpl_context as c
-from tg import expose, redirect
+from pylons import tmpl_context as c, app_globals as g
+from tg import expose, redirect, config
+from itertools import islice, ifilter
+from ming.orm import session
 
+from allura.model.timeline import perm_check, get_activity_object
 from allura.controllers import BaseController
 from allura.controllers.feed import FeedController
 from allura.lib.widgets.user_profile import SectionBase, SectionsUtil, ProjectsSectionBase
 from allura.lib.widgets import form_fields as ffw
+from paste.deploy.converters import asbool
+from forgeactivity.widgets.follow import FollowToggle
 
 log = logging.getLogger(__name__)
 
@@ -131,5 +136,41 @@ class MergeRequestsSection(DashboardSectionBase):
         return dict(merge_requests=merge_requests)
 
 
-class FollowersSection(DashboardSectionBase):
-    template = 'allura.ext.personal_dashboard:templates/sections/followers.html'
+class ActivitySection(DashboardSectionBase):
+    template = 'allura.ext.personal_dashboard:templates/sections/activity.html'
+
+    def __init__(self, user):
+        super(DashboardSectionBase, self).__init__(user)
+        self.activity_app = c.user.private_project().app_instance('activity')
+
+    def check_display(self):
+        app_installed = self.activity_app is not None
+        activity_enabled = asbool(config.get('activitystream.enabled', False))
+        return app_installed and activity_enabled
+
+    def prepare_context(self, context):
+        full_timeline = g.director.get_timeline(
+            self.user, page=0, limit=100,
+            actor_only=False,
+        )
+        filtered_timeline = list(islice(ifilter(perm_check(c.user), full_timeline),
+                                        0, 8))
+        for activity in filtered_timeline:
+            # Get the project for the activity.obj so we can use it in the
+            # template. Expunge first so Ming doesn't try to flush the attr
+            # we create to temporarily store the project.
+            #
+            # The get_activity_object() calls are cheap, pulling from
+            # the session identity map instead of mongo since identical
+            # calls are made by perm_check() above.
+            session(activity).expunge(activity)
+            activity_obj = get_activity_object(activity.obj)
+            activity.obj.project = getattr(activity_obj, 'project', None)
+
+        context['follow_toggle'] = FollowToggle(),
+        context['following'] = g.director.is_connected(c.user, self.user),
+        context['timeline'] = filtered_timeline
+        context['activity_app'] = self.activity_app
+
+        g.register_js('activity_js/follow.js')
+        return context

http://git-wip-us.apache.org/repos/asf/allura/blob/ce15220f/Allura/allura/ext/personal_dashboard/templates/sections/activity.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/personal_dashboard/templates/sections/activity.html b/Allura/allura/ext/personal_dashboard/templates/sections/activity.html
new file mode 100644
index 0000000..285aaa5
--- /dev/null
+++ b/Allura/allura/ext/personal_dashboard/templates/sections/activity.html
@@ -0,0 +1,60 @@
+{#-
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+-#}
+{% extends "allura.ext.personal_dashboard:templates/dashboard_section_base.html" %}
+{% import 'allura:templates/jinja_master/lib.html' as lib with context %}
+{% import 'forgeactivity:templates/macros.html' as am with context %}
+
+{% block title %}
+    Activity from people you follow
+{% endblock %}
+
+{% block actions %}
+    {% if c.user and not c.user.is_anonymous() and c.user != user %}
+        {{ follow_toggle.display(following=following) }}
+    {% endif %}
+{% endblock %}
+
+{% block section_class %}activity{% endblock %}
+
+{% block content %}
+    {% if not timeline %}
+        <p class="empty">No activity to display.</p>
+    {% else %}
+        <ul class="timeline">
+            {% for a in timeline %}
+                <li>
+                    <b>
+                        {{ a.verb.capitalize() }} {{ am.activity_obj(a.obj) }}
+                        {% if a.target.activity_name %}on {{ am.activity_obj(a.target) }}{% endif %}
+                        {% if a.obj.project %}on
+                            <a href="{{ a.obj.project.url() }}">{{ a.obj.project.name }}</a>{% endif %}
+                    </b>
+                    {% if a.obj.activity_extras.get('summary') %}
+                        <p>
+                            {{ a.obj.activity_extras.get('summary') }}
+                        </p>
+                    {% endif %}
+                    <time datetime="{{ a.published|datetimeformat }}"
+                          title="{{ a.published|datetimeformat }}">{{ h.ago(a.published, show_date_after=None) }}</time>
+                </li>
+            {% endfor %}
+        </ul>
+        <a class="view-all" href="{{activity_app.url}}">View All</a>
+    {% endif %}
+{% endblock %}

http://git-wip-us.apache.org/repos/asf/allura/blob/ce15220f/Allura/allura/ext/personal_dashboard/templates/sections/followers.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/personal_dashboard/templates/sections/followers.html b/Allura/allura/ext/personal_dashboard/templates/sections/followers.html
deleted file mode 100644
index 8c14fca..0000000
--- a/Allura/allura/ext/personal_dashboard/templates/sections/followers.html
+++ /dev/null
@@ -1,29 +0,0 @@
-{#-
-       Licensed to the Apache Software Foundation (ASF) under one
-       or more contributor license agreements.  See the NOTICE file
-       distributed with this work for additional information
-       regarding copyright ownership.  The ASF licenses this file
-       to you under the Apache License, Version 2.0 (the
-       "License"); you may not use this file except in compliance
-       with the License.  You may obtain a copy of the License at
-
-         http://www.apache.org/licenses/LICENSE-2.0
-
-       Unless required by applicable law or agreed to in writing,
-       software distributed under the License is distributed on an
-       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-       KIND, either express or implied.  See the License for the
-       specific language governing permissions and limitations
-       under the License.
--#}
-{% extends "allura.ext.personal_dashboard:templates/dashboard_section_base.html" %}
-
-{% block title %}
-    Followers
-{% endblock %}
-
-{% block actions %}{% endblock %}
-
-{% block section_class %}followers{% endblock %}
-
-{% block content %}{% endblock %}

http://git-wip-us.apache.org/repos/asf/allura/blob/ce15220f/Allura/allura/tests/functional/test_personal_dashboard.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_personal_dashboard.py b/Allura/allura/tests/functional/test_personal_dashboard.py
index 9a5169b..6d117d0 100644
--- a/Allura/allura/tests/functional/test_personal_dashboard.py
+++ b/Allura/allura/tests/functional/test_personal_dashboard.py
@@ -29,4 +29,4 @@ class TestPersonalDashboard(TestController):
         assert_in('tickets', sections)
         assert_in('projects', sections)
         assert_in('merge_requests', sections)
-        assert_in('followers', sections)
+        assert_in('activity', sections)

http://git-wip-us.apache.org/repos/asf/allura/blob/ce15220f/Allura/setup.py
----------------------------------------------------------------------
diff --git a/Allura/setup.py b/Allura/setup.py
index 8fbb87f..8eac602 100644
--- a/Allura/setup.py
+++ b/Allura/setup.py
@@ -126,7 +126,7 @@ setup(
     projects = allura.ext.personal_dashboard.dashboard_main:ProjectsSection
     tickets = allura.ext.personal_dashboard.dashboard_main:TicketsSection
     merge_requests = allura.ext.personal_dashboard.dashboard_main:MergeRequestsSection
-    followers = allura.ext.personal_dashboard.dashboard_main:FollowersSection
+    followers = allura.ext.personal_dashboard.dashboard_main:ActivitySection
 
     [allura.webhooks]
     repo-push = allura.webhooks:RepoPushWebhookSender