From e065bbb4586e94249a502154db5bf86ca0cae325 Mon Sep 17 00:00:00 2001
From: Jorran de Wit <jorrandewit@outlook.com>
Date: Sat, 29 Jul 2017 09:11:28 +0200
Subject: [PATCH] Improve personal (comment) page

---
 comments/managers.py                             |  6 ++++++
 comments/models.py                               |  3 ++-
 .../comments/_comment_card_content.html          |  4 +---
 .../_comment_card_extended_for_author.html       | 16 ++++++++++++++++
 scipost/templates/scipost/personal_page.html     | 12 ++++++++----
 5 files changed, 33 insertions(+), 8 deletions(-)
 create mode 100644 comments/templates/comments/_comment_card_extended_for_author.html

diff --git a/comments/managers.py b/comments/managers.py
index 37f5baef8..70e6f2069 100644
--- a/comments/managers.py
+++ b/comments/managers.py
@@ -9,3 +9,9 @@ class CommentQuerySet(models.QuerySet):
 
     def awaiting_vetting(self):
         return self.filter(status=STATUS_PENDING)
+
+    def regular_comments(self):
+        return self.filter(is_author_reply=False)
+
+    def author_replies(self):
+        return self.filter(is_author_reply=True)
diff --git a/comments/models.py b/comments/models.py
index 5a2a4a644..82ae4cf7b 100644
--- a/comments/models.py
+++ b/comments/models.py
@@ -57,7 +57,8 @@ class Comment(TimeStampedModel):
 
     # Author info
     is_author_reply = models.BooleanField(default=False)
-    author = models.ForeignKey('scipost.Contributor', on_delete=models.CASCADE)
+    author = models.ForeignKey('scipost.Contributor', on_delete=models.CASCADE,
+                               related_name='comments')
     anonymous = models.BooleanField(default=False, verbose_name='Publish anonymously')
 
     # Categories:
diff --git a/comments/templates/comments/_comment_card_content.html b/comments/templates/comments/_comment_card_content.html
index 6a96446b4..c6788a79a 100644
--- a/comments/templates/comments/_comment_card_content.html
+++ b/comments/templates/comments/_comment_card_content.html
@@ -1,9 +1,7 @@
 <div class="card-block card-comment">
     {% block card_block_header %}{% endblock %}
     <p class="card-text">
-        <span class="text-blue">
-            <a href="{{comment.author.get_absolute_url}}">{{comment.author.user.first_name}} {{comment.author.user.last_name}}</a>:
-        </span>
+        <a href="{{comment.author.get_absolute_url}}">{{comment.author.user.first_name}} {{comment.author.user.last_name}}</a>:
 
         <a href="{{comment.get_absolute_url}">
             "{{comment.comment_text|slice:'30'}}{% if comment.comment_text|length > 30 %}...{% endif %}"
diff --git a/comments/templates/comments/_comment_card_extended_for_author.html b/comments/templates/comments/_comment_card_extended_for_author.html
new file mode 100644
index 000000000..aaac79e90
--- /dev/null
+++ b/comments/templates/comments/_comment_card_extended_for_author.html
@@ -0,0 +1,16 @@
+<div class="card-block card-comment">
+    <div class="mb-4 mt-2">
+        <div class="d-inline-block mr-1">Nr {{comment.id}}</div>
+        {% include 'comments/_comment_voting_summary.html' with comment=comment class='small' %}
+    </div>
+
+    <p>"{{comment.comment_text|linebreaksbr}}"</p>
+    <p class="card-text">by <a href="{{comment.author.get_absolute_url}}">{{comment.author.user.first_name}} {{comment.author.user.last_name}}</a> in {{comment.content_type|capfirst}} on <a href="{{comment.content_object.get_absolute_url}}" class="pubtitleli">{{comment.title}}</a> {% if comment.content_object.author_list %} <span class="text-muted">by {{comment.content_object.author_list}}</span>{% endif %}</p>
+
+    {% comment %}
+        Using 'by xxx' on non-submission comments here would be ambigious. Does the `by xxx` apply to the
+        other object (eg. Report), or the Submission, the Comment, etc?
+    {% endcomment %}
+    <p class="card-text text-muted">Comment submitted {{comment.date_submitted}}</p>
+    <p class="card-text">Status: <span class="{% if comment.status == 1 %} text-success{% elif comment.status == 0 %} text-danger{% endif %}">{{comment.get_status_display}}</span></p>
+</div>
diff --git a/scipost/templates/scipost/personal_page.html b/scipost/templates/scipost/personal_page.html
index ea97280d1..c5534d313 100644
--- a/scipost/templates/scipost/personal_page.html
+++ b/scipost/templates/scipost/personal_page.html
@@ -58,10 +58,14 @@
                         <a class="nav-link" data-toggle="tab" href="#theses">Theses</a>
                       </li>
                       <li class="nav-item btn btn-secondary">
-                        <a class="nav-link" data-toggle="tab" href="#comments">Comments</a>
+                          {% with request.user.contributor.comments.regular_comments.awaiting_vetting.count as count %}
+                            <a class="nav-link" data-toggle="tab" href="#comments">Comments{% if count %} ({{count}} unvetted){% endif %}</a>
+                          {% endwith %}
                       </li>
                       <li class="nav-item btn btn-secondary">
-                        <a class="nav-link" data-toggle="tab" href="#author-replies">Author Replies</a>
+                          {% with request.user.contributor.comments.author_replies.awaiting_vetting.count as count %}
+                            <a class="nav-link" data-toggle="tab" href="#author-replies">Author Replies{% if count %} ({{count}} unvetted){% endif %}</a>
+                          {% endwith %}
                       </li>
                     </ul>
                 </div>
@@ -580,7 +584,7 @@
                     <ul class="list-group list-group-flush">
                         {% for own_comment in own_comments %}
                             <li class="list-group-item">
-                                {% include 'comments/_comment_card_extended_content.html' with comment=own_comment %}
+                                {% include 'comments/_comment_card_extended_for_author.html' with comment=own_comment %}
                             </li>
                         {% empty %}
                             <li class="list-group-item"><em>You have not commented yet.</em></li>
@@ -607,7 +611,7 @@
                     <ul class="list-group list-group-flush">
                       {% for own_reply in own_authorreplies %}
                           <li class="list-group-item">
-                              {% include 'comments/_comment_card_extended_content.html' with comment=own_reply %}
+                              {% include 'comments/_comment_card_extended_for_author.html' with comment=own_reply %}
                           </li>
                       {% empty %}
                           <li class="list-group-item"><em>You do not have Author Replies yet.</em></li>
-- 
GitLab