From a5540cb900bccae3f6659609f53ccd8bb6aec7f9 Mon Sep 17 00:00:00 2001
From: Thomas Kluyver <thomas@kluyver.me.uk>
Date: Mon, 20 Jul 2020 13:39:45 +0100
Subject: [PATCH] Sort 'precorrection' notebook before main correction
 notebooks in report

---
 xfel_calibrate/finalize.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/xfel_calibrate/finalize.py b/xfel_calibrate/finalize.py
index 695eb293b..c6c90f2c3 100644
--- a/xfel_calibrate/finalize.py
+++ b/xfel_calibrate/finalize.py
@@ -272,6 +272,16 @@ def make_report(run_path, tmp_path, out_path, project, author, version,
         if "summary" in f.lower() and f not in lead_rstfiles:
             direntries.insert(len(lead_rstfiles),
                               direntries.pop(direntries.index(f)))
+
+        # Move 'precorrection' notebook to the top if it exists
+        # TODO: find a better way to order the report content
+        elif "precorrection" in f.lower():
+            # There's currently only 1 case with 'precorrection', and that
+            # also has a summary notebook, so we can hardcode N+1 until we
+            # rework this.
+            direntries.insert(len(lead_rstfiles) + 1,
+                              direntries.pop(direntries.index(f)))
+
     files_to_handle = []
     for entry in direntries:
         if isfile("{}/{}".format(run_path, entry)):
-- 
GitLab