Skip to content

Commit

Permalink
fix kudos pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
octavioamu committed Sep 19, 2018
1 parent 8007fa6 commit 69f035e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 32 deletions.
4 changes: 2 additions & 2 deletions app/dashboard/templates/shared/profile_kudos.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<div class="tab-pane fade show active" id="mykudos" role="tabpanel" aria-labelledby="home-tab">
<div class="row justify-content-center">
{% include 'shared/kudos_card_profile.html' %}
{% include 'shared/kudos_card_profile.html' with kudos_data='kudos' %}
</div>
<div class="row justify-content-center">
{% if kudos.count > 8 %}
Expand All @@ -43,7 +43,7 @@

<div class="tab-pane fade" id="sentkudos" role="tabpanel" aria-labelledby="sentkudos-tab">
<div class="row justify-content-center">
{% include 'shared/kudos_card_profile.html' %}
{% include 'shared/kudos_card_profile.html' with kudos_data='sent_kudos' %}
</div>
<div class="row justify-content-center">
{% if sent_kudos.count > 8 %}
Expand Down
14 changes: 8 additions & 6 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,22 +1221,24 @@ def profile(request, handle):

def lazy_load_kudos(request):
page = request.POST.get('page')
context= {}
# with this attr from the button clicked we know if we request kudos or sent kudos
datarequest = request.POST.get('request')
# Need the current preferred address to make the query
profile = getattr(request.user, 'profile', None)
address = profile.preferred_payout_address
order_by = request.GET.get('order_by', '-modified_on')
# use Django’s pagination
# https://docs.djangoproject.com/en/dev/topics/pagination/
results_per_page = 8

if datarequest == 'mykudos':
context = Token.objects.filter(owner_address=to_checksum_address(address)).order_by(order_by)
context['kudos'] = Token.objects.filter(owner_address=to_checksum_address(address)).order_by(order_by)
paginator = Paginator(context['kudos'], results_per_page)
else :
context = Token.objects.filter(sent_from_address=to_checksum_address(address)).order_by(order_by)
context['sent_kudos'] = Token.objects.filter(sent_from_address=to_checksum_address(address)).order_by(order_by)
paginator = Paginator(context['sent_kudos'], results_per_page)

# use Django’s pagination
# https://docs.djangoproject.com/en/dev/topics/pagination/
results_per_page = 8
paginator = Paginator(context, results_per_page)
try:
kudos = paginator.page(page)
except PageNotAnInteger:
Expand Down
77 changes: 53 additions & 24 deletions app/kudos/templates/shared/kudos_card_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,59 @@
{% endcomment %}
{% load i18n staticfiles %}
{% load kudos_extras %}

{% for kudo 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 }}" 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>
<div class="kd-content">
<div class="kd-title">{{ kudo.name|humanize_name }}</div>
{{ kudo.description|truncatechars:100 }}
{% if kudos_data == 'sent_kudos' %}
{% for kudo 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="/kudos/{{ kudo.id }}" 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>
<div class="kd-content">
<div class="kd-title">{{ kudo.name|humanize_name }}</div>
{{ kudo.description|truncatechars:100 }}
</div>
<div class="content-hover">
<a class="kd-title" href="/kudos/{{ kudo.id }}">{{ kudo.name|humanize_name }}</a>
<a href="https://etherscan.io/address/{{ kudo.owner_address }}" target="_blank" class="d-block mb-1">{{ kudo.owner_address|humanize_address }}</a>
<!-- <div>Sent from <a href="">{{ kudo.sent_from_address|humanize_address }}</a></div> -->
<p>
{{ kudo.description }}
</p>
<p>
{% for tag in kudo.tags.split %}
<span class="badge badge-kudos">{{tag | replace_commas }}</span>
{% endfor %}
</p>
</div>
</div>
<div class="content-hover">
<a class="kd-title" href="/kudos/{{ kudo.id }}">{{ kudo.name|humanize_name }}</a>
<a href="https://etherscan.io/address/{{ kudo.owner_address }}" target="_blank" class="d-block mb-1">{{ kudo.owner_address|humanize_address }}</a>
<!-- <div>Sent from <a href="">{{ kudo.sent_from_address|humanize_address }}</a></div> -->
<p>
{{ kudo.description }}
</p>
<p>
{% for tag in kudo.tags.split %}
<span class="badge badge-kudos">{{tag | replace_commas }}</span>
{% endfor %}
</p>
</div>
{% endfor %}
{% else %}
{% for kudo 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 }}" 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>
<div class="kd-content">
<div class="kd-title">{{ kudo.name|humanize_name }}</div>
{{ kudo.description|truncatechars:100 }}
</div>
<div class="content-hover">
<a class="kd-title" href="/kudos/{{ kudo.id }}">{{ kudo.name|humanize_name }}</a>
<a href="https://etherscan.io/address/{{ kudo.owner_address }}" target="_blank" class="d-block mb-1">{{ kudo.owner_address|humanize_address }}</a>
<!-- <div>Sent from <a href="">{{ kudo.sent_from_address|humanize_address }}</a></div> -->
<p>
{{ kudo.description }}
</p>
<p>
{% for tag in kudo.tags.split %}
<span class="badge badge-kudos">{{tag | replace_commas }}</span>
{% endfor %}
</p>
</div>
</div>
</div>
</div>
{% endfor %}
{% endfor %}

{% endif %}

0 comments on commit 69f035e

Please sign in to comment.