-
-
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.
Merge remote-tracking branch 'origin/stable'
- Loading branch information
Showing
8 changed files
with
245 additions
and
19 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 |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Define the Grant subminer management command. | ||
Copyright (C) 2020 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 datetime import datetime | ||
|
||
from django.conf import settings | ||
from django.core.management.base import BaseCommand | ||
from django.db.models import Max, F | ||
from django.utils import timezone | ||
|
||
from dashboard.utils import get_tx_status, has_tx_mined | ||
from grants.clr import predict_clr | ||
from grants.models import Contribution, Grant, CartActivity, Subscription | ||
from grants.views import clr_active, round_end, next_round_start | ||
from marketing.mails import warn_subscription_failed, remember_your_cart | ||
from townsquare.models import MatchRound | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Sent reminder to user who forgot its cart ' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
'--test', | ||
default=False, | ||
type=bool, | ||
help="Only process and display the carts to being delivered" | ||
) | ||
parser.add_argument( | ||
'--full-cart', | ||
default=False, | ||
type=bool, | ||
help="Should the cart being delivered partially" | ||
) | ||
parser.add_argument( | ||
'--hours', | ||
type=int, | ||
help="Should the cart being delivered partially" | ||
) | ||
|
||
|
||
def handle(self, *args, **options): | ||
last_activity_by_user = CartActivity.objects.filter(latest=True, created_on__gt=next_round_start).exclude(metadata=[]) | ||
count = 0 | ||
if options.get('hours'): | ||
hours = options.get('hours') | ||
else: | ||
hours = int((round_end - datetime.now()).total_seconds() / 3600) | ||
|
||
for activity in last_activity_by_user: | ||
print(activity) | ||
|
||
# Check if this cart is still valid | ||
no_checkout_grants = [] | ||
for grant_entry in activity.metadata: | ||
subscription = Subscription.objects.filter(grant_id=grant_entry['grant_id'], | ||
contributor_profile=activity.profile, | ||
created_on__gt=activity.created_on, | ||
created_on__lte=round_end).first() | ||
|
||
if not subscription: | ||
no_checkout_grants.append(grant_entry) | ||
|
||
if options['full_cart']: | ||
if len(no_checkout_grants) != len(activity.metadata): | ||
print(f' * Activity {activity.id}: The grants were partially contributed but no notification will be delivered') | ||
continue | ||
|
||
cart_query = [f'{grant["grant_id"]};{grant.get("grant_donation_amount", 5)};{grant.get("token_local_id", 283)}' | ||
for grant in no_checkout_grants] | ||
|
||
cart_query = ','.join(cart_query) | ||
|
||
if not cart_query: | ||
print(f'** No items left in the {activity.profile}\'s cart') | ||
continue | ||
|
||
if not options['test']: | ||
try: | ||
remember_your_cart(activity.profile, cart_query, no_checkout_grants, hours) | ||
count += 1 | ||
except Exception as e: | ||
print(f'!! Failed to sent cart reminder email to {activity.profile}') | ||
print(e) | ||
|
||
print(f'\n\nSent {count} emails of {last_activity_by_user.count()} carts') | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{% extends 'emails/template.html' %} | ||
{% comment %} | ||
Copyright (C) 2020 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/>. | ||
{% endcomment %} | ||
{% load i18n humanize %} | ||
|
||
{% block content %} | ||
|
||
<style> | ||
.arrow-up{ | ||
width: 0; | ||
height: 0; | ||
border-left: 15px solid transparent; | ||
border-right: 15px solid transparent; | ||
border-bottom: 15px solid #ddd; | ||
margin-left: auto; | ||
margin-right: auto; | ||
} | ||
|
||
#founder_announce { | ||
background-color: #fafafa; | ||
margin-bottom: 15px; | ||
} | ||
|
||
#founder_announce a{ | ||
font-weight: bold; | ||
} | ||
</style> | ||
|
||
<div> | ||
<h1 class="text-centre">{% trans "Your cart is waiting for you" %}</h1> | ||
</div> | ||
|
||
<a href="https://gitcoin.co/owocki"> | ||
<img style="width: 100px; height: 100px;" src="https://gitcoin.co/dynamic/avatar/owocki"> | ||
</a> | ||
<div class="arrow-up"> </div> | ||
<div id="founder_announce" style="border: 1px solid #ddd; max-width: 500px; text-align: center; margin-left: auto; margin-right: auto; margin-bottom: 25px;"> | ||
<p style="margin: 5px; border-radius: 5px;"> | ||
{{desc|safe}} | ||
</p> | ||
</div> | ||
|
||
<HR> | ||
|
||
<div> | ||
<p style="margin: 5px; border-radius: 5px;"> | ||
You have the following {{grants|length}} grants in your cart: | ||
</p> | ||
<ol> | ||
{% for grant in grants %} | ||
<li><b>{{ grant.grant_title }}</b> ({{ grant.grant_donation_amount|default:5 }} {{ grant.grant_donation_currency|default:"DAI" }})</li> | ||
{% endfor %} | ||
</ol> | ||
</div> | ||
|
||
<HR> | ||
|
||
<a href={{base_url}}> | ||
<div style="margin-bottom: 2em; margin-top: 2em;"> | ||
<a class="button large" href="{{base_url}}{% url 'grants:grants_bulk_add' cart_query %}">{% trans "Go to cart" %}</a> | ||
</div> | ||
</a> | ||
|
||
|
||
{% endblock %} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Your cart is waiting for you | ||
|
||
{{ desc }}. | ||
|
||
Your cart grants: | ||
{% for grant in grants %} | ||
- {{ grant.grant_title }} ({{ grant.grant_donation_amount|default:5 }} {{ grant.grant_donation_currency|default:"DAI" }}) | ||
{% endfor %} | ||
|
||
Checkout your cart: {{base_url}}{% url 'grants:grants_bulk_add' cart_query %} |