From 84f9d08952d64e55f57b95165f40fc94226d7d2e Mon Sep 17 00:00:00 2001
From: Jacob Champion <jchampion@timescale.com>
Date: Wed, 27 Jul 2022 08:33:42 -0700
Subject: [PATCH 2/2] Add a "Deferred" patch section

Now that there are more clearly two tiers of "closed" patches -- those
that are more-or-less permananently finished, and those that may be
picked up and continued in the future -- split the latter group into a
new Deferred section in the UI.

This includes the newly added "Returned: Needs more interest", as well
as "Returned with Feedback" and "Moved to next CF".

This is a UI-only change and does not require any migrations.
---
 pgcommitfest/commitfest/models.py                    | 1 +
 pgcommitfest/commitfest/templates/commitfest.html    | 4 ++--
 pgcommitfest/commitfest/templates/patch_commands.inc | 8 +++++---
 pgcommitfest/commitfest/views.py                     | 4 +++-
 4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py
index 433eb4a..23fa1bd 100644
--- a/pgcommitfest/commitfest/models.py
+++ b/pgcommitfest/commitfest/models.py
@@ -199,6 +199,7 @@ class PatchOnCommitFest(models.Model):
         (STATUS_RETURNED_INTEREST, 'danger'),
     )
     OPEN_STATUSES = [STATUS_REVIEW, STATUS_AUTHOR, STATUS_COMMITTER]
+    DEFERRED_STATUSES = [STATUS_NEXT, STATUS_RETURNED, STATUS_RETURNED_INTEREST]
 
     @classmethod
     def OPEN_STATUS_CHOICES(cls):
diff --git a/pgcommitfest/commitfest/templates/commitfest.html b/pgcommitfest/commitfest/templates/commitfest.html
index 63f793a..19ef97f 100644
--- a/pgcommitfest/commitfest/templates/commitfest.html
+++ b/pgcommitfest/commitfest/templates/commitfest.html
@@ -51,12 +51,12 @@
 </p>
 
 {%for p in patches %}
-{%ifchanged p.is_open%}
+{%ifchanged p.is_open p.is_deferred%}
 {%if not forloop.first%}
  </tbody>
 </table>
 {%endif%}
-<h3>{{p.is_open|yesno:"Active patches,Closed patches"}}</h3>
+<h3>{%if p.is_open%}Active{%elif p.is_deferred%}Deferred{%else%}Closed{%endif%} patches</h3>
 <table class="table table-striped table-bordered table-hover table-condensed">
  <thead>
   <tr>
diff --git a/pgcommitfest/commitfest/templates/patch_commands.inc b/pgcommitfest/commitfest/templates/patch_commands.inc
index 63e4c1f..9a9eea3 100644
--- a/pgcommitfest/commitfest/templates/patch_commands.inc
+++ b/pgcommitfest/commitfest/templates/patch_commands.inc
@@ -17,12 +17,14 @@
   <li role="presentation"><a href="status/author/">Waiting on Author</a></li>
   <li role="presentation"><a href="status/committer/">Ready for Committer</a></li>
   <li role="presentation" class="divider"></li>
-  <li role="presentation" class="dropdown-header">Closed statuses</li>
-  <li role="presentation"><a href="close/reject/" onclick="return verify_reject()">Rejected</a></li>
-  <li role="presentation"><a href="close/withdrawn/" onclick="return verify_withdrawn()">Withdrawn</a></li>
+  <li role="presentation" class="dropdown-header">Deferred statuses</li>
   <li role="presentation"><a href="close/feedback/" onclick="return verify_returned()">Returned (with feedback)</a></li>
   <li role="presentation"><a href="close/interest/" onclick="return verify_returned_interest()">Returned (needs more interest)</a></li>
   <li role="presentation"><a href="close/next/" onclick="return verify_next()">Move to next CF</a></li>
+  <li role="presentation" class="divider"></li>
+  <li role="presentation" class="dropdown-header">Closed statuses</li>
+  <li role="presentation"><a href="close/reject/" onclick="return verify_reject()">Rejected</a></li>
+  <li role="presentation"><a href="close/withdrawn/" onclick="return verify_withdrawn()">Withdrawn</a></li>
   <li role="presentation"><a href="close/committed/" onclick="return flagCommitted({%if patch.committer%}'{{patch.committer}}'{%elif is_committer%}'{{user.username}}'{%else%}null{%endif%})">Committed</a></li>
  </ul>
 </div>
diff --git a/pgcommitfest/commitfest/views.py b/pgcommitfest/commitfest/views.py
index 1915aad..a3a0566 100644
--- a/pgcommitfest/commitfest/views.py
+++ b/pgcommitfest/commitfest/views.py
@@ -192,6 +192,7 @@ def commitfest(request, cfid):
     params = {
         'cid': cf.id,
         'openstatuses': PatchOnCommitFest.OPEN_STATUSES,
+        'deferredstatuses': PatchOnCommitFest.DEFERRED_STATUSES,
     }
     params.update(whereparams)
 
@@ -199,6 +200,7 @@ def commitfest(request, cfid):
     curs = connection.cursor()
     curs.execute("""SELECT p.id, p.name, poc.status, v.version AS targetversion, p.created, p.modified, p.lastmail, committer.username AS committer, t.topic,
 (poc.status=ANY(%(openstatuses)s)) AS is_open,
+(poc.status=ANY(%(deferredstatuses)s)) AS is_deferred,
 (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
@@ -209,7 +211,7 @@ LEFT JOIN auth_user committer ON committer.id=p.committer_id
 LEFT JOIN commitfest_targetversion v ON p.targetversion_id=v.id
 WHERE poc.commitfest_id=%(cid)s {0}
 GROUP BY p.id, poc.id, committer.id, t.id, v.version
-ORDER BY is_open DESC, {1}""".format(where_str, orderby_str), params)
+ORDER BY is_open DESC, is_deferred DESC, {1}""".format(where_str, orderby_str), params)
     patches = [dict(zip([col[0] for col in curs.description], row)) for row in curs.fetchall()]
 
     # Generate patch status summary.
-- 
2.25.1

