Skip to content

Commit

Permalink
feat: add ability grant_excludes (#10264)
Browse files Browse the repository at this point in the history
* feat: add ability grant_excludes

* add migration file

* address feedback
  • Loading branch information
thelostone-mc authored Mar 8, 2022
1 parent 779c10e commit 72c7344
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/grants/clr_data_src.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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)
Expand All @@ -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


Expand Down
19 changes: 19 additions & 0 deletions app/grants/migrations/0139_grantclr_grant_excludes.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
5 changes: 5 additions & 0 deletions app/grants/models/grant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions app/grants/tests/models/test_grant_clr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down

0 comments on commit 72c7344

Please sign in to comment.