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 2013/03/28 17:57:45 UTC
[16/42] git commit: [5453] Removed loops through entry points
[5453] Removed loops through entry points
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/0bd06174
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/0bd06174
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/0bd06174
Branch: refs/heads/db/5453
Commit: 0bd0617490010e4e8e51ab886e37713f32241f99
Parents: dd02cc2
Author: Stefano Invernizzi <st...@apache.org>
Authored: Sat Jan 19 17:29:34 2013 +0100
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Mar 28 16:53:31 2013 +0000
----------------------------------------------------------------------
Allura/allura/controllers/root.py | 6 +++---
Allura/allura/model/auth.py | 21 +++++++++------------
2 files changed, 12 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0bd06174/Allura/allura/controllers/root.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/root.py b/Allura/allura/controllers/root.py
index 859394b..a387b98 100644
--- a/Allura/allura/controllers/root.py
+++ b/Allura/allura/controllers/root.py
@@ -69,9 +69,9 @@ class RootController(WsgiDispatchController):
if n and not n.url_prefix.startswith('//'):
n.bind_controller(self)
self.browse = ProjectBrowseController()
- for ep in pkg_resources.iter_entry_points("allura.stats"):
- if ep.name.lower() == 'userstats' and g.show_userstats:
- setattr(self, ep.name.lower(), ep.load()().root)
+ ep = g.entry_points["stats"].get('userstats')
+ if ep and g.show_userstats:
+ self.userstats = ep().root
super(RootController, self).__init__()
def _setup_request(self):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0bd06174/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 9ed7067..23f5366 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -36,13 +36,6 @@ from .timeline import ActivityNode, ActivityObject
log = logging.getLogger(__name__)
-#This is just to keep the UserStats module completely optional
-has_user_stats_module = False
-for ep in iter_entry_points("allura.stats"):
- if ep.name.lower() == 'userstats':
- from forgeuserstats.model.stats import UserStats
- has_user_stats_module = True
-
def smart_str(s, encoding='utf-8', strings_only=False, errors='strict'):
"""
Returns a bytestring version of 's', encoded as specified in 'encoding'.
@@ -340,16 +333,20 @@ class User(MappedClass, ActivityNode, ActivityObject):
comment=str)])
#Statistics
- if has_user_stats_module:
- stats_id = ForeignIdProperty('UserStats', if_missing=None)
- stats = RelationProperty('UserStats', via='stats_id')
- else:
- stats_id = FieldProperty(S.ObjectId, if_missing=None)
+ stats_id = FieldProperty(S.ObjectId, if_missing=None)
@property
def activity_name(self):
return self.display_name or self.username
+ @property
+ def stats(self):
+ if g.show_userstats:
+ from forgeuserstats.model.stats import UserStats
+ return UserStats.query.get(_id=self.stats_id)
+ else:
+ return None
+
def get_pref(self, pref_name):
return plugin.UserPreferencesProvider.get().get_pref(self, pref_name)