You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2014/01/22 15:58:02 UTC
[5/7] 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/dc1ade58
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/dc1ade58
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/dc1ade58
Branch: refs/heads/master
Commit: dc1ade5827eeb4b3d80fc3c11de6cdc4de2b814b
Parents: cae66cc
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Thu Jan 16 16:03:13 2014 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Wed Jan 22 14:26:21 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/dc1ade58/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/dc1ade58/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)