From af89d3070627c214d94b4d77919320f09c67037d Mon Sep 17 00:00:00 2001 From: Kevin Owocki Date: Wed, 5 Feb 2020 06:54:23 -0700 Subject: [PATCH] fixes kudos foreign keys (#5828) --- app/dashboard/admin.py | 2 +- .../migrations/0077_remove_activity_kudos.py | 17 +++++++++++++ .../migrations/0078_auto_20200117_1755.py | 25 +++++++++++++++++++ app/dashboard/models.py | 10 ++++++-- app/kudos/views.py | 4 ++- app/retail/templates/shared/activity.html | 4 +-- 6 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 app/dashboard/migrations/0077_remove_activity_kudos.py create mode 100644 app/dashboard/migrations/0078_auto_20200117_1755.py diff --git a/app/dashboard/admin.py b/app/dashboard/admin.py index 0256b3f25eb..8896f8e3075 100644 --- a/app/dashboard/admin.py +++ b/app/dashboard/admin.py @@ -90,7 +90,7 @@ class ToolAdmin(admin.ModelAdmin): class ActivityAdmin(admin.ModelAdmin): ordering = ['-id'] - raw_id_fields = ['bounty', 'profile', 'tip', 'kudos', 'grant', 'subscription', 'other_profile'] + raw_id_fields = ['bounty', 'profile', 'tip', 'kudos', 'grant', 'subscription', 'other_profile', 'kudos_transfer'] search_fields = ['metadata', 'activity_type', 'profile__handle'] def response_change(self, request, obj): diff --git a/app/dashboard/migrations/0077_remove_activity_kudos.py b/app/dashboard/migrations/0077_remove_activity_kudos.py new file mode 100644 index 00000000000..5eaba8c56e9 --- /dev/null +++ b/app/dashboard/migrations/0077_remove_activity_kudos.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2.4 on 2020-01-17 17:55 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('dashboard', '0076_merge_20200117_1700'), + ] + + operations = [ + migrations.RemoveField( + model_name='activity', + name='kudos', + ), + ] diff --git a/app/dashboard/migrations/0078_auto_20200117_1755.py b/app/dashboard/migrations/0078_auto_20200117_1755.py new file mode 100644 index 00000000000..954e368d8ac --- /dev/null +++ b/app/dashboard/migrations/0078_auto_20200117_1755.py @@ -0,0 +1,25 @@ +# Generated by Django 2.2.4 on 2020-01-17 17:55 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('kudos', '0011_auto_20191106_0237'), + ('dashboard', '0077_remove_activity_kudos'), + ] + + operations = [ + migrations.AddField( + model_name='activity', + name='kudos', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='activities', to='kudos.Token'), + ), + migrations.AddField( + model_name='activity', + name='kudos_transfer', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='activities', to='kudos.KudosTransfer'), + ), + ] diff --git a/app/dashboard/models.py b/app/dashboard/models.py index 3c82b7d3ae4..91a93cade9d 100644 --- a/app/dashboard/models.py +++ b/app/dashboard/models.py @@ -2043,12 +2043,18 @@ class Activity(SuperModel): blank=True, null=True ) - kudos = models.ForeignKey( + kudos_transfer = models.ForeignKey( 'kudos.KudosTransfer', related_name='activities', on_delete=models.CASCADE, blank=True, null=True ) + kudos = models.ForeignKey( + 'kudos.Token', + related_name='activities', + on_delete=models.CASCADE, + blank=True, null=True + ) grant = models.ForeignKey( 'grants.Grant', related_name='activities', @@ -2196,7 +2202,7 @@ def view_props(self): # in a later release, it couild be refactored such that its just contained in the above code block ^^. activity['icon'] = icons.get(self.activity_type, 'fa-check-circle') if activity.get('kudos'): - activity['kudos_data'] = Token.objects.get(pk=self.kudos.kudos_token_cloned_from_id) + activity['kudos_data'] = self.kudos obj = self.metadata if 'new_bounty' in self.metadata: obj = self.metadata['new_bounty'] diff --git a/app/kudos/views.py b/app/kudos/views.py index d7522f6a2da..df7fc2f80a1 100644 --- a/app/kudos/views.py +++ b/app/kudos/views.py @@ -477,6 +477,7 @@ def record_kudos_email_activity(kudos_transfer, github_handle, event_name): kwargs = { 'activity_type': event_name, 'kudos_transfer': kudos_transfer, + 'kudos': kudos_transfer.kudos_token_cloned_from, 'metadata': { 'amount': str(kudos_transfer.amount), 'token_name': kudos_transfer.tokenName, @@ -512,7 +513,8 @@ def record_kudos_activity(kudos_transfer, github_handle, event_name): github_handle = github_handle.replace('@', '') kwargs = { 'activity_type': event_name, - 'kudos': kudos_transfer, + 'kudos_transfer': kudos_transfer, + 'kudos': kudos_transfer.kudos_token_cloned_from, 'metadata': { 'amount': str(kudos_transfer.amount), 'token_name': kudos_transfer.tokenName, diff --git a/app/retail/templates/shared/activity.html b/app/retail/templates/shared/activity.html index 758ced5a3ef..a3a1bc413ca 100644 --- a/app/retail/templates/shared/activity.html +++ b/app/retail/templates/shared/activity.html @@ -242,8 +242,8 @@ {% if row.profile.handle == github_handle %} {% elif row.kudos %} - - + + {% static row.kudos_data.name %} {% elif row.activity_type == 'leaderboard_rank' %}