Skip to content

Commit

Permalink
joined activity
Browse files Browse the repository at this point in the history
  • Loading branch information
owocki committed Jul 21, 2019
1 parent d171e40 commit 1f1d9b8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
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 @@ -2804,14 +2805,7 @@ def get_various_activities(self, network='mainnet'):
Q(tip__github_url__istartswith=url)
)

all_activities = all_activities.filter(
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 @@ -2903,7 +2897,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: 1 addition & 1 deletion app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1971,7 +1971,7 @@ def profile(request, handle):
if page:
page = int(page)
activity_type = request.GET.get('a', '')
all_activities = profile.get_various_activities(network)
all_activities = profile.get_various_activities()
paginator = Paginator(profile_filter_activities(all_activities, activity_type), 10)

if page > paginator.num_pages:
Expand Down
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

0 comments on commit 1f1d9b8

Please sign in to comment.