From 7106e95b4579ce1a6456f6a2c181d35211bb9ec8 Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Thu, 10 Oct 2024 11:16:23 +0200
Subject: [PATCH] add persistent referee numbering to reports

fixes #26
---
 scipost_django/submissions/models/report.py          | 12 ++++++++++++
 .../submissions/_report_public_without_comments.html |  8 ++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/scipost_django/submissions/models/report.py b/scipost_django/submissions/models/report.py
index 11645e064..9760a4ef5 100644
--- a/scipost_django/submissions/models/report.py
+++ b/scipost_django/submissions/models/report.py
@@ -320,6 +320,18 @@ class Report(SubmissionRelatedObjectMixin, models.Model):
             citation += "doi: %s" % self.doi_string
         return citation
 
+    @cached_property
+    def referee_nr_in_thread(self):
+        """Return the number of the referee in the thread."""
+        ordered_reports = list(
+            Report.objects.filter(
+                submission__thread_hash=self.submission.thread_hash,
+            )
+            .order_by("date_submitted")
+            .values_list("author__id", flat=True)
+        )
+        return ordered_reports.index(self.author.id) + 1
+
     def create_doi_label(self):
         """Create a doi in the default format."""
         Report.objects.filter(id=self.id).update(
diff --git a/scipost_django/submissions/templates/submissions/_report_public_without_comments.html b/scipost_django/submissions/templates/submissions/_report_public_without_comments.html
index afe95a004..7596350f0 100644
--- a/scipost_django/submissions/templates/submissions/_report_public_without_comments.html
+++ b/scipost_django/submissions/templates/submissions/_report_public_without_comments.html
@@ -6,13 +6,13 @@
     <div class="col-12">
       <div class="reportid">
         <h3>
+          Report #{{ report.report_nr }} by 
           {% if report.anonymous %}
-            Anonymous Report {{ report.report_nr }}
+            Anonymous 
           {% else %}
-            Report {{ report.report_nr }} by <a href="{{ report.author.get_absolute_url }}">{{ report.author.user.first_name }} {{ report.author.user.last_name }}</a>
+            <a href="{{ report.author.get_absolute_url }}">{{ report.author.user.first_name }} {{ report.author.user.last_name }}</a>
           {% endif %}
-
-          on {{ report.date_submitted|date:'Y-n-j' }}
+          (Referee {{ report.referee_nr_in_thread }}) on {{ report.date_submitted|date:'Y-n-j' }}
           {% if report.report_type == 'report_post_edrec' %}
             <small><label class="label label-outline-primary ms-2">Post-Editorial Recommendation Report</label> <span class="text-primary" data-bs-toggle="tooltip" data-bs-placement="auto" data-bs-html="true" title="Post-Editorial Reports are submitted after the Editorial Recommendation has been formulated." aria-hidden="true">{% include 'bi/question-circle-fill.html' %}</span></small>
           {% endif %}
-- 
GitLab