Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grant contributions in profile (#3316) #3859

Merged
merged 26 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1096cce
Grant contribution activity (#3316)
Feb 27, 2019
c54d417
Grant activity on profile (#3316)
Mar 7, 2019
b4d590a
Update app/grants/views.py
Mar 7, 2019
ddb5338
owocki's requested changes (#3316)
Mar 8, 2019
c25f034
Merge branch 'master' of github.com:e18r/web
Mar 8, 2019
a271bd0
owocki's requested changes 2 (#3316)
Mar 10, 2019
c3e27e8
Show grant-related activity in the /activity page (#3316)
Mar 13, 2019
32a59d0
Fixed icon bug (#3316)
Mar 13, 2019
6d90018
Record grant lifecycle activities (#3316)
Mar 13, 2019
caeee0f
Show grant lifecycle activities in profile (#3316)
Mar 13, 2019
bbe8096
Show new activities in /activity page (#3316)
Mar 13, 2019
c527307
Merge branch 'master' of https://github.com/gitcoinco/web
Mar 15, 2019
d92d575
Merge latest Gitcoinco changes into my local repo
Mar 19, 2019
3428359
Changes requested by @thelostone-mc (#3316)
Mar 19, 2019
ee5fe57
Undo change from `far` to `fa` (requested by @thelostone-mc) (#3316)
Mar 24, 2019
be021fe
Merge branch 'master' of https://github.com/gitcoinco/web
Mar 25, 2019
a83ef10
Merge branch 'master' of https://github.com/gitcoinco/web
Mar 26, 2019
6b94906
Solved migration conflict (requested by @danlipert) (#3316)
Mar 27, 2019
384a2c9
Merge branch 'master' into master
thelostone-mc Apr 6, 2019
2e13a32
Merge branch 'master' of https://github.com/gitcoinco/web
Apr 16, 2019
c1c0b58
Merge branch 'master' of https://github.com/gitcoinco/web
Apr 16, 2019
107aa54
Merge branch 'master' of https://github.com/gitcoinco/web
Apr 18, 2019
36aca5b
[#3316] Solved conflicting migrations
Apr 18, 2019
d303030
Merge branch 'master' of github.com:e18r/web
Apr 18, 2019
7e38f62
Merge branch 'master' into master
danlipert Apr 24, 2019
9b388f7
Merge branch 'master' into master
danlipert Apr 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/dashboard/migrations/0029_grant_activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.1.7 on 2019-03-27 00:10

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('grants', '0019_auto_20190412_0321'),
('dashboard', '0028_profile_actions_count'),
]

operations = [
migrations.AddField(
model_name='activity',
name='grant',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='activities', to='grants.Grant'),
),
migrations.AddField(
model_name='activity',
name='subscription',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='activities', to='grants.Subscription'),
),
]
48 changes: 36 additions & 12 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,7 @@ class Activity(SuperModel):
('update_grant', 'Updated Grant'),
('killed_grant', 'Cancelled Grant'),
('new_grant_contribution', 'Contributed to Grant'),
('new_grant_subscription', 'Subscribed to Grant'),
e18r marked this conversation as resolved.
Show resolved Hide resolved
('killed_grant_contribution', 'Cancelled Grant Contribution'),
('new_milestone', 'New Milestone'),
('update_milestone', 'Updated Milestone'),
Expand Down Expand Up @@ -1623,6 +1624,18 @@ class Activity(SuperModel):
on_delete=models.CASCADE,
blank=True, null=True
)
grant = models.ForeignKey(
'grants.Grant',
related_name='activities',
on_delete=models.CASCADE,
blank=True, null=True
)
subscription = models.ForeignKey(
e18r marked this conversation as resolved.
Show resolved Hide resolved
'grants.Subscription',
related_name='activities',
on_delete=models.CASCADE,
blank=True, null=True
)
created = models.DateTimeField(auto_now_add=True, blank=True, null=True, db_index=True)
activity_type = models.CharField(max_length=50, choices=ACTIVITY_TYPES, blank=True, db_index=True)
metadata = JSONField(default=dict)
Expand Down Expand Up @@ -1663,6 +1676,12 @@ def view_props(self):
'new_bounty': 'fa-money-bill-alt',
'work_done': 'fa-check-circle',
'new_kudos': 'fa-thumbs-up',
'new_grant': 'fa-envelope',
'update_grant': 'fa-edit',
'killed_grant': 'fa-trash',
'new_grant_contribution': 'fa-coins',
'new_grant_subscription': 'fa-calendar-check',
'killed_grant_contribution': 'fa-calendar-times',
}

# load up this data package with all of the information in the already existing objects
Expand Down Expand Up @@ -1692,12 +1711,13 @@ def view_props(self):
obj = self.metadata['new_bounty']
activity['title'] = obj.get('title', '')
if 'id' in obj:
activity['bounty_url'] = Bounty.objects.get(pk=obj['id']).get_relative_url()
if activity.get('title'):
activity['urled_title'] = f'<a href="{activity["bounty_url"]}">{activity["title"]}</a>'
else:
activity['urled_title'] = activity.get('title')
activity['humanized_activity_type'] = self.humanized_activity_type
if 'category' not in obj or obj['category'] == 'bounty': # backwards-compatible for category-lacking metadata
e18r marked this conversation as resolved.
Show resolved Hide resolved
activity['bounty_url'] = Bounty.objects.get(pk=obj['id']).get_relative_url()
if activity.get('title'):
activity['urled_title'] = f'<a href="{activity["bounty_url"]}">{activity["title"]}</a>'
else:
activity['urled_title'] = activity.get('title')
activity['humanized_activity_type'] = self.humanized_activity_type
if 'value_in_usdt_now' in obj:
activity['value_in_usdt_now'] = obj['value_in_usdt_now']
if 'token_name' in obj:
Expand Down Expand Up @@ -2601,8 +2621,8 @@ def get_funded_bounties(self, network='mainnet'):
)
return funded_bounties

def get_bounty_and_tip_activities(self, network='mainnet'):
"""Get bounty and tip related activities for this profile.
def get_various_activities(self, network='mainnet'):
"""Get bounty, tip and grant related activities for this profile.

Args:
network (str): The network to query results for.
Expand All @@ -2618,13 +2638,17 @@ def get_bounty_and_tip_activities(self, network='mainnet'):
url = self.github_url
all_activities = Activity.objects.filter(
Q(bounty__github_url__startswith=url) |
Q(tip__github_url__startswith=url),
Q(tip__github_url__startswith=url) |
Q(grant__isnull=False) |
Q(subscription__isnull=False)
)

all_activities = all_activities.filter(
Q(bounty__network=network) |
Q(tip__network=network),
).select_related('bounty', 'tip').all().order_by('-created')
Q(tip__network=network) |
Q(grant__network=network) |
Q(subscription__network=network)
).select_related('bounty', 'tip', 'grant', 'subscription').all().order_by('-created')

return all_activities

Expand Down Expand Up @@ -2713,7 +2737,7 @@ def to_dict(self, activities=True, leaderboards=True, network=None, tips=True):
}

if activities:
params['activities'] = self.get_bounty_and_tip_activities(network=network)
params['activities'] = self.get_various_activities(network=network)

if tips:
params['tips'] = self.tips.filter(**query_kwargs).send_happy_path()
Expand Down
4 changes: 4 additions & 0 deletions app/dashboard/templates/profiles/profile_activities.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
{% include "shared/profile_activities_tip.html" with tip=activity.tip %}
{% elif activity.bounty %}
{% include "shared/profile_activities_bounty.html" %}
{% elif activity.grant %}
{% include "shared/profile_activities_grant.html" %}
{% elif activity.subscription %}
{% include "shared/profile_activities_subscription.html" %}
{% endif %}
{% endfor %}
63 changes: 63 additions & 0 deletions app/dashboard/templates/shared/profile_activities_grant.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{% load i18n humanize %}
<a class="row result bounty_row {{ activity.grant.network }}" target="_blank"
{% if activity.grant.url %} href="{{ activity.grant.url }}"
{% elif activity.grant.reference_url %} href="{{ activity.grant.reference_url }}"
{% endif %}>
<div class="avatar-container col-1 justify-content-center special_tag hide_min_viewport">
{% if activity.grant.logo %}
<img class="avatar" src="{{ activity.grant.logo.url }}">
{% else %}
<img class="avatar" src="{% url 'org_avatar' activity.grant.admin_profile.handle %}">
{% endif %}
</div>
<div class="col-12 col-md-7 d-flex flex-column">
<div class="bounty-detail">
<div class="title font-subheader">
{{ activity.grant.title }}
</div>

<div class="bounty-summary col-12">
<div class="info font-caption">
{{ activity.grant.amount_received | floatformat:2 }} /
{{ activity.grant.amount_goal | floatformat:2 }}
{{ activity.grant.token_symbol }}
&bull; {{ activity.created | naturaltime }}
</div>
</div>
</div>
</div>
<div class="col-12 col-md-4 tags fixed font-caption align-items-center">
{% if activity.activity_type == 'new_grant' %}
<div class="tag success">
<p>
<span>{% trans "Created " %}</span>
</p>
</div>
{% elif activity.activity_type == 'update_grant' %}
<div class="tag success">
<p>
<span>{% trans "Updated " %}</span>
</p>
</div>
{% elif activity.activity_type == 'killed_grant' %}
<div class="tag warning">
<p>
<span>{% trans "Cancelled " %}</span>
</p>
</div>
{% else %}
<div class="tag in-progress">
<p>
<span>{{ activity.i18n_name }}</span>
</p>
</div>
{% endif %}
{% if activity.grant.network != 'mainnet' %}
<div class="tag network_warning">
<p>
<span>{{ activity.grant.network }}</span>
</p>
</div>
{% endif %}
</div>
</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{% load i18n humanize %}
<a class="row result bounty_row {{ activity.subscription.network }}" target="_blank"
{% if activity.subscription.grant.url %} href="{{ activity.subscription.grant.url }}"
{% elif activity.subscription.grant.reference_url %} href="{{ activity.subscription.grant.reference_url }}"
{% endif %}>
<div class="avatar-container col-1 justify-content-center special_tag hide_min_viewport">
{% if activity.subscription.grant.logo %}
<img class="avatar" src="{{ activity.subscription.grant.logo.url }}">
{% else %}
<img class="avatar" src="{% url 'org_avatar' activity.subscription.grant.admin_profile.handle %}">
{% endif %}
</div>
<div class="col-12 col-md-7 d-flex flex-column">
<div class="bounty-detail">
<div class="title font-subheader">
{{ activity.subscription.grant.title }}
</div>

<div class="bounty-summary col-12">
<div class="info font-caption">
{{ activity.subscription.grant.amount_received | floatformat:2 }} /
{{ activity.subscription.grant.amount_goal | floatformat:2 }}
{{ activity.subscription.grant.token_symbol }}
&bull; {{ activity.created | naturaltime }}
</div>
</div>
</div>
</div>
<div class="col-12 col-md-4 tags fixed font-caption align-items-center">
{% if activity.activity_type == 'new_grant_contribution' %}
<div class="tag success">
<p>
<span>{% trans "Contributed " %}</span>
</p>
</div>
{% elif activity.activity_type == 'new_grant_subscription' %}
<div class="tag success">
<p>
<span>{% trans "Subscribed " %}</span>
</p>
</div>
{% elif activity.activity_type == 'killed_grant_contribution' %}
<div class="tag warning">
<p>
<span>{% trans "Cancelled subscription " %}</span>
</p>
</div>
{% else %}
<div class="tag in-progress">
<p>
<span>{{ activity.i18n_name }}</span>
</p>
</div>
{% endif %}
{% if activity.subscription.network != 'mainnet' %}
<div class="tag network_warning">
<p>
<span>{{ activity.subscription.network }}</span>
</p>
</div>
{% endif %}
<div class="tag token">
<p>
{{ activity.subscription.amount_per_period | floatformat:2 }}
<span>{{ activity.subscription.token_symbol }}</span>
</p>
</div>
<div class="tag usd">
<p>
{{ activity.subscription.amount_per_period_usdt | floatformat:2 }}
<span>USD</span>
</p>
</div>
</div>
</a>
8 changes: 7 additions & 1 deletion app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1737,13 +1737,19 @@ def profile(request, handle):
('work_done', _('Bounties Completed')),
('new_tip', _('Tips Sent')),
('receive_tip', _('Tips Received')),
('new_grant', _('Grants created')),
('update_grant', _('Grants updated')),
('killed_grant', _('Grants cancelled')),
('new_grant_contribution', _('Grants contributed to')),
('new_grant_subscription', _('Grants subscribed to')),
('killed_grant_contribution', _('Grants unsubscribed from')),
]
page = request.GET.get('p', None)

if page:
page = int(page)
activity_type = request.GET.get('a', '')
all_activities = profile.get_bounty_and_tip_activities()
all_activities = profile.get_various_activities()
paginator = Paginator(profile_filter_activities(all_activities, activity_type), 10)

if page > paginator.num_pages:
Expand Down
Loading