From 93a080de64b897b989d8a81babaaaeacaab5195f Mon Sep 17 00:00:00 2001
From: Jorran de Wit <jorrandewit@outlook.com>
Date: Mon, 24 Jul 2017 17:31:56 +0200
Subject: [PATCH] Reduce lines of code editorial-page view

---
 .../templates/submissions/editorial_page.html | 22 ++++++++++---------
 submissions/views.py                          | 17 +-------------
 2 files changed, 13 insertions(+), 26 deletions(-)

diff --git a/submissions/templates/submissions/editorial_page.html b/submissions/templates/submissions/editorial_page.html
index c2a20c722..6debf2f9e 100644
--- a/submissions/templates/submissions/editorial_page.html
+++ b/submissions/templates/submissions/editorial_page.html
@@ -71,15 +71,17 @@
     </div>
 </div>
 
-{% if recommendation %}
-    <div class="row">
-        <div class="col-12">
-            <div class="card card-outline-secondary">
-                {% include 'submissions/_recommendation_author_content.html' with recommendation=recommendation %}
+{% with recommendation as submission.eicrecommendations.first %}
+    {% if recommendation %}
+        <div class="row">
+            <div class="col-12">
+                <div class="card card-outline-secondary">
+                    {% include 'submissions/_recommendation_author_content.html' with recommendation=recommendation %}
+                </div>
             </div>
         </div>
-    </div>
-{% endif %}
+    {% endif %}
+{% endwith %}
 
 <div class="row">
     <div class="col-12">
@@ -123,7 +125,7 @@
         <div class="row">
             <div class="col-12">
                 <h3 class="mb-2">Detail of refereeing invitations:</h3>
-                {% include 'submissions/_submission_refereeing_invitations.html' with submission=submission invitations=ref_invitations %}
+                {% include 'submissions/_submission_refereeing_invitations.html' with submission=submission invitations=submission.referee_invitations.all %}
             </div>
         </div>
     {% endif %}
@@ -173,7 +175,7 @@
                                 </div>
                             </form>
                         </li>
-                        <li><a href="{% url 'submissions:vet_submitted_reports' %}">Vet submitted Reports</a> ({{ nr_reports_to_vet }})</li>
+                        <li><a href="{% url 'submissions:vet_submitted_reports' %}">Vet submitted Reports</a> ({{ submission.reports.awaiting_vetting.count }})</li>
                         {% if not submission.reporting_deadline_has_passed %}
                             <li><a href="{% url 'submissions:close_refereeing_round' arxiv_identifier_w_vn_nr=submission.arxiv_identifier_w_vn_nr %}">Close the refereeing round</a> &nbsp;(deactivates submission of new Reports and Comments)</li>
                         {% endif %}
@@ -201,7 +203,7 @@
 <div class="row">
     <div class="col-12">
         <ul class="list-group list-group-flush">
-            {% for comm in communications %}
+            {% for comm in submission.editorial_communications.all %}
                 <li class="list-group-item">
                     {% include 'submissions/_editorial_communication_content.html' with communication=comm %}
                 </li>
diff --git a/submissions/views.py b/submissions/views.py
index 67d59bfba..1036455a0 100644
--- a/submissions/views.py
+++ b/submissions/views.py
@@ -529,27 +529,12 @@ def editorial_page(request, arxiv_identifier_w_vn_nr):
     other_versions = (Submission.objects
                       .filter(arxiv_identifier_wo_vn_nr=submission.arxiv_identifier_wo_vn_nr)
                       .exclude(pk=submission.id))
-    ref_invitations = RefereeInvitation.objects.filter(submission=submission)
-    nr_reports_to_vet = (Report.objects.awaiting_vetting()
-                         .filter(submission=submission,
-                                 submission__editor_in_charge=request.user.contributor)
-                         .count())
-    communications = (EditorialCommunication.objects
-                      .filter(submission=submission).order_by('timestamp'))
-    try:
-        recommendation = (EICRecommendation.objects.get_for_user_in_pool(request.user)
-                          .get(submission=submission))
-    except EICRecommendation.DoesNotExist:
-        recommendation = None
+
     context = {
         'submission': submission,
         'other_versions': other_versions,
-        'recommendation': recommendation,
         'set_deadline_form': SetRefereeingDeadlineForm(),
         'cycle_choice_form': SubmissionCycleChoiceForm(instance=submission),
-        'ref_invitations': ref_invitations,
-        'nr_reports_to_vet': nr_reports_to_vet,
-        'communications': communications
     }
     return render(request, 'submissions/editorial_page.html', context)
 
-- 
GitLab