From ce1e6f699a33c5327f652ba10d249ec59e3fb155 Mon Sep 17 00:00:00 2001 From: Owocki Date: Sun, 21 Jul 2019 12:45:44 -0600 Subject: [PATCH] joined activity --- app/app/context.py | 9 +++++++- app/dashboard/models.py | 14 ++++------- .../profiles/profile_activities.html | 2 ++ .../shared/profile_activities_misc.html | 23 +++++++++++++++++++ app/retail/templates/shared/activity.html | 2 ++ 5 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 app/dashboard/templates/shared/profile_activities_misc.html diff --git a/app/app/context.py b/app/app/context.py index b24a3c0e0e2..26b9b6aa3f3 100644 --- a/app/app/context.py +++ b/app/app/context.py @@ -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 @@ -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() @@ -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, diff --git a/app/dashboard/models.py b/app/dashboard/models.py index 876bf5d8994..366e702ea68 100644 --- a/app/dashboard/models.py +++ b/app/dashboard/models.py @@ -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( @@ -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: @@ -2805,14 +2806,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) @@ -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() diff --git a/app/dashboard/templates/profiles/profile_activities.html b/app/dashboard/templates/profiles/profile_activities.html index 7c1c81444f0..dc1e548e636 100644 --- a/app/dashboard/templates/profiles/profile_activities.html +++ b/app/dashboard/templates/profiles/profile_activities.html @@ -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 %} diff --git a/app/dashboard/templates/shared/profile_activities_misc.html b/app/dashboard/templates/shared/profile_activities_misc.html new file mode 100644 index 00000000000..32067846581 --- /dev/null +++ b/app/dashboard/templates/shared/profile_activities_misc.html @@ -0,0 +1,23 @@ +{% load i18n humanize %} + +
+ +
+
+
+
+
+ {{activity.humanized_activity_type}} +
+
+ • {{ activity.created_on | naturaltime }} +
+
+
+
+
+
+
diff --git a/app/retail/templates/shared/activity.html b/app/retail/templates/shared/activity.html index 00ac49e9b39..af0e3038d43 100644 --- a/app/retail/templates/shared/activity.html +++ b/app/retail/templates/shared/activity.html @@ -50,6 +50,8 @@ {{ row.metadata.title }} + {% elif row.activity_type == 'joined' %} + {% trans "joined Gitcoin" %} {% elif row.activity_type == 'update_grant' %} {% trans "updated" %}