You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2014/01/16 17:03:31 UTC

[4/4] git commit: [#7002] Improved profile section caching and added docstring

[#7002] Improved profile section caching and added docstring

Signed-off-by: Cory Johns <cj...@slashdotmedia.com>


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

Branch: refs/heads/cj/7002
Commit: 2590b2ed1109317b39796993407f3e1bc3d4b49f
Parents: 0b3f650
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Thu Jan 16 16:03:13 2014 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Thu Jan 16 16:03:13 2014 +0000

----------------------------------------------------------------------
 Allura/allura/ext/user_profile/user_main.py     | 21 +++++++++++++++++---
 .../tests/functional/test_user_profile.py       | 12 +++++------
 2 files changed, 24 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2590b2ed/Allura/allura/ext/user_profile/user_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/user_profile/user_main.py b/Allura/allura/ext/user_profile/user_main.py
index 530d5a3..788d8a2 100644
--- a/Allura/allura/ext/user_profile/user_main.py
+++ b/Allura/allura/ext/user_profile/user_main.py
@@ -26,7 +26,6 @@ from formencode import validators
 from tg import expose, redirect, validate, flash
 import tg
 from webob import exc
-from ming.utils import LazyProperty
 from jinja2 import Markup
 
 from allura import version
@@ -88,8 +87,23 @@ class UserProfileApp(Application):
     def uninstall(self, project):  # pragma no cover
         pass
 
-    @LazyProperty
+    @property
     def profile_sections(self):
+        """
+        Loads and caches user profile sections.
+
+        Profile sections are loaded unless disabled (see
+        `allura.lib.helpers.iter_entry_points`) and are sorted according
+        to the `user_profile_sections.order` config value.
+
+        The config should contain a comma-separated list of entry point names
+        in the order that they should appear in the profile.  Unknown or
+        disabled sections are ignored, and available sections that are not
+        specified in the order come after all explicitly ordered sections,
+        sorted randomly.
+        """
+        if hasattr(UserProfileApp, '_sections'):
+            return UserProfileApp._sections
         sections = {}
         for ep in h.iter_entry_points('allura.user_profile.sections'):
             sections[ep.name] = ep.load()
@@ -98,7 +112,8 @@ class UserProfileApp(Application):
         for section in re.split(r'\s*,\s*', section_ordering):
             if section in sections:
                 ordered_sections.append(sections.pop(section))
-        return ordered_sections + sections.values()
+        UserProfileApp._sections = ordered_sections + sections.values()
+        return UserProfileApp._sections
 
 
 class UserProfileController(BaseController, FeedController):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2590b2ed/Allura/allura/tests/functional/test_user_profile.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_user_profile.py b/Allura/allura/tests/functional/test_user_profile.py
index 71ae05a..1f58868 100644
--- a/Allura/allura/tests/functional/test_user_profile.py
+++ b/Allura/allura/tests/functional/test_user_profile.py
@@ -173,9 +173,9 @@ class TestUserProfile(TestController):
                         eps[2].load(),
                         eps[0].load(),
                     ])
-                r = self.app.get('/u/test-user/profile')
-                assert_in('Section a', r.body)
-                assert_in('Section b', r.body)
-                assert_in('Section c', r.body)
-                assert_in('Section d', r.body)
-                assert_not_in('Section f', r.body)
+        r = self.app.get('/u/test-user/profile')
+        assert_in('Section a', r.body)
+        assert_in('Section b', r.body)
+        assert_in('Section c', r.body)
+        assert_in('Section d', r.body)
+        assert_not_in('Section f', r.body)