allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [35/50] [abbrv] git commit: [5453] Removed loops through entry points
Date Mon, 25 Feb 2013 21:56:17 GMT
[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/b1b3dc3d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/b1b3dc3d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/b1b3dc3d

Branch: refs/heads/si/5453
Commit: b1b3dc3db3c1e2745529c7fa7f3029f3ee538ad4
Parents: ac7da23
Author: Stefano Invernizzi <stefanoinve@apache.org>
Authored: Sat Jan 19 17:29:34 2013 +0100
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Mon Feb 25 20:20:56 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/b1b3dc3d/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/b1b3dc3d/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)
 


Mime
View raw message