allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [1/9] git commit: [#7292] ticket:568 Added __json__ implementation for all profile secions
Date Mon, 21 Apr 2014 17:24:00 GMT
Repository: allura
Updated Branches:
  refs/heads/master 23958c68f -> 1b79f47c3


[#7292] ticket:568 Added __json__ implementation for all profile secions


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

Branch: refs/heads/master
Commit: 9f47cd6ff32dd8e055829c8c9bd0b5056f49f523
Parents: cf8b2b8
Author: Aleksey 'LXj' Alekseyev <gotletter@gmail.com>
Authored: Fri Apr 4 00:14:35 2014 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Mon Apr 21 17:21:56 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/rest.py           |  3 ++-
 Allura/allura/ext/user_profile/user_main.py | 26 +++++++++++++++++++++---
 2 files changed, 25 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/9f47cd6f/Allura/allura/controllers/rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/rest.py b/Allura/allura/controllers/rest.py
index 145d969..ee7c9c6 100644
--- a/Allura/allura/controllers/rest.py
+++ b/Allura/allura/controllers/rest.py
@@ -325,5 +325,6 @@ class UserProfileRestController(object):
         print sections
         json = {}
         for s in sections:
-            json.update(s.__json__())
+            if hasattr(s, '__json__'):
+                json.update(s.__json__())
         return json

http://git-wip-us.apache.org/repos/asf/allura/blob/9f47cd6f/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 87fb67b..44a073a 100644
--- a/Allura/allura/ext/user_profile/user_main.py
+++ b/Allura/allura/ext/user_profile/user_main.py
@@ -291,7 +291,7 @@ class PersonalDataSection(ProfileSectionBase):
         return context
 
     def __json__(self):
-        auth_provider = AuthenticationProvider.get()
+        auth_provider = AuthenticationProvider.get(request)
         return dict(
             username=self.user.username,
             joined=auth_provider.user_registration_date(self.user),
@@ -306,20 +306,36 @@ class PersonalDataSection(ProfileSectionBase):
 class ProjectsSection(ProfileSectionBase):
     template = 'allura.ext.user_profile:templates/sections/projects.html'
 
-    def prepare_context(self, context):
-        context['projects'] = [
+    def get_projects(self):
+        return [
             project
             for project in self.user.my_projects()
             if project != c.project
             and (self.user == c.user or h.has_access(project, 'read'))
             and not project.is_nbhd_project
             and not project.is_user_project]
+
+    def prepare_context(self, context):
+        context['projects'] = self.get_projects()
         return context
 
+    def __json__(self):
+        projects = [
+            {
+                'name': project['name'],
+                'url': project.url(),
+            }
+            for project in self.get_projects()]
+        return dict(projects=projects)
 
 class SkillsSection(ProfileSectionBase):
     template = 'allura.ext.user_profile:templates/sections/skills.html'
 
+    def __json__(self):
+        skills = {
+            skill['skill']['fullname']: skill['level']
+            for skill in self.user.get_skills()}
+        return dict(skills=skills)
 
 class ToolsSection(ProfileSectionBase):
     template = 'allura.ext.user_profile:templates/sections/tools.html'
@@ -327,3 +343,7 @@ class ToolsSection(ProfileSectionBase):
 
 class SocialSection(ProfileSectionBase):
     template = 'allura.ext.user_profile:templates/sections/social.html'
+
+    def __json__(self):
+        return dict(
+            socialnetworks=self.user.get_pref('socialnetworks'))


Mime
View raw message