From 2044d83ed36b2fe56d31e085d43ea520763d443f Mon Sep 17 00:00:00 2001 From: Owocki Date: Thu, 1 Nov 2018 12:35:24 +0100 Subject: [PATCH 1/2] refactors kudos profile --- app/dashboard/models.py | 35 ++++++++++--------- app/dashboard/views.py | 6 +++- .../shared/kudos_card_hover_content.html | 34 ++++++++---------- .../templates/shared/kudos_card_profile.html | 28 +++++++-------- 4 files changed, 52 insertions(+), 51 deletions(-) diff --git a/app/dashboard/models.py b/app/dashboard/models.py index 9158170dfbf..0ca5f14db50 100644 --- a/app/dashboard/models.py +++ b/app/dashboard/models.py @@ -1567,25 +1567,28 @@ class Profile(SuperModel): @property def get_my_kudos(self): - from kudos.models import Token - profile = self - return Token.objects.select_related('kudos_transfer', 'contract').filter( - Q(owner_address__iexact=profile.preferred_payout_address) | - Q(kudos_token_cloned_from__recipient_profile=profile) | - Q(kudos_transfer__recipient_profile=profile), - contract__network=settings.KUDOS_NETWORK - ).distinct('id') + from kudos.models import KudosTransfer + kt_owner_address = KudosTransfer.objects.filter(kudos_token_cloned_from__owner_address__iexact=self.preferred_payout_address) + kt_profile = KudosTransfer.objects.filter(recipient_profile=self) + + kudos_transfers = kt_profile | kt_owner_address + kudos_transfers = kudos_transfers.filter(kudos_token_cloned_from__contract__network=settings.KUDOS_NETWORK) + #kudos_transfers = kudos_transfers.distinct('kudos_token_cloned_from_id') # remove this line IFF we ever move to showing multiple kudos transfers on a profile + + return kudos_transfers + @property def get_sent_kudos(self): - from kudos.models import Token - profile = self - return Token.objects.select_related('kudos_transfer', 'contract').filter( - Q(kudos_token_cloned_from__from_address__iexact=profile.preferred_payout_address) | - Q(kudos_token_cloned_from__sender_profile=profile) | - Q(kudos_transfer__sender_profile=profile), - contract__network=settings.KUDOS_NETWORK, - ).distinct('id') + from kudos.models import KudosTransfer + kt_address = KudosTransfer.objects.filter(from_address__iexact=self.preferred_payout_address) + kt_sender_profile = KudosTransfer.objects.filter(sender_profile=self) + + kudos_transfers = kt_address | kt_sender_profile + kudos_transfers = kudos_transfers.filter(kudos_token_cloned_from__contract__network=settings.KUDOS_NETWORK) + #kudos_transfers = kudos_transfers.distinct('kudos_token_cloned_from_id') # remove this line IFF we ever move to showing multiple kudos transfers on a profile + + return kudos_transfers @property diff --git a/app/dashboard/views.py b/app/dashboard/views.py index b2713f61ab4..5c30f94e544 100644 --- a/app/dashboard/views.py +++ b/app/dashboard/views.py @@ -1209,6 +1209,7 @@ def lazy_load_kudos(request): limit = int(request.GET.get('limit', 8)) handle = request.POST.get('handle') profile = Profile.objects.get(handle=handle) + if datarequest == 'mykudos': key = 'kudos' context[key] = profile.get_my_kudos.order_by('id', order_by) @@ -1219,7 +1220,10 @@ def lazy_load_kudos(request): paginator = Paginator(context[key], limit) kudos = paginator.get_page(page) - kudos_html = loader.render_to_string('shared/kudos_card_profile.html', {'kudos': kudos}) + html_context = {} + html_context[key] = kudos + html_context['kudos_data'] = key + kudos_html = loader.render_to_string('shared/kudos_card_profile.html', html_context) return JsonResponse({'kudos_html': kudos_html, 'has_next': kudos.has_next()}) diff --git a/app/kudos/templates/shared/kudos_card_hover_content.html b/app/kudos/templates/shared/kudos_card_hover_content.html index 33a81084989..ec513d34f29 100644 --- a/app/kudos/templates/shared/kudos_card_hover_content.html +++ b/app/kudos/templates/shared/kudos_card_hover_content.html @@ -16,26 +16,20 @@ {% endcomment %} {% load i18n static kudos_extras %} {% load humanize %} -{% if kudo.kudos_token_cloned_from %} - {% for kt in kudo.kudos_token_cloned_from.all %} - {% if countercounterparty == 'from_username' and kt.from_username.strip == profile.handle.strip or countercounterparty == 'username' and kt.username.strip|slice:'1:' == profile.handle.strip %} -

Sent {{relation}} +

Sent {{relation}} - {% if counterparty == 'username' %} - {{kt.username|slice:"1:"}} - {% else %} - {{kt.from_username}} - {% endif %} + {% if relation == 'from' %} + {{kt.username}} + {% else %} + {{kt.from_username}} + {% endif %} - {{kt.created_on|naturaltime}}

-

- {{ kt.txid|humanize_address }} -

- {% if kt.comments_public %} - {% trans "Comment:" %} -

{{kt.comments_public}}

- {% endif %} - {% endif %} - {% endfor %} -{% endif %} +{{kt.created_on|naturaltime}}

+

+ {{ kt.txid|humanize_address }} +

+{% if kt.comments_public %} + {% trans "Comment:" %} +

{{kt.comments_public}}

+ {% endif %} diff --git a/app/kudos/templates/shared/kudos_card_profile.html b/app/kudos/templates/shared/kudos_card_profile.html index 1ebcf6e3a94..52631223a41 100644 --- a/app/kudos/templates/shared/kudos_card_profile.html +++ b/app/kudos/templates/shared/kudos_card_profile.html @@ -17,38 +17,38 @@ {% load i18n static kudos_extras %} {% load humanize %} {% if kudos_data == 'sent_kudos' %} - {% for kudo in sent_kudos|slice:":8" %} + {% for kt in sent_kudos|slice:":8" %}
- - {{ kudo.name|humanize_name }} + + {{ kt.kudos_token_cloned_from.name|humanize_name }}
-
{{ kudo.name|humanize_name }}
- {{ kudo.description|truncatechars:60 }} +
{{ kt.kudos_token_cloned_from.name|humanize_name }}
+ {{ kt.kudos_token_cloned_from.description|truncatechars:60 }}
- {{ kudo.name|humanize_name }} - {% include 'shared/kudos_card_hover_content.html' with relation='to' counterparty='username' countercounterparty='from_username' %} + {{ kt.kudos_token_cloned_from.name|humanize_name }} + {% include 'shared/kudos_card_hover_content.html' with relation='to' %}
{% endfor %} {% else %} - {% for kudo in kudos|slice:":8" %} + {% for kt in kudos|slice:":8" %}
- - {{ kudo.name|humanize_name }} + + {{ kt.kudos_token_cloned_from.name|humanize_name }}
-
{{ kudo.name|humanize_name }}
- {{ kudo.description|truncatechars:60 }} +
{{ kt.kudos_token_cloned_from.name|humanize_name }}
+ {{ kt.kudos_token_cloned_from.description|truncatechars:60 }}
- {{ kudo.name|humanize_name }} + {{ kt.kudos_token_cloned_from.name|humanize_name }} - {% include 'shared/kudos_card_hover_content.html' with relation='from' counterparty='from_username' countercounterparty='username' %} + {% include 'shared/kudos_card_hover_content.html' with relation='from' %}
From 48eb2303ed4664fadd23240b9702ed7f4c7dd71c Mon Sep 17 00:00:00 2001 From: Owocki Date: Thu, 1 Nov 2018 12:38:19 +0100 Subject: [PATCH 2/2] distinct --- app/dashboard/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/dashboard/models.py b/app/dashboard/models.py index f88e8315e9e..9862a66da9a 100644 --- a/app/dashboard/models.py +++ b/app/dashboard/models.py @@ -1573,7 +1573,7 @@ def get_my_kudos(self): kudos_transfers = kt_profile | kt_owner_address kudos_transfers = kudos_transfers.filter(kudos_token_cloned_from__contract__network=settings.KUDOS_NETWORK) - #kudos_transfers = kudos_transfers.distinct('kudos_token_cloned_from_id') # remove this line IFF we ever move to showing multiple kudos transfers on a profile + kudos_transfers = kudos_transfers.distinct('id') # remove this line IFF we ever move to showing multiple kudos transfers on a profile return kudos_transfers @@ -1586,7 +1586,7 @@ def get_sent_kudos(self): kudos_transfers = kt_address | kt_sender_profile kudos_transfers = kudos_transfers.filter(kudos_token_cloned_from__contract__network=settings.KUDOS_NETWORK) - #kudos_transfers = kudos_transfers.distinct('kudos_token_cloned_from_id') # remove this line IFF we ever move to showing multiple kudos transfers on a profile + kudos_transfers = kudos_transfers.distinct('id') # remove this line IFF we ever move to showing multiple kudos transfers on a profile return kudos_transfers