allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [2/9] git commit: [#7292] ticket:568 Added UserProfileRestController to handle user profile API endpoint
Date Mon, 21 Apr 2014 17:24:01 GMT
[#7292] ticket:568 Added UserProfileRestController to handle user profile API endpoint


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

Branch: refs/heads/master
Commit: cf8b2b81b4df48a1305170173134f33ad50c5789
Parents: 23958c6
Author: Aleksey 'LXj' Alekseyev <gotletter@gmail.com>
Authored: Wed Apr 2 16:07:06 2014 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Mon Apr 21 17:21:56 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/rest.py           | 15 +++++++++++++++
 Allura/allura/ext/user_profile/user_main.py | 14 ++++++++++++++
 Allura/allura/model/project.py              |  5 ++++-
 3 files changed, 33 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/cf8b2b81/Allura/allura/controllers/rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/rest.py b/Allura/allura/controllers/rest.py
index 8610462..145d969 100644
--- a/Allura/allura/controllers/rest.py
+++ b/Allura/allura/controllers/rest.py
@@ -312,3 +312,18 @@ class ProjectRestController(object):
             response.content_type = 'application/rdf+xml'
             return '<?xml version="1.0" encoding="UTF-8" ?>' + c.project.doap()
         return c.project.__json__()
+
+
+class UserProfileRestController(object):
+    @expose('json:')
+    def index(self, **kw):
+        user = c.project.user_project_of
+        if not user:
+            raise exc.HTTPNotFound()
+        sections = [section(user, c.project)
+                    for section in c.app.profile_sections]
+        print sections
+        json = {}
+        for s in sections:
+            json.update(s.__json__())
+        return json

http://git-wip-us.apache.org/repos/asf/allura/blob/cf8b2b81/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 cd7bac9..87fb67b 100644
--- a/Allura/allura/ext/user_profile/user_main.py
+++ b/Allura/allura/ext/user_profile/user_main.py
@@ -41,6 +41,7 @@ from allura.controllers import BaseController
 from allura.controllers.feed import FeedArgs, FeedController
 from allura.lib.decorators import require_post
 from allura.lib.widgets.user_profile import SendMessageForm
+from allura.controllers.rest import UserProfileRestController
 
 log = logging.getLogger(__name__)
 
@@ -69,6 +70,7 @@ class UserProfileApp(Application):
         self.root = UserProfileController()
         self.templates = pkg_resources.resource_filename(
             'allura.ext.user_profile', 'templates')
+        self.api_root = UserProfileRestController()
 
     @property
     @h.exceptionless([], log)
@@ -288,6 +290,18 @@ class PersonalDataSection(ProfileSectionBase):
             context['timezone'] = tz.tzname(datetime.utcnow())
         return context
 
+    def __json__(self):
+        auth_provider = AuthenticationProvider.get()
+        return dict(
+            username=self.user.username,
+            joined=auth_provider.user_registration_date(self.user),
+            localization=self.user.get_pref('localization'),
+            sex=self.user.get_pref('sex'),
+            telnumbers=self.user.get_pref('telnumbers'),
+            skypeaccount=self.user.get_pref('skypeaccount'),
+            webpages=self.user.get_pref('webpages'),
+            availability=self.user.get_pref('availability'))
+
 
 class ProjectsSection(ProfileSectionBase):
     template = 'allura.ext.user_profile:templates/sections/projects.html'

http://git-wip-us.apache.org/repos/asf/allura/blob/cf8b2b81/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index ed581d0..3f68e94 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -989,7 +989,7 @@ class Project(MappedClass, ActivityNode, ActivityObject):
             return 'busy'
 
     def __json__(self):
-        return dict(
+        result = dict(
             shortname=self.shortname,
             name=self.name,
             _id=str(self._id),
@@ -1025,6 +1025,9 @@ class Project(MappedClass, ActivityNode, ActivityObject):
                 for ss in self.get_screenshots()
             ]
         )
+        if self.is_user_project:
+            result['profile_url'] = h.absurl('/rest' + self.url() + 'profile/')
+        return result
 
     def doap(self):
         root = ET.Element('rdf:RDF', {


Mime
View raw message