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:38 UTC

[1/2] allura git commit: [#8216] Personal Dashboard - Activity Section cleaning up the code

Repository: allura
Updated Branches:
  refs/heads/master 650e181ce -> 0d602084c


[#8216] Personal Dashboard - Activity Section cleaning up the code


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

Branch: refs/heads/master
Commit: 0d602084c2c80ad099de4c046b3e2ca9b39c5b5e
Parents: ce15220
Author: deshanigtk <de...@cse.mrt.ac.lk>
Authored: Mon Jul 9 22:50:06 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    |  4 ---
 .../templates/sections/activity.html            | 31 ++------------------
 .../forgeactivity/templates/macros.html         | 27 +++++++++++++++++
 .../templates/widgets/profile_section.html      | 23 +--------------
 6 files changed, 30 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/0d602084/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
deleted file mode 100644
index 144e298..0000000
--- a/Allura/allura/ext/personal_dashboard/config/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/allura/blob/0d602084/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
deleted file mode 100644
index 5d98bd3..0000000
--- a/Allura/allura/ext/personal_dashboard/config/resources.py
+++ /dev/null
@@ -1,23 +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.
-
-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/0d602084/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 16c0fad..4f2a9f9 100644
--- a/Allura/allura/ext/personal_dashboard/dashboard_main.py
+++ b/Allura/allura/ext/personal_dashboard/dashboard_main.py
@@ -28,7 +28,6 @@ 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__)
 
@@ -167,10 +166,7 @@ class ActivitySection(DashboardSectionBase):
             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/0d602084/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
index 285aaa5..98f909f 100644
--- a/Allura/allura/ext/personal_dashboard/templates/sections/activity.html
+++ b/Allura/allura/ext/personal_dashboard/templates/sections/activity.html
@@ -24,37 +24,10 @@
     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 actions %}{% 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 %}
+    {{ am.timeline_section(timeline, activity_app) }}
 {% endblock %}

http://git-wip-us.apache.org/repos/asf/allura/blob/0d602084/ForgeActivity/forgeactivity/templates/macros.html
----------------------------------------------------------------------
diff --git a/ForgeActivity/forgeactivity/templates/macros.html b/ForgeActivity/forgeactivity/templates/macros.html
index 25fed79..4f87732 100644
--- a/ForgeActivity/forgeactivity/templates/macros.html
+++ b/ForgeActivity/forgeactivity/templates/macros.html
@@ -38,3 +38,30 @@
         extra_css='emboss {} x{}'.format(className or '', size or '')) }}
   {% endif %}
 {%- endmacro %}
+
+{% macro timeline_section(timeline, activity_app) -%}
+    {% if not timeline %}
+        <p class="empty">No activity to display.</p>
+    {% else %}
+        <ul class="timeline">
+            {% for a in timeline %}
+                <li>
+                    <b>
+                        {{ a.verb.capitalize() }} {{ activity_obj(a.obj) }}
+                        {% if a.target.activity_name %}on {{ 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 %}
+{%- endmacro %}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/allura/blob/0d602084/ForgeActivity/forgeactivity/templates/widgets/profile_section.html
----------------------------------------------------------------------
diff --git a/ForgeActivity/forgeactivity/templates/widgets/profile_section.html b/ForgeActivity/forgeactivity/templates/widgets/profile_section.html
index 5f6fbee..37a19a9 100644
--- a/ForgeActivity/forgeactivity/templates/widgets/profile_section.html
+++ b/ForgeActivity/forgeactivity/templates/widgets/profile_section.html
@@ -34,26 +34,5 @@
 {% 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 %}
+    {{ am.timeline_section(timeline, activity_app) }}
 {% endblock %}


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

Posted by br...@apache.org.
[#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