Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactors kudos data profile so the view/data/query is comprehensible #2662

Merged
merged 3 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E501 line too long (133 > 120 characters)

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('id') # remove this line IFF we ever move to showing multiple kudos transfers on a profile

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E261 at least two spaces before inline comment
E501 line too long (141 > 120 characters)


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('id') # remove this line IFF we ever move to showing multiple kudos transfers on a profile

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E261 at least two spaces before inline comment
E501 line too long (141 > 120 characters)


return kudos_transfers

@property
def is_org(self):
Expand Down
5 changes: 4 additions & 1 deletion app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,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()})


Expand Down
34 changes: 14 additions & 20 deletions app/kudos/templates/shared/kudos_card_hover_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<p>Sent {{relation}}
<p>Sent {{relation}}

{% if counterparty == 'username' %}
<a href="{% url 'profile' kt.username|slice:'1:' %}">{{kt.username|slice:"1:"}}</a>
{% else %}
<a href="{% url 'profile' kt.from_username %}">{{kt.from_username}}</a>
{% endif %}
{% if relation == 'from' %}
<a href="{% url 'profile' kt.username %}">{{kt.username}}</a>
{% else %}
<a href="{% url 'profile' kt.from_username %}">{{kt.from_username}}</a>
{% endif %}

{{kt.created_on|naturaltime}}</p>
<p>
<a href="{% if not kt == 'mainnet' %}https://{{ kt.network }}.etherscan.io/tx/{{ kt.txid }}{% else %}https://etherscan.io/tx/{{ kt.txid }}{% endif %}" target="_blank" class="d-block mb-1">{{ kt.txid|humanize_address }}</a>
</p>
{% if kt.comments_public %}
{% trans "Comment:" %}
<p>{{kt.comments_public}}</p>
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{{kt.created_on|naturaltime}}</p>
<p>
<a href="{% if not kt.network == 'mainnet' %}https://{{ kt.network }}.etherscan.io/tx/{{ kt.txid }}{% else %}https://etherscan.io/tx/{{ kt.txid }}{% endif %}" target="_blank" class="d-block mb-1">{{ kt.txid|humanize_address }}</a>
</p>
{% if kt.comments_public %}
{% trans "Comment:" %}
<p>{{kt.comments_public}}</p>
{% endif %}

28 changes: 14 additions & 14 deletions app/kudos/templates/shared/kudos_card_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -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" %}
<div class="col-xs-12 col-sm-6 col-lg-3 mb-3">
<div class="kd-card kd-extended" aria-haspopup="true" tabindex="0">
<a href="{% url 'kudos_details' kudo.id kudos.name %}" class="" title="{{ kudo.name|humanize_name }}" tabindex="0">
<img src="{% static kudo.image %}" alt="{{ kudo.name|humanize_name }}" class="img-thumbnail border-transparent kd-shadow" width="250">
<a href="{{kt.kudos_token_cloned_from.url}}" class="" title="{{ kt.kudos_token_cloned_from.name|humanize_name }}" tabindex="0">
<img src="{% static kt.kudos_token_cloned_from.image %}" alt="{{ kt.kudos_token_cloned_from.name|humanize_name }}" class="img-thumbnail border-transparent kd-shadow" width="250">
</a>
<div class="kd-content">
<div class="kd-title">{{ kudo.name|humanize_name }}</div>
{{ kudo.description|truncatechars:60 }}
<div class="kd-title">{{ kt.kudos_token_cloned_from.name|humanize_name }}</div>
{{ kt.kudos_token_cloned_from.description|truncatechars:60 }}
</div>
<div class="content-hover">
<a class="kd-title" href="{% url 'kudos_details' kudo.id kudos.name %}">{{ kudo.name|humanize_name }}</a>
{% include 'shared/kudos_card_hover_content.html' with relation='to' counterparty='username' countercounterparty='from_username' %}
<a class="kd-title" href="{% url 'kudos_details' kt.kudos_token_cloned_from.id kudos.name %}">{{ kt.kudos_token_cloned_from.name|humanize_name }}</a>
{% include 'shared/kudos_card_hover_content.html' with relation='to' %}
</div>
</div>
</div>
{% endfor %}
{% else %}
{% for kudo in kudos|slice:":8" %}
{% for kt in kudos|slice:":8" %}
<div class="col-xs-12 col-sm-6 col-lg-3 mb-3">
<div class="kd-card kd-extended" aria-haspopup="true" tabindex="0">
<a href="/kudos/{{ kudo.id }}/{{ kudo.name }}" class="" title="{{ kudo.name|humanize_name }}" tabindex="0">
<img src="{% static kudo.image %}" alt="{{ kudo.name|humanize_name }}" class="img-thumbnail border-transparent kd-shadow" width="250">
<a href="/kudos/{{ kt.kudos_token_cloned_from.id }}/{{ kt.kudos_token_cloned_from.name }}" class="" title="{{ kt.kudos_token_cloned_from.name|humanize_name }}" tabindex="0">
<img src="{% static kt.kudos_token_cloned_from.image %}" alt="{{ kt.kudos_token_cloned_from.name|humanize_name }}" class="img-thumbnail border-transparent kd-shadow" width="250">
</a>
<div class="kd-content">
<div class="kd-title">{{ kudo.name|humanize_name }}</div>
{{ kudo.description|truncatechars:60 }}
<div class="kd-title">{{ kt.kudos_token_cloned_from.name|humanize_name }}</div>
{{ kt.kudos_token_cloned_from.description|truncatechars:60 }}
</div>
<div class="content-hover">
<a class="kd-title" href="/kudos/{{ kudo.id }}/{{ kudo.name }}">{{ kudo.name|humanize_name }}</a>
<a class="kd-title" href="/kudos/{{ kt.kudos_token_cloned_from.id }}/{{ kt.kudos_token_cloned_from.name }}">{{ kt.kudos_token_cloned_from.name|humanize_name }}</a>

{% 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' %}
</div>
</div>
</div>
Expand Down