From 724067aa893068f7f15378c310c8a03d338c1a89 Mon Sep 17 00:00:00 2001
From: Ole Laursen <olau@iola.dk>
Date: Thu, 16 Feb 2012 16:31:01 +0000
Subject: [PATCH] Sort documents on agenda on when an IESG process was started
 on them  - Legacy-Id: 3930

---
 ietf/iesg/views.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/ietf/iesg/views.py b/ietf/iesg/views.py
index b82a8a885..5133bf817 100644
--- a/ietf/iesg/views.py
+++ b/ietf/iesg/views.py
@@ -223,14 +223,17 @@ def agenda_docs(date, next_agenda):
         for m in matches:
             if m.latest_event(TelechatDocEvent, type="scheduled_for_telechat").telechat_date != date:
                 continue
-            
+
+            e = m.latest_event(type="started_iesg_process")
+            m.balloting_started = e.time if e else datetime.datetime.min
+
             if m.docalias_set.filter(name__startswith="rfc"):
                 rfcmatches.append(m)
             else:
                 idmatches.append(m)
 
-        idmatches.sort(key=lambda d: d.start_date or datetime.date.min)
-        rfcmatches.sort(key=lambda d: d.start_date or datetime.date.min)
+        idmatches.sort(key=lambda d: d.balloting_started)
+        rfcmatches.sort(key=lambda d: d.balloting_started)
     else:
         if next_agenda:
             matches = IDInternal.objects.filter(telechat_date=date, primary_flag=1, agenda=1)