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

show 'joined Gitcoin' as an item on /activity #4836

Merged
merged 1 commit into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion app/app/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from django.utils import timezone

from app.utils import get_location_from_ip
from dashboard.models import Tip, UserAction
from dashboard.models import Activity, Tip, UserAction
from dashboard.utils import _get_utm_from_cookie
from kudos.models import KudosTransfer
from retail.helpers import get_ip
Expand Down Expand Up @@ -51,9 +51,12 @@ def preprocess(request):
email_subs = profile.email_subscriptions if profile else None
email_key = email_subs.first().priv if user_is_authenticated and email_subs and email_subs.exists() else ''
if user_is_authenticated and profile and profile.pk:
# what actions to take?
record_join = not profile.last_visit
record_visit = not profile.last_visit or profile.last_visit < (
timezone.now() - timezone.timedelta(seconds=RECORD_VISIT_EVERY_N_SECONDS)
)

if record_visit:
ip_address = get_ip(request)
profile.last_visit = timezone.now()
Expand All @@ -68,6 +71,10 @@ def preprocess(request):
utm=_get_utm_from_cookie(request),
metadata=metadata,
)

if record_join:
Activity.objects.create(profile=profile, activity_type='joined')

context = {
'STATIC_URL': settings.STATIC_URL,
'MEDIA_URL': settings.MEDIA_URL,
Expand Down
14 changes: 4 additions & 10 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,7 @@ class Activity(SuperModel):
('new_milestone', 'New Milestone'),
('update_milestone', 'Updated Milestone'),
('new_kudos', 'New Kudos'),
('joined', 'Joined Gitcoin'),
]

profile = models.ForeignKey(
Expand Down Expand Up @@ -2783,7 +2784,7 @@ def get_funded_bounties(self, network='mainnet'):
)
return funded_bounties

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

Args:
Expand All @@ -2805,14 +2806,7 @@ def get_various_activities(self, network='mainnet'):
Q(tip__github_url__istartswith=url)
)

all_activities = all_activities.filter(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is as much for performance / simplicity as it is for the 'joined' activity

Q(bounty__network=network) |
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
return all_activities.all().order_by('-created')

def activate_avatar(self, avatar_pk):
self.avatar_baseavatar_related.update(active=False)
Expand Down Expand Up @@ -2904,7 +2898,7 @@ def to_dict(self, activities=True, leaderboards=True, network=None, tips=True):
}

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

if tips:
params['tips'] = self.tips.filter(**query_kwargs).send_happy_path()
Expand Down
2 changes: 2 additions & 0 deletions app/dashboard/templates/profiles/profile_activities.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
{% include "shared/profile_activities_grant.html" %}
{% elif activity.subscription %}
{% include "shared/profile_activities_subscription.html" %}
{% else %}
{% include "shared/profile_activities_misc.html" %}
{% endif %}
{% endfor %}
23 changes: 23 additions & 0 deletions app/dashboard/templates/shared/profile_activities_misc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% 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">
<img class="avatar" src="/dynamic/avatar/{{ activity.profile.handle }}">
</div>
<div class="col-12 col-md-7 d-flex flex-column">
<div class="bounty-detail">
<div class="title font-subheader">
</div>
{{activity.humanized_activity_type}}
<div class="bounty-summary col-12">
<div class="info font-caption">
&bull; {{ activity.created_on | naturaltime }}
</div>
</div>
</div>
</div>
<div class="col-12 col-md-4 tags fixed font-caption align-items-center">
</div>
</a>
2 changes: 2 additions & 0 deletions app/retail/templates/shared/activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
<a href="{{ row.metadata.grant_url }}" target="_blank">
{{ row.metadata.title }}
</a>
{% elif row.activity_type == 'joined' %}
{% trans "joined Gitcoin" %}
{% elif row.activity_type == 'update_grant' %}
{% trans "updated" %}
<a href="{{ row.metadata.grant_url }}" target="_blank">
Expand Down