has_filter = len(whereclauses) > 0
# Figure out custom ordering
- ordering = ['-is_open', 'topic__topic', 'created',]
if request.GET.has_key('sortkey') and request.GET['sortkey']!='':
try:
sortkey=int(request.GET['sortkey'])
orderby_str = 'p.id'
sortkey=0
else:
- orderby_str = 'p.id'
+ orderby_str = 'topic, created'
sortkey = 0
if not has_filter and sortkey==0 and request.GET:
# Let's not overload the poor django ORM
curs = connection.cursor()
- curs.execute("""SELECT p.id, p.name, poc.status, p.created, p.modified, p.lastmail, committer.username AS committer,
+ curs.execute("""SELECT p.id, p.name, poc.status, p.created, p.modified, p.lastmail, committer.username AS committer, t.topic,
(poc.status=ANY(%(openstatuses)s)) AS is_open,
(SELECT string_agg(first_name || ' ' || last_name || ' (' || username || ')', ', ') FROM auth_user INNER JOIN commitfest_patch_authors cpa ON cpa.user_id=auth_user.id WHERE cpa.patch_id=p.id) AS author_names,
(SELECT string_agg(first_name || ' ' || last_name || ' (' || username || ')', ', ') FROM auth_user INNER JOIN commitfest_patch_reviewers cpr ON cpr.user_id=auth_user.id WHERE cpr.patch_id=p.id) AS reviewer_names,
(SELECT count(1) FROM commitfest_patchoncommitfest pcf WHERE pcf.patch_id=p.id) AS num_cfs
FROM commitfest_patch p
INNER JOIN commitfest_patchoncommitfest poc ON poc.patch_id=p.id
+INNER JOIN commitfest_topic t ON t.id=p.topic_id
LEFT JOIN auth_user committer ON committer.id=p.committer_id
WHERE poc.commitfest_id=%(cid)s {0}
-GROUP BY p.id, poc.id, committer.id
+GROUP BY p.id, poc.id, committer.id, t.id
ORDER BY is_open DESC, {1}""".format(where_str, orderby_str), params)
patches = [dict(zip([col[0] for col in curs.description], row)) for row in curs.fetchall()]