def update(request): first_kpop = request.GET.get('first_kpop') last_kpop = request.GET.get('last_kpop') kpop_source = request.GET.get('kpop_source') kpops = Kpop.get_kpops().filter(id__range=(last_kpop, first_kpop)) if kpop_source != 'all': kpops = kpops.filter(user__id=kpop_source) dump = {} for kpop in kpops: dump[kpop.pk] = {'likes': kpop.likes, 'comments': kpop.comments} data = json.dumps(dump) return HttpResponse(data, content_type='application/json')
def kpops(request): all_kpops = Kpop.get_kpops() paginator = Paginator(all_kpops, FEEDS_NUM_PAGES) kpops = paginator.page(1) from_kpop = -1 if kpops: from_kpop = kpops[0].id return render(request, 'kpops/kpops.html', { 'kpops': kpops, 'from_kpop': from_kpop, 'page': 1, })
def load(request): from_kpop = request.GET.get('from_kpop') page = request.GET.get('page') kpop_source = request.GET.get('kpop_source') all_kpops = Kpop.get_kpops(from_kpop) if kpop_source != 'all': all_kpops = all_kpops.filter(user__id=kpop_source) paginator = Paginator(all_kpops, FEEDS_NUM_PAGES) try: kpops = paginator.page(page) except PageNotAnInteger: return HttpResponseBadRequest() except EmptyPage: kpops = [] html = u'' csrf_token = unicode(csrf(request)['csrf_token']) for kpop in kpops: html = u'{0}{1}'.format(html, render_to_string('kpops/partial_kpop.html', { 'kpop': kpop, 'user': request.user, 'csrf_token': csrf_token }) ) return HttpResponse(html)