From 78b4fae9782b366cbf6496f4238f22e9a3436bc1 Mon Sep 17 00:00:00 2001
From: "J.-S. Caux" <J.S.Caux@uva.nl>
Date: Mon, 22 Jan 2018 16:48:02 +0100
Subject: [PATCH] Add cite-as info on citable Reports and Comments

---
 comments/models.py                              | 17 +++++++++++++++++
 .../templates/comments/_comment_identifier.html |  2 +-
 submissions/models.py                           | 13 +++++++++++++
 .../_single_public_report_without_comments.html |  4 ++--
 submissions/templatetags/submissions_extras.py  |  5 +++++
 5 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/comments/models.py b/comments/models.py
index 9f52ca8d0..6a36fa055 100644
--- a/comments/models.py
+++ b/comments/models.py
@@ -233,3 +233,20 @@ class Comment(TimeStampedModel):
                 return relation
 
         return None
+
+
+    @property
+    def citation(self):
+        if self.doi_string:
+            citation = ''
+            if self.anonymous:
+                citation += 'Anonymous, '
+            else:
+                citation += '%s %s, ' % (self.author.user.first_name, self.author.user.last_name)
+            if self.is_authorreply:
+                citation += 'SciPost Author Replies '
+            else:
+                citation += 'SciPost Comments '
+            citation += '(%s), doi:' % self.date_submitted.strftime('%Y')
+            citation += self.doi_string
+        return None
diff --git a/comments/templates/comments/_comment_identifier.html b/comments/templates/comments/_comment_identifier.html
index 2d518eced..5eb681610 100644
--- a/comments/templates/comments/_comment_identifier.html
+++ b/comments/templates/comments/_comment_identifier.html
@@ -17,7 +17,7 @@
             <a href="{{comment.author.get_absolute_url}}">{{comment.author.user.first_name}} {{comment.author.user.last_name}}</a>
             on {{comment.date_submitted|date:'Y-m-d'}}
         {% endif %}
-	{% if comment.doi_string %}&nbsp; <small>doi:  {{ comment.doi_string }}</small>{% endif %}
+	{% if comment.doi_string %}&nbsp; <small>{{ comment|citation }}</small>{% endif %}
     </h3>
 
 
diff --git a/submissions/models.py b/submissions/models.py
index 14408d47c..88d66aace 100644
--- a/submissions/models.py
+++ b/submissions/models.py
@@ -523,6 +523,19 @@ class Report(SubmissionRelatedObjectMixin, models.Model):
 
         return None
 
+    @property
+    def citation(self):
+        if self.doi_string:
+            citation = ''
+            if self.anonymous:
+                citation += 'Anonymous, '
+            else:
+                citation += '%s %s, ' % (self.author.user.first_name, self.author.user.last_name)
+            citation += 'Report on %s, ' % self.submission.arxiv_identifier_w_vn_nr
+            citation += 'SciPost Reports (%s), doi:' % self.date_submitted.strftime('%Y')
+            citation += self.doi_string
+        return None
+
 
 ##########################
 # EditorialCommunication #
diff --git a/submissions/templates/submissions/_single_public_report_without_comments.html b/submissions/templates/submissions/_single_public_report_without_comments.html
index 5f0a3cf45..0e438c4ca 100644
--- a/submissions/templates/submissions/_single_public_report_without_comments.html
+++ b/submissions/templates/submissions/_single_public_report_without_comments.html
@@ -11,7 +11,7 @@
                       on {{ report.date_submitted|date:'Y-n-j' }}
                     </h3>
             	    <ul class="publicationClickables">
-            	      {% if report.doi_string %}<li>doi:  {{ report.doi_string }}</li>{% endif %}
+            	      {% if report.doi_string %}<li>{{ report|citation }}</li>{% endif %}
                               {% if report.pdf_report %}
                               <li><a href="{% url 'submissions:report_detail_pdf' report.submission.arxiv_identifier_w_vn_nr report.report_nr %}" target="_blank">Download as PDF</a></li>
                             {% endif %}
@@ -53,7 +53,7 @@
                         on {{ report.date_submitted|date:'Y-n-j' }}</h3>
                     </h3>
         		    <ul class="publicationClickables">
-        		      {% if report.doi_string %}<li>doi:  {{ report.doi_string }}</li>{% endif %}
+        		      {% if report.doi_string %}<li>{{ report|citation }}</li>{% endif %}
                               {% if report.pdf_report %}
                               <li><a href="{% url 'submissions:report_detail_pdf' report.submission.arxiv_identifier_w_vn_nr report.report_nr %}" target="_blank">Download as PDF</a></li>
                               {% endif %}
diff --git a/submissions/templatetags/submissions_extras.py b/submissions/templatetags/submissions_extras.py
index 97943119c..f7e9990c2 100644
--- a/submissions/templatetags/submissions_extras.py
+++ b/submissions/templatetags/submissions_extras.py
@@ -30,3 +30,8 @@ def user_is_referee(submission, user):
 @register.filter
 def is_voting_fellow(submission, user):
     return submission.voting_fellows.filter(contributor__user=user).exists()
+
+
+@register.filter
+def citation(citable):
+    return citable.citation
-- 
GitLab