Skip to content

Commit

Permalink
Fix #2655 - Adjust lazy_load_kudos to catch nonexistent profile (#2657)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Beacom authored and octavioamu committed Nov 2, 2018
1 parent cd76fc1 commit 98a15d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
1 change: 0 additions & 1 deletion app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,6 @@ def get_sent_kudos(self):
contract__network=settings.KUDOS_NETWORK,
).distinct('id')


@property
def is_org(self):
try:
Expand Down
21 changes: 12 additions & 9 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,22 +1202,25 @@ def profile(request, handle):
@csrf_exempt
def lazy_load_kudos(request):
page = request.POST.get('page', 1)
address = request.POST.get('address')
context = {}
datarequest = request.POST.get('request')
order_by = request.GET.get('order_by', '-modified_on')
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)
else:
key = 'sent_kudos'
context[key] = profile.get_sent_kudos.order_by('id', order_by)

paginator = Paginator(context[key], limit)
if handle:
try:
profile = Profile.objects.get(handle=handle)
if datarequest == 'mykudos':
key = 'kudos'
context[key] = profile.get_my_kudos.order_by('id', order_by)
else:
key = 'sent_kudos'
context[key] = profile.get_sent_kudos.order_by('id', order_by)
except Profile.DoesNotExist:
pass

paginator = Paginator(context[key], limit)
kudos = paginator.get_page(page)
kudos_html = loader.render_to_string('shared/kudos_card_profile.html', {'kudos': kudos})
return JsonResponse({'kudos_html': kudos_html, 'has_next': kudos.has_next()})
Expand Down

0 comments on commit 98a15d5

Please sign in to comment.