Skip to content

Commit

Permalink
fixes kudos foreign keys (#5828)
Browse files Browse the repository at this point in the history
  • Loading branch information
owocki authored Feb 5, 2020
1 parent 559e665 commit af89d30
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/dashboard/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 17 additions & 0 deletions app/dashboard/migrations/0077_remove_activity_kudos.py
Original file line number Diff line number Diff line change
@@ -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',
),
]
25 changes: 25 additions & 0 deletions app/dashboard/migrations/0078_auto_20200117_1755.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
10 changes: 8 additions & 2 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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']
Expand Down
4 changes: 3 additions & 1 deletion app/kudos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions app/retail/templates/shared/activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@
{% if row.profile.handle == github_handle %}
<a href=# data-pk={{row.pk}} class="delete_activity" style="color:black; font-size: 10px;"><i class="fas fa-trash"></i></a>
{% elif row.kudos %}
<a href="/kudos/{{row.kudos.kudos_token_cloned_from_id}}/{{row.kudos.kudos_token_cloned_from.name}}">
<img class="activity_feed_kudos_image" src="{{row.kudos_data.preview_img_url }}" alt="">
<a href="{{row.kudos_data.url}}">
<img src="{% static row.kudos_data.image %}" alt="{% static row.kudos_data.name %}">
</a>
{% elif row.activity_type == 'leaderboard_rank' %}
<img src="{% static "/v2/images/kudos/money.svg" %}" alt="" class="w-100" style="max-width:100px;">
Expand Down

0 comments on commit af89d30

Please sign in to comment.