Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
gdixon committed Dec 1, 2021
2 parents 0ed844d + 1a31d9d commit abceaf0
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 83 deletions.
Binary file removed app/assets/v2/images/twitter_cards/grants12.jpg
Binary file not shown.
Binary file added app/assets/v2/images/twitter_cards/grants12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 12 additions & 12 deletions app/dashboard/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,21 +409,21 @@ def maybe_market_to_github(bounty, event_name, profile_pairs=None):
bool: Whether or not the Github comment was posted successfully.
"""
if not bounty.is_notification_eligible(var_to_check=settings.GITHUB_CLIENT_ID):
return False
try:
if not bounty.is_notification_eligible(var_to_check=settings.GITHUB_CLIENT_ID):
return False

# Define posting specific variables.
comment_id = None
url = bounty.github_url
uri = parse(url).path
uri_array = uri.split('/')
# Define posting specific variables.
comment_id = None
url = bounty.github_url
uri = parse(url).path
uri_array = uri.split('/')

# Prepare the comment message string.
msg = build_github_notification(bounty, event_name, profile_pairs)
if not msg:
return False
# Prepare the comment message string.
msg = build_github_notification(bounty, event_name, profile_pairs)
if not msg:
return False

try:
username = uri_array[1]
repo = uri_array[2]
issue_num = uri_array[4]
Expand Down
6 changes: 4 additions & 2 deletions app/grants/models/contribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ def blockexplorer_url_txid(self):
return self.blockexplorer_url_helper(self.tx_id)

def blockexplorer_url_helper(self, tx_id):
if self.checkout_type == 'eth_zksync':
if self.checkout_type == 'eth_polygon':
return f'https://polygonscan.com/tx/{tx_id}'
elif self.checkout_type == 'eth_zksync':
return f'https://zkscan.io/explorer/transactions/{tx_id.replace("sync-tx:", "")}'
if self.checkout_type == 'eth_std':
elif self.checkout_type == 'eth_std':
network_sub = f"{self.subscription.network}." if self.subscription and self.subscription.network != 'mainnet' else ''
return f'https://{network_sub}etherscan.io/tx/{tx_id}'
# TODO: support all block explorers for diff chains
Expand Down
2 changes: 1 addition & 1 deletion app/grants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ def grants_landing(request):
'title': 'Grants',
'EMAIL_ACCOUNT_VALIDATION': EMAIL_ACCOUNT_VALIDATION,
'card_desc': f'{live_now}',
'avatar_url': request.build_absolute_uri(static('v2/images/twitter_cards/grants12.jpg')),
'avatar_url': request.build_absolute_uri(static('v2/images/twitter_cards/grants12.png')),
'card_type': 'summary_large_image',
'avatar_height': 675,
'avatar_width': 1200,
Expand Down
22 changes: 11 additions & 11 deletions app/kudos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,18 +375,18 @@ def as_img(self):
root = environ.Path(__file__) - 2 # Set the base directory to two levels.
file_path = root('assets') + '/' + self.image

# download it if file is remote
if settings.AWS_STORAGE_BUCKET_NAME and settings.AWS_STORAGE_BUCKET_NAME in self.image:
file_path = f'cache/{self.pk}.png'
if not path.exists(file_path):
safe_url = self.image.replace(' ', '%20')
filedata = urllib.request.urlopen(safe_url)
datatowrite = filedata.read()
with open(file_path, 'wb') as f:
f.write(datatowrite)

# serve file
try:
# download it if file is remote
if settings.AWS_STORAGE_BUCKET_NAME and settings.AWS_STORAGE_BUCKET_NAME in self.image:
file_path = f'cache/{self.pk}.png'
if not path.exists(file_path):
safe_url = self.image.replace(' ', '%20')
filedata = urllib.request.urlopen(safe_url)
datatowrite = filedata.read()
with open(file_path, 'wb') as f:
f.write(datatowrite)

# serve file
with open(file_path, 'rb') as f:
obj = File(f)
from avatar.utils import svg_to_png
Expand Down
27 changes: 20 additions & 7 deletions app/retail/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ def render_new_contributions_email(grant):
'show_polygon_amount': False if amount_raised_polygon < 1 else True,
'num_of_contributors': num_of_contributors,
'media_url': settings.MEDIA_URL,
'contributions': contributions,
'utm_tracking': build_utm_tracking('new_contributions'),
}
response_html = premailer_transform(render_to_string("emails/grants/new_contributions.html", params))
response_txt = render_to_string("emails/grants/new_contributions.txt", params)
subject = _("You have new Grant contributions!")
subject = f"You have {contributions.count()} new Grant contributions worth ${round(amount_raised, 2)}!"

if amount_raised < 1:
# trigger to prevent email sending for negligible amounts
Expand All @@ -163,8 +164,17 @@ def render_new_contributions_email(grant):


def render_thank_you_for_supporting_email(grants_with_subscription):
totals = {}
for gws in grants_with_subscription:
key = gws['subscription'].token_symbol
val = gws['subscription'].amount_per_period
if key not in totals.keys():
totals[key] = 0
totals[key] += val

params = {
'grants_with_subscription': grants_with_subscription,
"totals": totals,
'utm_tracking': build_utm_tracking('thank_you_for_supporting_email'),
}
response_html = premailer_transform(render_to_string("emails/grants/thank_you_for_supporting.html", params))
Expand Down Expand Up @@ -272,12 +282,15 @@ def support_cancellation(request):

@staff_member_required
def thank_you_for_supporting(request):
grant = Grant.objects.first()
subscription = Subscription.objects.filter(grant__pk=grant.pk).first()
grant_with_subscription = [{
'grant': grant,
'subscription': subscription
}]
grant_with_subscription = []
for i in range(0, 10):
grant = Grant.objects.order_by('?').first()
subscription = Subscription.objects.filter(grant__pk=grant.pk).last()
if subscription:
grant_with_subscription.append({
'grant': grant,
'subscription': subscription
})
response_html, __, __ = render_thank_you_for_supporting_email(grant_with_subscription)
return HttpResponse(response_html)

Expand Down
35 changes: 35 additions & 0 deletions app/retail/templates/emails/grants/new_contributions.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
margin-top: 0 !important;
}
}
#transaction_history{
margin: 0px auto;
}
#transaction_history tr{
margin-left: 10px;
}
#transaction_history td{
padding: 10px;
}
#transaction_history tr.row td{
border-top: 1px solid #777;
}
</style>
<div id="content-body">
<img class="center-img bounties-img" src="{% static 'v2/images/emails/grants.png' %}">
Expand Down Expand Up @@ -127,6 +139,29 @@ <h1 style="text-transform: none; font-weight: normal; font-size: 36px;">New Cont
Grants Page</a>
</p>
</div>
<hr style="margin-left: 0; margin-top: 40px;">
<h3>The {{contributions.count}} Contributions: </h3>
<table id=transaction_history>
{% for contribution in contributions %}
{% with subscription=contribution.subscription %}
<tr class="row">
<td>
{{contribution.created_on|naturaltime}}
</td>
<td>
<img style="height: 20px; width:20px; border-radius: 10px;" src="https://gitcoin.co/dynamic/avatar/{{subscription.contributor_profile.handle}}">
<a href="https://gitcoin.co/{{subscription.contributor_profile.handle}}">{{subscription.contributor_profile.handle}}</a>
</td>
<td>
{{subscription.amount_per_period|floatformat:4}} {{subscription.token_symbol}}
</td>
<td>
<a href="{{contribution.blockexplorer_url_split_txid}}">view &gt;&gt;</a>
</td>
</tr>
{% endwith %}
{% endfor %}
</table>
</div>

{% endblock %}
98 changes: 55 additions & 43 deletions app/retail/templates/emails/grants/thank_you_for_supporting.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,57 +63,69 @@
max-width: 25rem;
width: 100%;
}
.robot-img {
max-width: 10em;
width: 10em;
}
.contribution_table{
margin: 0px auto;
}
.contribution_table td{
padding: 5px;
border-top: 1px solid black;
}
</style>
<div id="content-body">
<img class="center-img bounties-img" src="{% static 'v2/images/emails/grants.png' %}">
<img class="center-img robot-img" src="{% static "v2/images/heart-robot.png" %}" alt="{% trans "Gitcoin Heart Robot" %}" title="{% trans "Gitcoin Heart Robot" %}">
<h1 style="text-align:center; margin-top: 10px;">🤖❤️{% trans "Thank you for supporting these grants on Gitcoin!" %}</h1>
<table class="contribution_table">
<tr>
<td>
Grant
</td>
<td>
Amount
</td>
<td>
Transaction
</td>
</tr>
{% for grant_with_subscription in grants_with_subscription %}
{% with subscription=grant_with_subscription.subscription grant=grant_with_subscription.grant %}
<div class="grant-header">
<img src="{% static "v2/images/heart-robot.png" %}" alt="{% trans "Gitcoin Heart Robot" %}" title="{% trans "Gitcoin Heart Robot" %}">
<div style="margin-top: 4em;">
<h1 style="text-transform: none;">{% trans "Thank you for supporting" %} {{ grant.title }}!
</h1>
<h2 style="text-transform: none;">{% trans "The world of open source is a better place because of you." %}
</h2>
</div>
</div>

<hr style="margin-left: 0;">
<br>
<div class="grant-info">
<a href="{% url 'grants:details' grant.id grant.slug %}?{{ utm_tracking }}">
<img id="grant-logo"
src="{% if grant.logo and grant.logo.url %}{{ grant.logo.url }}{% else %}{% with grant_logo='v2/images/grants/logos/' id=grant.id|modulo:3 %}{% static grant_logo|addstr:id|add:'.png' %}{% endwith %}{% endif %}" />
</a>
<br>
<a class="grant-info-name" href="{% url 'grants:details' grant.id grant.slug %}?{{ utm_tracking }}">
{{ grant.title }}
</a>
<p class="grant-description">
{{ grant.description|truncatechars:300 }}
</p>
<p>
{% trans "You have contributed" %}
</p>
<p>
<strong>{{ subscription.amount_per_period|floatformat:4|intcomma }} {{ subscription.token_symbol }} </strong>
</p>
<p>{% trans "You can see all the grants you support and your transaction history " %}
<a href="{% url 'grants:profile' %}?{{ utm_tracking }}">{% trans "here." %}</a>
</p>
</div>
<tr>
<td>
<a href="{% url 'grants:details' grant.id grant.slug %}?{{ utm_tracking }}">
{{ grant.title }}
</a>
</td>
<td>
{{ subscription.amount_per_period|floatformat:4|intcomma }} {{ subscription.token_symbol }}
</td>
<td>
<a href="{{subscription.subscription_contribution.first.blockexplorer_url_split_txid}}">view &gt;&gt;</a>
</td>
</tr>

<br>
<a class="btn" href="{% url 'grants:details' grant.id grant.slug %}?{{ utm_tracking }}">{% trans "View Updates" %}</a>
<hr style="margin-left: 0;">
{% endwith %}
{% endfor %}

<div>
<h3>How did we do?</h3>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSdSVQ2OHbmqqEDEfE0vlRE5exLZso7TM_Eo4nZg7vnu2GE1Cw/viewform">Take this quick survey and receive an NFT</a>
<p>Share your honest feedback so that we can improve the product.</p>
<img src="{% static 'v2/images/survey-nft.png' %}" alt="Kudos preview">
</div>
<tr>
<td>
<strong>Total</strong>
</td>
<td>
{%for key, val in totals.items%}
{{val|floatformat:4}} {{key}}
{%endfor%}
</td>
<td>
</td>
</tr>
</table>

<p>{% trans "You can see all the grants you support and your transaction history " %}
<a href="{% url 'grants:profile' %}?{{ utm_tracking }}">{% trans "here." %}</a>
</p>
</div>
{% endblock %}
23 changes: 16 additions & 7 deletions app/retail/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,54 +750,60 @@ def get_specific_activities(what, trending_only, user, after_pk, request=None, p

activities = Activity.objects.none()

page_size = 10
start_index = (page-1) * page_size
end_index = page * page_size

# 2. Choose which filter to index

filter_applied = False

# grants
if (
what in ['grants', 'all_grants']
):
activity_pks = ActivityIndex.objects.filter(key__startswith='grant:')
filter_applied = True
elif 'grant:' in what:
activity_pks = ActivityIndex.objects.filter(key=what)
filter_applied = True

# all Grants
if what == 'all_grants':
activity_pks = ActivityIndex.objects.filter(key__startswith='grant:')
filter_applied = True

# kudos
if (
what in ['kudos']
):
activity_pks = ActivityIndex.objects.filter(key__startswith='kudo:')
filter_applied = True
elif 'kudos:' in what:
activity_pks = ActivityIndex.objects.filter(key=what.replace('kudos', 'kudo'))
filter_applied = True

# hackathon project
if 'project:' in what:
activity_pks = ActivityIndex.objects.filter(key=what)
filter_applied = True

# tribes
if 'tribe:' in what:
handle = what[6:]
print(handle)
profile = Profile.objects.filter(handle=handle).first()
filter_applied = True
if profile:
activity_pks = ActivityIndex.objects.filter(key=f'profile:{profile.pk}')

# hackathon activity
if 'hackathon:' in what:
activity_pks = ActivityIndex.objects.filter(key=what)
filter_applied = True

# single activity
if 'activity:' in what:
activity_pks = [what.replace('activity:', '')]
filter_applied = True

# Defaults
if not activity_pks:
if not activity_pks and not filter_applied:
activity_pks = ActivityIndex.objects.all()

# Are the pks already in a list?
Expand All @@ -806,6 +812,9 @@ def get_specific_activities(what, trending_only, user, after_pk, request=None, p
activity_pks = activity_pks.order_by('-id')
# Pagination is done here
if page:
page_size = 10
start_index = (page-1) * page_size
end_index = page * page_size
activity_pks = activity_pks[start_index:end_index].values_list('activity_id', flat=True)
else:
activity_pks = activity_pks.values_list('activity_id', flat=True)
Expand All @@ -831,7 +840,7 @@ def get_specific_activities(what, trending_only, user, after_pk, request=None, p

def activity(request):
"""Render the Activity response."""
page_size = 7

page = int(request.GET.get('page', 1)) if request.GET.get('page') and request.GET.get('page').isdigit() else 1
what = request.GET.get('what', 'everywhere')
trending_only = int(request.GET.get('trending_only', 0)) if request.GET.get('trending_only') and request.GET.get('trending_only').isdigit() else 0
Expand Down

0 comments on commit abceaf0

Please sign in to comment.