Return-Path: X-Original-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 79E4C1016A for ; Wed, 21 Aug 2013 20:12:28 +0000 (UTC) Received: (qmail 70939 invoked by uid 500); 21 Aug 2013 20:12:26 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 70542 invoked by uid 500); 21 Aug 2013 20:12:24 -0000 Mailing-List: contact allura-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: allura-dev@incubator.apache.org Delivered-To: mailing list allura-commits@incubator.apache.org Received: (qmail 69455 invoked by uid 99); 21 Aug 2013 20:12:18 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Aug 2013 20:12:18 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5B24C8C1ED1; Wed, 21 Aug 2013 20:12:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: brondsem@apache.org To: allura-commits@incubator.apache.org Date: Wed, 21 Aug 2013 20:12:42 -0000 Message-Id: <86d4a6440eb441ee81c01307cd19550a@git.apache.org> In-Reply-To: <5e9ac297178240c4945d759d2ccda9db@git.apache.org> References: <5e9ac297178240c4945d759d2ccda9db@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [26/50] git commit: [#3154] add & update project json API [#3154] add & update project json API * add screenshots * fix screenshot url encoding on screenshot admin page * add trove categories * add a few individual fields * rename fields to match their usage better * remove download field since it's SourceForge-specific Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/5359716f Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/5359716f Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/5359716f Branch: refs/heads/db/3154b Commit: 5359716fad7c0d730bf2e41cd857b325e90f9ef8 Parents: 794a532 Author: Dave Brondsema Authored: Thu Aug 1 15:35:24 2013 +0000 Committer: Dave Brondsema Committed: Wed Aug 21 18:12:26 2013 +0000 ---------------------------------------------------------------------- Allura/allura/model/auth.py | 2 +- Allura/allura/model/project.py | 52 +++++++++++++++++--- .../templates/widgets/project_screenshots.html | 2 +- Allura/allura/tests/functional/test_rest.py | 11 ++--- 4 files changed, 53 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5359716f/Allura/allura/model/auth.py ---------------------------------------------------------------------- diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py index c8964f3..fb58ce9 100644 --- a/Allura/allura/model/auth.py +++ b/Allura/allura/model/auth.py @@ -702,7 +702,7 @@ class User(MappedClass, ActivityNode, ActivityObject): return dict( username=self.username, name=self.display_name, - url=self.url(), + url=h.absurl(self.url()), ) class OldProjectRole(MappedClass): http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5359716f/Allura/allura/model/project.py ---------------------------------------------------------------------- diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py index 941b360..2258c18 100644 --- a/Allura/allura/model/project.py +++ b/Allura/allura/model/project.py @@ -20,6 +20,7 @@ import logging from collections import Counter, OrderedDict from datetime import datetime from copy import deepcopy +import urllib from tg import config from pylons import tmpl_context as c, app_globals as g @@ -137,6 +138,14 @@ class TroveCategory(MappedClass): crumbs.append((trove.fullname, url)) return crumbs + def __json__(self): + return dict( + id=self.trove_cat_id, + shortname=self.shortname, + fullname=self.fullname, + fullpath=self.fullpath, + ) + class ProjectMapperExtension(MapperExtension): def after_insert(self, obj, st, sess): g.zarkov_event('project_create', project=obj) @@ -250,6 +259,21 @@ class Project(MappedClass, ActivityNode, ActivityObject): def troves_by_type(self, trove_type): return TroveCategory.query.find({'_id':{'$in':getattr(self,'trove_%s' % trove_type)}}).all() + def all_troves(self): + ''' + Returns a dict of human-readable root troves => [categories] + ''' + troves = {} + for attr in dir(self): + if attr.startswith('trove_'): + trove_type = attr.replace('trove_','') + nice_name = dict( + natlanguage='translation', + root_database='database', + ).get(trove_type, trove_type) + troves[nice_name] = self.troves_by_type(trove_type) + return troves + def get_tool_data(self, tool, key, default=None): return self.tool_data.get(tool, {}).get(key, default) @@ -839,17 +863,33 @@ class Project(MappedClass, ActivityNode, ActivityObject): def __json__(self): return dict( - name=self.shortname, - title=self.name, + shortname=self.shortname, + name=self.name, _id=self._id, + url=h.absurl(self.url()), private=self.private, short_description=self.short_description, - description=self.description, - download_page=self.best_download_url(), - preferred_support=self.support_page_url, + summary=self.summary, + external_homepage=self.external_homepage, + socialnetworks=self.socialnetworks, + status=self.removal or 'active', + moved_to_url=self.moved_to_url, + preferred_support_tool=self.support_page, + preferred_support_url=self.support_page_url, developers=self.users_with_role('Developer'), tools=[dict(name=t.tool_name, mount_point=t.options.mount_point, label=t.options.mount_label) - for t in self.app_configs if h.has_access(t, 'read')] + for t in self.app_configs if h.has_access(t, 'read')], + labels=self.labels, + categories=self.all_troves(), + icon_url=h.absurl(self.url() + 'icon') if self.icon else None, + screenshots = [ + dict( + url = h.absurl(self.url() + 'screenshot/' + urllib.quote(ss.filename)), + thumbnail_url = h.absurl(self.url() + 'screenshot/' + urllib.quote(ss.filename) + '/thumb'), + caption = ss.caption, + ) + for ss in self.get_screenshots() + ] ) http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5359716f/Allura/allura/templates/widgets/project_screenshots.html ---------------------------------------------------------------------- diff --git a/Allura/allura/templates/widgets/project_screenshots.html b/Allura/allura/templates/widgets/project_screenshots.html index 01d9849..7d3d338 100644 --- a/Allura/allura/templates/widgets/project_screenshots.html +++ b/Allura/allura/templates/widgets/project_screenshots.html @@ -24,7 +24,7 @@ {% for ss in screenshots %}
- Screenshot thumbnail + Screenshot thumbnail {% if not edit %}
{{ss.caption}} http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5359716f/Allura/allura/tests/functional/test_rest.py ---------------------------------------------------------------------- diff --git a/Allura/allura/tests/functional/test_rest.py b/Allura/allura/tests/functional/test_rest.py index 0278666..0977f26 100644 --- a/Allura/allura/tests/functional/test_rest.py +++ b/Allura/allura/tests/functional/test_rest.py @@ -74,14 +74,13 @@ class TestRestHome(TestRestApiBase): def test_project_data(self): r = self.api_get('/rest/p/test/') - assert_equal(r.json['name'], 'test') - assert_equal(r.json['title'], 'Test Project') - assert_equal(r.json['description'], 'You can edit this description in the admin page') + assert_equal(r.json['shortname'], 'test') + assert_equal(r.json['name'], 'Test Project') assert_equal(len(r.json['developers']), 1) admin_dev = r.json['developers'][0] assert_equal(admin_dev['username'], 'test-admin') assert_equal(admin_dev['name'], 'Test Admin') - assert_equal(admin_dev['url'], '/u/test-admin/') + assert_equal(admin_dev['url'], 'http://localhost:80/u/test-admin/') @td.with_tool('test', 'Tickets', 'bugs') @td.with_tool('test', 'Tickets', 'private-bugs') @@ -95,14 +94,14 @@ class TestRestHome(TestRestApiBase): # admin sees both 'Tickets' tools r = self.api_get('/rest/p/test/') - assert_equal(r.json['name'], 'test') + assert_equal(r.json['shortname'], 'test') tool_mounts = [t['mount_point'] for t in r.json['tools']] assert_in('bugs', tool_mounts) assert_in('private-bugs', tool_mounts) # anonymous sees only non-private tool r = self.app.get('/rest/p/test/', extra_environ={'username': '*anonymous'}) - assert_equal(r.json['name'], 'test') + assert_equal(r.json['shortname'], 'test') tool_mounts = [t['mount_point'] for t in r.json['tools']] assert_in('bugs', tool_mounts) assert_not_in('private-bugs', tool_mounts)