Merge lp:~sinzui/charmworld/modern-py into lp:~juju-jitsu/charmworld/trunk

Proposed by Curtis Hovey
Status: Merged
Merged at revision: 352
Proposed branch: lp:~sinzui/charmworld/modern-py
Merge into: lp:~juju-jitsu/charmworld/trunk
Diff against target: 41 lines (+9/-12)
1 file modified
charmworld/views/misc.py (+9/-12)
To merge this branch: bzr merge lp:~sinzui/charmworld/modern-py
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+180562@code.launchpad.net

Commit message

Modernise chartmers() and document what it really does.

Description of the change

Modernise chartmers() and document what it really does.

While adding API3, I stumbled reading the charmer() method. The code is written like py2.3. I uses the deprecated cmp() builtin, and it does work that defaultdict and soted do. I did not understand why the first element was popped. I then read the comment and knew it was a lie. charmworld does not know all the committers to charms. The listing is really about how many charms people own, except for the charmers team which is assumed to own most charms.

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) wrote :

This is shorter and clearer, so I like it. I don't know if there's value in py3 compatibility per se. If it were somewhere other than report code, I'd ask about tests.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmworld/views/misc.py'
2--- charmworld/views/misc.py 2013-08-15 20:28:10 +0000
3+++ charmworld/views/misc.py 2013-08-16 13:42:08 +0000
4@@ -1,6 +1,8 @@
5 # Copyright 2012, 2013 Canonical Ltd. This software is licensed under the
6 # GNU Affero General Public License version 3 (see the file LICENSE).
7
8+from collections import defaultdict
9+
10 from pyramid.view import view_config
11
12 from charmworld import cached_view_config
13@@ -24,22 +26,17 @@
14 route_name="charmers",
15 renderer="charmworld:templates/charmers.pt")
16 def charmers(request):
17- # We want to collect which users have worked on which charms.
18- # By worked on means they have at least one commit to it.
19- # collect a list of users grouped by charm name.
20- # The list of users does not correspond to the lp ids.
21+ # We want to collect which users have contributes on which charms.
22+ # This however reports charm owners ordered decending by ownership.
23+ # The largest owner is not included because we think this is ~charmers.
24 results = request.db.charms.find(
25 {}, {"name": 1, 'owner': 1, 'short_url': 1})
26
27- owner_map = {}
28+ owner_map = defaultdict(int)
29 for i in results:
30- if not i['owner'] in owner_map:
31- owner_map[i['owner']] = 1
32- else:
33- owner_map[i['owner']] += 1
34-
35- owners = owner_map.items()
36- owners.sort(lambda x, y: cmp(y[1], x[1]))
37+ owner_map[i['owner']] += 1
38+ owners = sorted(
39+ owner_map.items(), key=lambda i: (i[1], i[0]), reverse=True)
40 owners.pop(0)
41 return {"owners": owners}
42

Subscribers

People subscribed via source and target branches