From 08fe473e6cbeefcb01e5d45219b42979199377a3 Mon Sep 17 00:00:00 2001
From: sks444 <krishnasingh.ss30@gmail.com>
Date: Mon, 14 Sep 2020 17:54:46 +0530
Subject: [PATCH] Add total investments to the partners page

---
 ...001_add_investments_table_and_partners_page.py |  6 +++---
 hypha/public/partner/models.py                    | 15 ++++++++++-----
 .../partner/templates/partner/partner_page.html   |  3 +++
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/hypha/public/partner/migrations/0001_add_investments_table_and_partners_page.py b/hypha/public/partner/migrations/0001_add_investments_table_and_partners_page.py
index c8ac3b68d..6d2dda6c2 100644
--- a/hypha/public/partner/migrations/0001_add_investments_table_and_partners_page.py
+++ b/hypha/public/partner/migrations/0001_add_investments_table_and_partners_page.py
@@ -1,4 +1,4 @@
-# Generated by Django 2.2.16 on 2020-09-13 22:41
+# Generated by Django 2.2.16 on 2020-09-14 12:16
 
 import django.core.validators
 from django.db import migrations, models
@@ -13,9 +13,9 @@ class Migration(migrations.Migration):
     initial = True
 
     dependencies = [
-        ('images', '0003_customimage_drupal_id'),
         ('wagtailcore', '0045_assign_unlock_grouppagepermission'),
         ('funds', '0078_add_heading_block_to_form_fields_block'),
+        ('images', '0003_customimage_drupal_id'),
     ]
 
     operations = [
@@ -67,7 +67,7 @@ class Migration(migrations.Migration):
                 ('amount_committed', models.DecimalField(decimal_places=2, default=0, max_digits=11, verbose_name='Ammount Commited US$')),
                 ('description', models.TextField()),
                 ('created_at', models.DateTimeField(auto_now_add=True)),
-                ('updated_at', models.DateTimeField(auto_now_add=True)),
+                ('updated_at', models.DateTimeField(auto_now=True)),
                 ('application', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='funds.ApplicationSubmission')),
                 ('partner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='investments', to='partner.PartnerPage')),
             ],
diff --git a/hypha/public/partner/models.py b/hypha/public/partner/models.py
index 2e2e52616..e3e9a828e 100644
--- a/hypha/public/partner/models.py
+++ b/hypha/public/partner/models.py
@@ -11,7 +11,7 @@ from wagtail.images.edit_handlers import ImageChooserPanel
 from wagtail.search import index
 
 from hypha.apply.funds.models import ApplicationSubmission
-from hypha.public.utils.models import BasePage
+from hypha.public.utils.models import BasePage, FundingMixin
 
 
 class PartnerIndexPage(BasePage):
@@ -29,12 +29,10 @@ class PartnerIndexPage(BasePage):
     ]
 
     def serve(self, request, *args, **kwargs):
-        # import ipdb; ipdb.set_trace()
         return redirect('investments')
-        # return super().serve(request, *args, **kwargs)
 
 
-class PartnerPage(BasePage):
+class PartnerPage(FundingMixin, BasePage):
     STATUS = [
         ('active', 'Active'),
         ('inactive', 'Inactive')
@@ -73,6 +71,13 @@ class PartnerPage(BasePage):
     def __str__(self):
         return self.name
 
+    def get_context(self, request):
+        context = super(PartnerPage, self).get_context(request)
+        context['total_investments'] = sum(
+            investment.amount_committed for investment in self.investments.all()
+        )
+        return context
+
     def get_absolute_url(self):
         return self.url
 
@@ -112,7 +117,7 @@ class Investment(models.Model):
     )
 
     created_at = models.DateTimeField(auto_now_add=True)
-    updated_at = models.DateTimeField(auto_now_add=True)
+    updated_at = models.DateTimeField(auto_now=True)
 
     def __str__(self):
         return self.name
diff --git a/hypha/public/partner/templates/partner/partner_page.html b/hypha/public/partner/templates/partner/partner_page.html
index 7d81860bd..b75bbabea 100644
--- a/hypha/public/partner/templates/partner/partner_page.html
+++ b/hypha/public/partner/templates/partner/partner_page.html
@@ -16,6 +16,9 @@
         {% if page.web_url %}
             <p class="list list--contact"><span>Website:</span> <a href="{{ page.web_url }}">{{ page.web_url }}</a></p>
         {% endif %}
+
+        <p class="list list--contact"><span>Total Investments:   </span>US$ {{ total_investments }}</p>
+
     </div>
 
     <div>
-- 
GitLab