-
-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functionality so one POST now saves payload then ingests grant data
- Loading branch information
Showing
3 changed files
with
228 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ | |
support_cancellation, thank_you_for_supporting, | ||
) | ||
from marketing.models import Keyword, Stat | ||
from perftools.models import JSONStore | ||
from ratelimit.decorators import ratelimit | ||
from retail.helpers import get_ip | ||
from townsquare.models import Comment, PinnedPost | ||
|
@@ -850,7 +851,157 @@ def grant_fund(request, grant_id, grant_slug): | |
|
||
raise Http404 | ||
|
||
@login_required | ||
def bulk_fund(request): | ||
if request.method != 'POST': | ||
raise Http404 | ||
|
||
# Save off payload data | ||
JSONStore.objects.create( | ||
key=request.POST.get('split_tx_id'), # use bulk data tx hash as key | ||
view='bulk_fund_post_payload', | ||
data=request.POST | ||
) | ||
|
||
# Get list of grant IDs | ||
grant_ids_list = [int(pk) for pk in request.POST.get('grant_id').split(',')] | ||
|
||
# For each grant, we validate the data. If it fails, save it off and throw error at the end | ||
successes = [] | ||
failures = [] | ||
for (index, grant_id) in enumerate(grant_ids_list): | ||
try: | ||
grant = Grant.objects.get(pk=grant_id) | ||
except Grant.DoesNotExist: | ||
failures.append({ | ||
'active': 'grant_error', | ||
'title': _('Fund - Grant Does Not Exist'), | ||
'grant':grant_id, | ||
'text': _('This grant does not exist'), | ||
'subtext': _('No grant with this ID was found'), | ||
'success': False | ||
}) | ||
continue | ||
|
||
profile = get_profile(request) | ||
|
||
if not grant.active: | ||
failures.append({ | ||
'active': 'grant_error', | ||
'title': _('Fund - Grant Ended'), | ||
'grant':grant_id, | ||
'text': _('This Grant has ended.'), | ||
'subtext': _('Contributions can no longer be made this grant'), | ||
'success': False | ||
}) | ||
continue | ||
|
||
if is_grant_team_member(grant, profile): | ||
failures.append({ | ||
'active': 'grant_error', | ||
'title': _('Fund - Grant funding blocked'), | ||
'grant':grant_id, | ||
'text': _('This Grant cannot be funded'), | ||
'subtext': _('Grant team members cannot contribute to their own grant.'), | ||
'success': False | ||
}) | ||
continue | ||
|
||
if grant.link_to_new_grant: | ||
failures.append({ | ||
'active': 'grant_error', | ||
'title': _('Fund - Grant Migrated'), | ||
'grant':grant_id, | ||
'text': _('This Grant has ended'), | ||
'subtext': _('Contributions can no longer be made to this grant. <br> Visit the new grant to contribute.'), | ||
'success': False | ||
}) | ||
continue | ||
|
||
active_subscription = Subscription.objects.select_related('grant').filter( | ||
grant=grant_id, active=True, error=False, contributor_profile=request.user.profile, is_postive_vote=True | ||
) | ||
|
||
if active_subscription: | ||
failures.append({ | ||
'active': 'grant_error', | ||
'title': _('Subscription Exists'), | ||
'grant':grant_id, | ||
'text': _('You already have an active subscription for this grant.'), | ||
'success': False | ||
}) | ||
continue | ||
|
||
if not grant.configured_to_receieve_funding: | ||
failures.append({ | ||
'active': 'grant_error', | ||
'title': _('Fund - Grant Not Configured'), | ||
'grant':grant_id, | ||
'text': _('This Grant is not configured to accept funding at this time.'), | ||
'subtext': _('Grant is not properly configured for funding. Please set grant.contract_address on this grant, or contact [email protected] if you believe this message is in error!'), | ||
'success': False | ||
}) | ||
continue | ||
|
||
try: | ||
from grants.tasks import process_grant_contribution | ||
payload = { | ||
# Values that are constant for all donations | ||
'contributor_address': request.POST.get('contributor_address'), | ||
'csrfmiddlewaretoken': request.POST.get('csrfmiddlewaretoken'), | ||
'frequency_count': request.POST.get('frequency_count'), | ||
'frequency_unit': request.POST.get('frequency_unit'), | ||
'gas_price': request.POST.get('gas_price'), | ||
'gitcoin_donation_address': request.POST.get('gitcoin_donation_address'), | ||
'hide_wallet_address': request.POST.get('hide_wallet_address'), | ||
'match_direction': request.POST.get('match_direction'), | ||
'network': request.POST.get('network'), | ||
'num_periods': request.POST.get('num_periods'), | ||
'real_period_seconds': request.POST.get('real_period_seconds'), | ||
'recurring_or_not': request.POST.get('recurring_or_not'), | ||
'signature': request.POST.get('signature'), | ||
'split_tx_id': request.POST.get('split_tx_id'), | ||
'splitter_contract_address': request.POST.get('splitter_contract_address'), | ||
'subscription_hash': request.POST.get('subscription_hash'), | ||
# Values that vary by donation | ||
'admin_address': request.POST.get('admin_address').split(',')[index], | ||
'amount_per_period': request.POST.get('amount_per_period').split(',')[index], | ||
'comment': request.POST.get('comment').split(',')[index], | ||
'confirmed': request.POST.get('confirmed').split(',')[index], | ||
'contract_address': request.POST.get('contract_address').split(',')[index], | ||
'contract_version': request.POST.get('contract_version').split(',')[index], | ||
'denomination': request.POST.get('denomination').split(',')[index], | ||
'gitcoin-grant-input-amount': request.POST.get('gitcoin-grant-input-amount').split(',')[index], | ||
'grant_id': request.POST.get('grant_id').split(',')[index], | ||
'sub_new_approve_tx_id': request.POST.get('sub_new_approve_tx_id').split(',')[index], | ||
'token_address': request.POST.get('token_address').split(',')[index], | ||
'token_symbol': request.POST.get('token_symbol').split(',')[index], | ||
} | ||
process_grant_contribution.delay(grant_id, grant.slug, profile.pk, payload) | ||
except Exception as e: | ||
failures.append({ | ||
'active': 'grant_error', | ||
'title': _('Fund - Grant Processing Failed'), | ||
'grant':grant_id, | ||
'text': _('This Grant was not processed successfully.'), | ||
'subtext': _(f'{str(e)}'), | ||
'success': False | ||
}) | ||
continue | ||
|
||
successes.append({ | ||
'title': _('Fund - Grant Funding Processed Successfully'), | ||
'grant':grant_id, | ||
'text': _('Funding for this grant was successfully processed and saved.'), | ||
'success': True | ||
}) | ||
|
||
return JsonResponse({ | ||
'success': True, | ||
'grant_ids': grant_ids_list, | ||
'successes': successes, | ||
'failures': failures | ||
}) | ||
|
||
@login_required | ||
def subscription_cancel(request, grant_id, grant_slug, subscription_id): | ||
|