Skip to content

Commit

Permalink
management command for grant_txn_failed_email
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiantf committed Jun 6, 2020
1 parent b18bf1f commit 20b2b76
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
32 changes: 32 additions & 0 deletions app/dashboard/management/commands/grant_txn_failed_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'''
Copyright (C) 2019 Gitcoin Core
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
from django.conf import settings
from django.core.management.base import BaseCommand

from grants.models import Contribution
from marketing.mails import grant_txn_failed


class Command(BaseCommand):
help = 'sends emails for grant contributors whose contribution txns have failed'

def handle(self, *args, **options):
if settings.DEBUG:
print("not active in non prod environments")
return

failed_contribs = Contribution.objects.exclude(validator_passed=True)

for failed_contrib in failed_contribs:
grant_txn_failed(failed_contrib.subscription.contributor_profile, failed_contrib.subscription.grant, failed_contrib.tx_id)
21 changes: 20 additions & 1 deletion app/marketing/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
render_bounty_expire_warning, render_bounty_feedback, render_bounty_request, render_bounty_startwork_expire_warning,
render_bounty_unintersted, render_comment, render_faucet_rejected, render_faucet_request,
render_featured_funded_bounty, render_funder_payout_reminder, render_funder_stale, render_gdpr_reconsent,
render_gdpr_update, render_grant_cancellation_email, render_grant_update, render_kudos_email,
render_gdpr_update, render_grant_cancellation_email, render_grant_txn_failed, render_grant_update, render_kudos_email,
render_match_distribution, render_match_email, render_mention, render_new_bounty, render_new_bounty_acceptance,
render_new_bounty_rejection, render_new_bounty_roundup, render_new_grant_email, render_new_supporter_email,
render_new_work_submission, render_no_applicant_reminder, render_nth_day_email_campaign, render_quarterly_stats,
Expand Down Expand Up @@ -288,6 +288,25 @@ def grant_cancellation(grant, subscription):
finally:
translation.activate(cur_language)

def grant_txn_failed(profile, grant, tx_id):
from_email = settings.CONTACT_EMAIL
to_email = profile.email
if not to_email:
if profile and profile.user:
to_email = profile.user.email
if not to_email:
return

cur_language = translation.get_language()

subject = f"Your Grant transaction failed. Wanna try again?"

try:
setup_lang(to_email)
html, text = render_grant_txn_failed(to_email, grant, tx_id)
send_mail(from_email, to_email, subject, text, html, categories=['transactional', func_name()])
finally:
translation.activate(cur_language)

def subscription_terminated(grant, subscription):
if subscription and subscription.negative:
Expand Down

0 comments on commit 20b2b76

Please sign in to comment.