From 0fc44a79c9103af7ebd710877c2e1c6a95bb1fe4 Mon Sep 17 00:00:00 2001
From: sks444 <krishnasingh.ss30@gmail.com>
Date: Mon, 28 Sep 2020 10:18:21 +0530
Subject: [PATCH] Fix migration file

---
 hypha/apply/funds/tables.py                   |  2 +-
 ...add_investments_table_and_partners_page.py | 48 ++++++++++++++-----
 .../0002_remove_partnerpage_name.py           | 17 -------
 .../0003_investmentcategorysettings.py        | 27 -----------
 .../migrations/0004_investmentcategory.py     | 23 ---------
 hypha/public/partner/tables.py                | 27 ++++++++---
 6 files changed, 58 insertions(+), 86 deletions(-)
 delete mode 100644 hypha/public/partner/migrations/0002_remove_partnerpage_name.py
 delete mode 100644 hypha/public/partner/migrations/0003_investmentcategorysettings.py
 delete mode 100644 hypha/public/partner/migrations/0004_investmentcategory.py

diff --git a/hypha/apply/funds/tables.py b/hypha/apply/funds/tables.py
index c40767822..fc4d824f8 100644
--- a/hypha/apply/funds/tables.py
+++ b/hypha/apply/funds/tables.py
@@ -249,7 +249,7 @@ class StatusMultipleChoiceFilter(Select2MultipleChoiceFilter):
         return any(item in second for item in first)
 
     def get_filter_predicate(self, v):
-        return {f'{ self.field_name }__in': self.status_map[v]}
+        return {f'{ self.field_name }__in': v}
 
 
 class SubmissionFilter(filters.FilterSet):
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 6d2dda6c2..a06da0b52 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-14 12:16
+# Generated by Django 2.2.16 on 2020-09-28 07:00
 
 import django.core.validators
 from django.db import migrations, models
@@ -14,11 +14,25 @@ class Migration(migrations.Migration):
 
     dependencies = [
         ('wagtailcore', '0045_assign_unlock_grouppagepermission'),
-        ('funds', '0078_add_heading_block_to_form_fields_block'),
         ('images', '0003_customimage_drupal_id'),
+        ('categories', '0005_alter_is_archived_field_on_terms'),
+        ('funds', '0079_add_reviewer_settings_for_submission_access'),
     ]
 
     operations = [
+        migrations.CreateModel(
+            name='Investment',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('name', models.CharField(max_length=50)),
+                ('year', models.IntegerField(default=hypha.public.partner.models.current_year, help_text='Use format: <YYYY>', validators=[django.core.validators.MinValueValidator(1984), hypha.public.partner.models.max_value_current_year])),
+                ('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=True)),
+                ('application', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='funds.ApplicationSubmission')),
+            ],
+        ),
         migrations.CreateModel(
             name='PartnerPage',
             fields=[
@@ -26,7 +40,6 @@ class Migration(migrations.Migration):
                 ('social_text', models.CharField(blank=True, max_length=255)),
                 ('listing_title', models.CharField(blank=True, help_text='Override the page title used when this page appears in listings', max_length=255)),
                 ('listing_summary', models.CharField(blank=True, help_text="The text summary used when this page appears in listings. It's also used as the description for search engines if the 'Search description' field above is not defined.", max_length=255)),
-                ('name', models.CharField(max_length=100)),
                 ('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive')], default='current_partner', max_length=20)),
                 ('public', models.BooleanField(default=True)),
                 ('description', wagtail.core.fields.RichTextField(blank=True)),
@@ -59,17 +72,28 @@ class Migration(migrations.Migration):
             bases=(wagtailcache.cache.WagtailCacheMixin, 'wagtailcore.page', models.Model),
         ),
         migrations.CreateModel(
-            name='Investment',
+            name='InvestmentCategorySettings',
             fields=[
                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
-                ('name', models.CharField(max_length=50)),
-                ('year', models.IntegerField(default=hypha.public.partner.models.current_year, help_text='Use format: <YYYY>', validators=[django.core.validators.MinValueValidator(1984), hypha.public.partner.models.max_value_current_year])),
-                ('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=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')),
+                ('categories', models.ManyToManyField(help_text='Select the categories that should be used in investments.', to='categories.Category')),
+                ('site', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, to='wagtailcore.Site')),
+            ],
+            options={
+                'verbose_name': 'Investment Category Settings',
+            },
+        ),
+        migrations.CreateModel(
+            name='InvestmentCategory',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('name', models.CharField(blank=True, max_length=255, null=True)),
+                ('value', models.CharField(blank=True, max_length=255, null=True)),
+                ('investment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='categories', to='partner.Investment')),
             ],
         ),
+        migrations.AddField(
+            model_name='investment',
+            name='partner',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='investments', to='partner.PartnerPage'),
+        ),
     ]
diff --git a/hypha/public/partner/migrations/0002_remove_partnerpage_name.py b/hypha/public/partner/migrations/0002_remove_partnerpage_name.py
deleted file mode 100644
index aecd1442f..000000000
--- a/hypha/public/partner/migrations/0002_remove_partnerpage_name.py
+++ /dev/null
@@ -1,17 +0,0 @@
-# Generated by Django 2.2.16 on 2020-09-16 04:59
-
-from django.db import migrations
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('partner', '0001_add_investments_table_and_partners_page'),
-    ]
-
-    operations = [
-        migrations.RemoveField(
-            model_name='partnerpage',
-            name='name',
-        ),
-    ]
diff --git a/hypha/public/partner/migrations/0003_investmentcategorysettings.py b/hypha/public/partner/migrations/0003_investmentcategorysettings.py
deleted file mode 100644
index b15c855f7..000000000
--- a/hypha/public/partner/migrations/0003_investmentcategorysettings.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# Generated by Django 2.2.16 on 2020-09-17 14:58
-
-from django.db import migrations, models
-import django.db.models.deletion
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('wagtailcore', '0045_assign_unlock_grouppagepermission'),
-        ('categories', '0005_alter_is_archived_field_on_terms'),
-        ('partner', '0002_remove_partnerpage_name'),
-    ]
-
-    operations = [
-        migrations.CreateModel(
-            name='InvestmentCategorySettings',
-            fields=[
-                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
-                ('categories', models.ManyToManyField(help_text='Select the categories that should be used in investments.', to='categories.Category')),
-                ('site', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, to='wagtailcore.Site')),
-            ],
-            options={
-                'verbose_name': 'Investment Category Settings',
-            },
-        ),
-    ]
diff --git a/hypha/public/partner/migrations/0004_investmentcategory.py b/hypha/public/partner/migrations/0004_investmentcategory.py
deleted file mode 100644
index 3233cf2d3..000000000
--- a/hypha/public/partner/migrations/0004_investmentcategory.py
+++ /dev/null
@@ -1,23 +0,0 @@
-# Generated by Django 2.2.16 on 2020-09-21 06:25
-
-from django.db import migrations, models
-import django.db.models.deletion
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('partner', '0003_investmentcategorysettings'),
-    ]
-
-    operations = [
-        migrations.CreateModel(
-            name='InvestmentCategory',
-            fields=[
-                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
-                ('name', models.CharField(blank=True, max_length=255, null=True)),
-                ('value', models.CharField(blank=True, max_length=255, null=True)),
-                ('investment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='categories', to='partner.Investment')),
-            ],
-        ),
-    ]
diff --git a/hypha/public/partner/tables.py b/hypha/public/partner/tables.py
index 746770744..452e2a4b9 100644
--- a/hypha/public/partner/tables.py
+++ b/hypha/public/partner/tables.py
@@ -9,9 +9,23 @@ from hypha.apply.funds.tables import Select2MultipleChoiceFilter
 from .models import Investment, InvestmentCategorySettings, PartnerPage
 
 
-def get_year_choices():
-    years = Investment.objects.order_by('-year').values_list('year', flat=True).distinct()
-    return [(year, str(year)) for year in years]
+class YearMultipleChoiceFilter(Select2MultipleChoiceFilter):
+    def __init__(self, *args, **kwargs):
+        years = Investment.objects.order_by('-year').values_list('year', flat=True).distinct()
+        choices = [(year, str(year)) for year in years]
+        super().__init__(
+            *args,
+            field_name='year',
+            choices=choices,
+            label='Years',
+            **kwargs,
+        )
+
+    def has_any(self, first, second):
+        return any(item in second for item in first)
+
+    def get_filter_predicate(self, v):
+        return {f'{ self.field_name }': v}
 
 
 class InvestmentFilter(filters.FilterSet):
@@ -27,9 +41,6 @@ class InvestmentFilter(filters.FilterSet):
         ('1m+', '$1m+'),
     )
 
-    YEAR_CHOICES = get_year_choices()
-
-    year = Select2MultipleChoiceFilter(choices=YEAR_CHOICES, label='Years')
     amount_committed = Select2MultipleChoiceFilter(
         choices=AMOUNT_COMMITTED_CHOICES,
         label='Amount Committed(US$)',
@@ -49,6 +60,10 @@ class InvestmentFilter(filters.FilterSet):
         model = Investment
         fields = ('year', 'amount_committed')
 
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        self.filters['year'] = YearMultipleChoiceFilter()
+
     def filter_amount_committed(self, queryset, name, value):
         query = Q()
         for v in value:
-- 
GitLab