Skip to content

Commit

Permalink
Merge branch 'stable' of github.com:gitcoinco/web
Browse files Browse the repository at this point in the history
  • Loading branch information
owocki committed Feb 6, 2020
2 parents ee48526 + a11aadd commit 49f5ebc
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 43 deletions.
2 changes: 2 additions & 0 deletions app/app/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@

logger = logging.getLogger(__name__)


def fetchPost(qt='2'):
"""Fetch last post from wordpress blog."""
url = f"https://gitcoin.co/blog/wp-json/wp/v2/posts?_fields=excerpt,title,link,jetpack_featured_media_url&per_page={qt}"
last_posts = requests.get(url=url).json()
return last_posts


@cached_as(Announcement.objects.filter(key__in=['footer', 'header']), timeout=120)
def get_sitewide_announcements():
announcements = Announcement.objects.filter(key__in=['footer', 'header'])
Expand Down
12 changes: 10 additions & 2 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,16 @@

# bounty requests
re_path(r'^requests/?', bounty_requests.views.bounty_request, name='bounty_requests'),
url('^api/v1/bounty_request/create', bounty_requests.views.create_bounty_request_v1, name='create_bounty_request_v1'),
url('^api/v1/bounty_request/update', bounty_requests.views.update_bounty_request_v1, name='update_bounty_request_v1'),
url(
'^api/v1/bounty_request/create',
bounty_requests.views.create_bounty_request_v1,
name='create_bounty_request_v1'
),
url(
'^api/v1/bounty_request/update',
bounty_requests.views.update_bounty_request_v1,
name='update_bounty_request_v1'
),

# admin views
re_path(r'^_administration/?', admin.site.urls, name='admin'),
Expand Down
23 changes: 13 additions & 10 deletions app/assets/v2/js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,19 @@ $(document).ready(function() {
});

$('.activity.wall_post .activity-status b, .activity.status_update .activity-status b').each(function() {
let new_text = $(this).text();

new_text = new_text.replace('<', '_');
new_text = new_text.replace('>', '_');
new_text = new_text.replace('>', '_');
new_text = new_text.replace('<', '_');
new_text = urlify(new_text);
new_text = new_text.replace(/#(\S*)/g, '<a href="/?tab=search-$1">#$1</a>');
new_text = new_text.replace(/@(\S*)/g, '<a href="/profile/$1">@$1</a>');
$(this).html(new_text);
if (!$(this).hasClass('clean')) {
let new_text = $(this).text();

new_text = new_text.replace('&lt;', '_');
new_text = new_text.replace('&gt;', '_');
new_text = new_text.replace('>', '_');
new_text = new_text.replace('<', '_');
new_text = urlify(new_text);
new_text = new_text.replace(/#(\S*)/g, '<a href="/?tab=search-$1">#$1</a>');
new_text = new_text.replace(/@(\S*)/g, '<a href="/profile/$1">@$1</a>');
$(this).html(new_text);
$(this).addClass('clean');
}
});

// inserts links into the text where there are URLS detected
Expand Down
10 changes: 5 additions & 5 deletions app/assets/v2/js/pages/tribe-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,16 @@ $('[data-createbountyrequest]').on('click', function() {
_alert('Bounty Request has been created');
location.reload();
} else {
_alert('Error creating bounty request. Try again later', 'error');
_alert(`Error creating bounty request as ${response.message}`, 'error');
console.error(response.message);
}

}).fail(function(error) {
_alert('Error creating bounty request. Try again later', 'error');
_alert(`Error creating bounty request as ${error}`, 'error');
console.error('error: unable to creating bounty request', error);
});
}).catch(error => {
_alert(`Error creating bounty request. Try again later. ${error}`, 'error');
_alert(`Error creating bounty request as ${error}`, 'error');
console.error('error: unable to creating bounty request', error);
});
});
Expand All @@ -238,12 +238,12 @@ $('[data-cancelbountyrequest]').on('click', function() {
_alert('Bounty Request has been rejected');
$(`#${bounty_request_id}`).hide();
} else {
_alert('Error rejecting bounty request. Try again later', 'error');
_alert(`Error rejecting bounty request as ${response.message}`, 'error');
console.error(response.message);
}

}).fail(function(error) {
_alert('Error rejecting bounty request. Try again later', 'error');
_alert(`Error rejecting bounty request. ${error}`, 'error');
console.error('error: unable to reject bounty request', error);
});
});
33 changes: 21 additions & 12 deletions app/assets/v2/js/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ $(document).ready(function() {
$('#textarea').focus();
}

document.is_shift = false;
// handle shift button
$('body').on('keyup', '#textarea', function(e) {
if (e.keyCode == 16) {
document.is_shift = false;
}
});
// handle shift button
$('body').on('keydown', '#textarea', function(e) {
if (e.keyCode == 16) {
document.is_shift = true;
}
});

$('body').on('focus change paste keyup blur', '#textarea', function(e) {

// enforce a max length
Expand All @@ -88,19 +102,11 @@ $(document).ready(function() {
if ($(this).val().trim().length > max_len) {
e.preventDefault();
$(this).addClass('red');
var old_val = $(this).val();

setTimeout(function() {
$('#textarea').val(old_val.slice(0, max_len));
}, 20);
} else {
$(this).removeClass('red');
}

// enable post via enter button
if ($(this).val().trim().length > 4) {
$('#btn_post').attr('disabled', true);
} else if ($(this).val().trim().length > 4) {
$('#btn_post').attr('disabled', false);
if ($('#textarea').is(':focus') && (e.keyCode == 13)) {
$(this).removeClass('red');
if ($('#textarea').is(':focus') && !document.is_shift && (e.keyCode == 13)) {
submitStatusUpdate();
e.preventDefault();
}
Expand All @@ -110,6 +116,9 @@ $(document).ready(function() {
});

function submitStatusUpdate() {
if ($('#btn_post').is(':disabled')) {
return;
}
const data = new FormData();
const message = $('#textarea');
const ask = $('.activity_type_selector .active input').val();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
<label class="filter-label" for="any_org">All</label>
</div>
{% for org in orgs %}
<div class="form__radio option {{org.org_name}}">
<input name="org" id="{{org.org_name}}" type="radio" value="{{org.org_name}}" val-ui="Turing-Chain">
<label class="filter-label" for="{{org.org_name}}">
<div class="form__radio option {{org.display_name}}">
<input name="org" id="{{org.display_name}}" type="radio" value="{{org.org_name}}">
<label class="filter-label" for="{{org.display_name}}">
<img src="{{org.avatar_url}}" class="rounded-circle" width="24" height="24" alt="{{org.display_name}}"> {{org.display_name}}
</label>
</div>
Expand Down
2 changes: 2 additions & 0 deletions app/grants/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def is_grant_team_member(grant, profile):
profile (dashboard.models.Profile): The current user's profile.
"""
if not profile:
return False
is_team_member = False
if grant.admin_profile == profile:
is_team_member = True
Expand Down
12 changes: 12 additions & 0 deletions app/marketing/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,18 @@ def comment_email(comment):
finally:
pass
translation.activate(cur_language)
print(f"sent comment email to {len(to_emails)}")

import re
from dashboard.models import Profile
username_pattern = re.compile(r'@(\S+)')
mentioned_usernames = re.findall(username_pattern, comment.comment)
emails = Profile.objects.filter(handle__in=mentioned_usernames).values_list('email', flat=True)
mentioned_emails = set(emails)
# Don't send emails again to users who already received a comment email
deduped_emails = mentioned_emails.difference(to_emails)
print(f"sent mention email to {len(deduped_emails)}")
mention_email(comment, deduped_emails)


def mention_email(post, to_emails):
Expand Down
23 changes: 23 additions & 0 deletions app/marketing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""
from __future__ import unicode_literals

import csv
import json
import logging

Expand Down Expand Up @@ -565,6 +566,28 @@ def account_settings(request):
profile.preferred_payout_address = eth_address
profile.save()
msg = _('Updated your Address')
elif request.POST.get('export', False):
export_type = request.POST.get('export_type', False)

response = HttpResponse(content_type='text/csv')
name = f"gitcoin_{export_type}_{timezone.now().strftime('%Y_%m_%dT%H_00_00')}"
response['Content-Disposition'] = f'attachment; filename="{name}.csv"'

writer = csv.writer(response)
writer.writerow(['id', 'date', 'From', 'To', 'Type', 'Value In USD', 'url'])
profile = request.user.profile
earnings = profile.earnings if export_type == 'earnings' else profile.sent_earnings
earnings = earnings.all().order_by('-created_on')
for earning in earnings:
writer.writerow([earning.pk,
earning.created_on.strftime("%Y-%m-%dT%H:00:00"),
earning.from_profile.handle if earning.from_profile else '*',
earning.to_profile.handle if earning.to_profile else '*',
earning.source_type.model_class(),
earning.value_usd,
earning.url])

return response
elif request.POST.get('disconnect', False):
profile.github_access_token = ''
profile = record_form_submission(request, profile, 'account-disconnect')
Expand Down
2 changes: 1 addition & 1 deletion app/quests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def editquest(request, pk=None):
answers = package.getlist('answer[]',[])
answer_correct = package.getlist('answer_correct[]',[])
seconds_to_respond = package.getlist('seconds_to_respond[]',[])
points = abs(int(package.get('points')))
points = abs(int(float(package.get('points'))))

# continue building questions object
for i in range(0, len(seconds_to_respond)):
Expand Down
4 changes: 3 additions & 1 deletion app/retail/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,11 @@ def render_comment(to_email, comment):


def render_mention(to_email, post):
from dashboard.models import Activity
params = {
'post': post,
'email_type': 'mention',
'is_activity': isinstance(post, Activity),
'subscriber': get_or_save_email_subscriber(to_email, 'internal'),
}

Expand Down Expand Up @@ -1268,7 +1270,7 @@ def comment(request):

@staff_member_required
def mention(request):
from townsquare.models import Activity
from dashboard.models import Activity
response_html, _ = render_mention(settings.CONTACT_EMAIL, Activity.objects.last())
return HttpResponse(response_html)

Expand Down
2 changes: 1 addition & 1 deletion app/retail/templates/emails/mention.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1>💬@{{post.profile.handle}} {% trans "mentioned you in a post" %} 💬</h1>
<a href="{{post.profile.url}}">@{{post.profile.handle}}</a> mentioned you in a post. This is what the post looks like:

<pre>
{% if isinstance(post, Activity) %}
{% if is_activity %}
{{post.metadata.title}}
{% else %}
- @{{post.profile.handle}} ({{post.created_on | naturaltime}}): {{post.comment}}
Expand Down
27 changes: 27 additions & 0 deletions app/retail/templates/settings/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,33 @@ <h5>{% trans "ETH Account Preferences" %}</h5>
<input class='button button--primary' type='submit' name='submit' value="{% trans "Save" %}">
</form>
<div class="col-md-8 m-auto">
{% if is_alpha_tester %}
<div class="form-group">
<h4 class="font-title mb-4 text-left">{% trans "Account Financials -- ALPHA" %}</h4>
</div>
<div class="form-group mb-4">
<div class="major_button_container">
<form id="export" method="POST" action="{% url 'account_settings' %}">
{% csrf_token %}
<input type="hidden" name="export_type" value="earnings">
<input type="submit" class="button button--primary" name="export" value="Export">
</form>
<h5 class="font-subheader">{% trans "Export Earnings" %} ({{profile.earnings.count}})</h5>
<p class="font-body">{% trans "Export all of your earnings for @" %}{{ github_handle }}</p>
</div>
</div>
<div class="form-group mb-4">
<div class="major_button_container">
<form id="export" method="POST" action="{% url 'account_settings' %}">
{% csrf_token %}
<input type="hidden" name="export_type" value="sent">
<input type="submit" class="button button--primary" name="export" value="Export">
</form>
<h5 class="font-subheader">{% trans "Export Spending" %} ({{profile.sent_earnings.count}})</h5>
<p class="font-body">{% trans "Export all of your spending for @" %}{{ github_handle }}</p>
</div>
</div>
{% endif %}
<h4 class="font-title mb-4 text-left">{% trans "Profile Photo" %}</h4>
<div class="profile-avatar row mx-0 px-0 major_button_container">
<div class="col-12 col-md-5 pl-0 pr-0 text-center">
Expand Down
10 changes: 2 additions & 8 deletions app/townsquare/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from dashboard.models import Activity, HackathonEvent, Profile, get_my_earnings_counter_profiles, get_my_grants
from kudos.models import Token
from marketing.mails import comment_email, mention_email, new_action_request
from marketing.mails import comment_email, new_action_request
from ratelimit.decorators import ratelimit

from .models import Announcement, Comment, Flag, Like, Offer, OfferAction
Expand Down Expand Up @@ -290,15 +290,9 @@ def api(request, activity_id):
# comment request
elif request.POST.get('method') == 'comment':
comment = request.POST.get('comment')
title = request.POST.get('comment')
comment = Comment.objects.create(profile=request.user.profile, activity=activity, comment=comment)

username_pattern = re.compile(r'@(\S+)')
mentioned_usernames = re.findall(username_pattern, title)
mentioned_emails = set(Profile.objects.filter(handle__in=mentioned_usernames).values_list('email', flat=True))
# Don't send emails again to users who already received a comment email
deduped_emails = mentioned_emails.difference(to_emails)
mention_email(comment, deduped_emails)

return JsonResponse(response)


Expand Down

0 comments on commit 49f5ebc

Please sign in to comment.