From 379d455a324d81ad5ba689821a8b0f8396f63770 Mon Sep 17 00:00:00 2001
From: Erin Mullaney <erin.mullaney@torchbox.com>
Date: Wed, 16 Jan 2019 12:25:41 -0500
Subject: [PATCH] 808 round block data on submissions WIP

---
 opentech/apply/funds/models/applications.py   |  5 ++
 .../templates/funds/includes/round-block.html | 59 ++++++++-----------
 .../funds/templates/funds/submissions.html    |  3 +-
 opentech/apply/funds/views.py                 | 15 ++++-
 4 files changed, 45 insertions(+), 37 deletions(-)

diff --git a/opentech/apply/funds/models/applications.py b/opentech/apply/funds/models/applications.py
index 0119e8c65..759009d7d 100644
--- a/opentech/apply/funds/models/applications.py
+++ b/opentech/apply/funds/models/applications.py
@@ -104,6 +104,11 @@ class RoundBaseManager(PageQuerySet):
         )
         return rounds
 
+    def closed(self):
+        rounds = self.live().public().specific()
+        rounds = rounds.filter(end_date__lt=date.today())
+        return rounds
+
 
 class RoundBase(WorkflowStreamForm, SubmittableStreamForm):  # type: ignore
     is_creatable = False
diff --git a/opentech/apply/funds/templates/funds/includes/round-block.html b/opentech/apply/funds/templates/funds/includes/round-block.html
index 2e5993027..e77155771 100644
--- a/opentech/apply/funds/templates/funds/includes/round-block.html
+++ b/opentech/apply/funds/templates/funds/includes/round-block.html
@@ -8,58 +8,49 @@
     </section>
 
     {# Closed rounds/labs tab #}
-    <div class="tabs__content" id="tab-1">
+    <div class="tabs__content-nm" id="tab-1">
         <ul class="round-block">
-            <li class="round-block__item">
-                <h4 class="round-block__title">IFFund-2018-01</h4>
-                <p>Internet Freedom Fund</p>
-                <p class="round-block__date">Closed 2018-01-01</p>
-                <p class="round-block__determination">33% Determined</p>
-                <a class="round-block__view" href="#">View</a>
-            </li>
+            {% for round in closed_rounds %}
+                <li class="round-block__item">
+                    <h4 class="round-block__title">{{ round }}</h4>
+                    <p> {{ round.fund }} </p>
+                    <p class="round-block__date">Closed {{ round.end_date|date:"Y-m-d" }}</p>
+                    <p class="round-block__determination">TODO: 33% Determined</p>
+                    <a class="round-block__view" href="#">View</a>
+                </li>
+            {% endfor %}
 
-            <li class="round-block__item">
-                <h4 class="round-block__title">IFFund-2018-01</h4>
-                <p>Rapid Response Fund</p>
-                <p class="round-block__date">Closed 2018-01-01</p>
-                <p class="round-block__determination">50% Determined</p>
-                <a class="round-block__view" href="#">View</a>
-            </li>
-            {% if 10 >= 10 %}
+            {% if closed_round_count > 10 %}
                 {# If count of rounds/labs >= 10 #}
                 <li class="round-block__item round-block__item--more">
                     {# href required #}
-                    <a href="#">Show more</a>
+                    <a href="#">Show all</a>
                 </li>
             {% endif %}
         </ul>
     </div>
 
     {# Open rounds/labs tab #}
-    <div class="tabs__content" id="tab-2">
+    <div class="tabs__content-nm" id="tab-2">
         <ul class="round-block">
-            <li class="round-block__item">
-                <h4 class="round-block__title">IFFund-2018-01</h4>
-                <p>Internet Freedom Fund (archive fund)</p>
-                <p class="round-block__date">Open until 2020-01-01</p>
-                <p class="round-block__determination">25% Determined</p>
-                <a class="round-block__view" href="#">View</a>
-            </li>
+            {% for round in open_rounds %}
+                <li class="round-block__item">
+                    <h4 class="round-block__title">{{ round }}</h4>
+                    <p> {{ round.fund }} </p>
+                    <p class="round-block__date">Open until {{ round.end_date|date:"Y-m-d" }}</p>
+                    <p class="round-block__determination">TODO: 33% Determined</p>
+                    <a class="round-block__view" href="#">View</a>
+                </li>
+            {% endfor %}
 
-            <li class="round-block__item">
-                <h4 class="round-block__title">IFFund-2018-01</h4>
-                <p>Communit Lab</p>
-                <p class="round-block__date">Open</p>
-                <p class="round-block__determination">33% Determined</p>
-                <a class="round-block__view" href="#">View</a>
-            </li>
-            {% if 10 >= 10 %}
+            {% if open_round_count > 10 %}
                 {# If count of rounds/labs >= 10 #}
                 <li class="round-block__item round-block__item--more">
                     {# href required #}
-                    <a href="#">Show more</a>
+                    <a href="#">Show all</a>
                 </li>
             {% endif %}
         </ul>
     </div>
+
 </div>
diff --git a/opentech/apply/funds/templates/funds/submissions.html b/opentech/apply/funds/templates/funds/submissions.html
index c50576eb1..5589b26b2 100644
--- a/opentech/apply/funds/templates/funds/submissions.html
+++ b/opentech/apply/funds/templates/funds/submissions.html
@@ -15,7 +15,8 @@
 </div>
 
 <div class="wrapper wrapper--large wrapper--inner-space-medium">
-    {% include "funds/includes/round-block.html" %}
+
+    {% include "funds/includes/round-block.html" with closed_rounds=closed_rounds open_rounds=open_rounds %}
 
     {% block table %}
         {{ block.super }}
diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py
index 1bc6e5e49..246f4e980 100644
--- a/opentech/apply/funds/views.py
+++ b/opentech/apply/funds/views.py
@@ -44,7 +44,7 @@ from opentech.apply.utils.views import DelegateableView, ViewDispatcher
 
 from .differ import compare
 from .forms import ProgressSubmissionForm, ScreeningSubmissionForm, UpdateReviewersForm, UpdateSubmissionLeadForm
-from .models import ApplicationBase, ApplicationSubmission, ApplicationRevision, RoundBase, LabBase
+from .models import ApplicationBase, ApplicationSubmission, ApplicationRevision, Round, RoundBase, LabBase
 from .models.utils import SubmittableStreamForm
 from .tables import (
     AdminSubmissionsTable,
@@ -87,7 +87,18 @@ class BaseAdminSubmissionsTable(SingleTableMixin, FilterView):
             search_term=search_term,
         )
 
-        return kwargs
+        open_round_count = Round.objects.open().count()
+        open_rounds = Round.objects.open().order_by('-end_date')[:10]
+        closed_round_count = Round.objects.closed().count()
+        closed_rounds = Round.objects.closed().order_by('-end_date')[:10]
+
+        return super().get_context_data(
+            open_rounds=open_rounds,
+            open_round_count=open_round_count,
+            closed_rounds=closed_rounds,
+            closed_round_count=closed_round_count,
+            **kwargs,
+        )
 
 
 class SubmissionListView(AllActivityContextMixin, BaseAdminSubmissionsTable):
-- 
GitLab