From 72c734466020590de132c05ebe0d4b79ad664431 Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Tue, 8 Mar 2022 08:45:31 +0530 Subject: [PATCH] feat: add ability grant_excludes (#10264) * feat: add ability grant_excludes * add migration file * address feedback --- app/grants/clr_data_src.py | 6 +++++- .../0139_grantclr_grant_excludes.py | 19 +++++++++++++++++++ app/grants/models/grant.py | 5 +++++ app/grants/tests/models/test_grant_clr.py | 11 +++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 app/grants/migrations/0139_grantclr_grant_excludes.py diff --git a/app/grants/clr_data_src.py b/app/grants/clr_data_src.py index f9437b3cfd9..e4643d90a6e 100644 --- a/app/grants/clr_data_src.py +++ b/app/grants/clr_data_src.py @@ -1,6 +1,6 @@ from django.db import connection -from grants.models import Contribution, Grant, GrantCollection +from grants.models import Contribution, GrantCollection from townsquare.models import SquelchProfile @@ -17,6 +17,7 @@ def fetch_grants(clr_round, network='mainnet'): ''' grant_filters = clr_round.grant_filters + grant_excludes = clr_round.grant_excludes collection_filters = clr_round.collection_filters grants = clr_round.grants.filter(network=network, hidden=False, active=True, is_clr_eligible=True, link_to_new_grant=None) @@ -29,6 +30,9 @@ def fetch_grants(clr_round, network='mainnet'): grant_ids = GrantCollection.objects.filter(**collection_filters).values_list('grants', flat=True) grants = grants.filter(pk__in=grant_ids) + if grant_excludes: + grants = grants.exclude(**grant_excludes) + return grants diff --git a/app/grants/migrations/0139_grantclr_grant_excludes.py b/app/grants/migrations/0139_grantclr_grant_excludes.py new file mode 100644 index 00000000000..600b39a6398 --- /dev/null +++ b/app/grants/migrations/0139_grantclr_grant_excludes.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.24 on 2022-03-08 03:12 + +import django.contrib.postgres.fields.jsonb +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('grants', '0138_granttag_is_eligibility_tag'), + ] + + operations = [ + migrations.AddField( + model_name='grantclr', + name='grant_excludes', + field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict, help_text='Grants excluded in this CLR round', null=True), + ), + ] diff --git a/app/grants/models/grant.py b/app/grants/models/grant.py index b8bb253946b..4249bf723b4 100644 --- a/app/grants/models/grant.py +++ b/app/grants/models/grant.py @@ -130,6 +130,11 @@ class Meta: null=True, blank=True, help_text="Grants allowed in this CLR round" ) + grant_excludes = JSONField( + default=dict, + null=True, blank=True, + help_text="Grants excluded in this CLR round" + ) subscription_filters = JSONField( default=dict, null=True, blank=True, diff --git a/app/grants/tests/models/test_grant_clr.py b/app/grants/tests/models/test_grant_clr.py index d7b00e03ba3..dc0ec23d277 100644 --- a/app/grants/tests/models/test_grant_clr.py +++ b/app/grants/tests/models/test_grant_clr.py @@ -90,6 +90,17 @@ def test_grant_clr_has_grant_filters(self): assert grant_clr.grant_filters == {} assert len(grant_clr.grant_filters) == 0 + + def test_grant_clr_has_grant_excludes(self): + """Test grant_excludes attribute is present and defaults to an empty dictionary.""" + + grant_clr = GrantCLRFactory() + + assert hasattr(grant_clr, 'grant_excludes') + assert grant_clr.grant_excludes == {} + assert len(grant_clr.grant_excludes) == 0 + + def test_grant_clr_has_subscription_filters(self): """Test subscription_filters attribute is present and defaults to an empty dictionary."""