def load(request): from_feed = request.GET.get('from_feed') page = request.GET.get('page') feed_source = request.GET.get('feed_source') all_feeds = Feed.get_feeds(from_feed) if feed_source != 'all': all_feeds = all_feeds.filter(user__id=feed_source) paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) try: feeds = paginator.page(page) except PageNotAnInteger: return HttpResponseBadRequest() except EmptyPage: feeds = [] html = '' csrf_token = (csrf(request)['csrf_token']) for feed in feeds: html = '{0}{1}'.format( html, render_to_string('feeds/partial_feed.html', { 'feed': feed, 'user': request.user, 'csrf_token': csrf_token })) return HttpResponse(html)
def update(request): first_feed = request.GET.get('first_feed') last_feed = request.GET.get('last_feed') feed_source = request.GET.get('feed_source') feeds = Feed.get_feeds().filter(id__range=(last_feed, first_feed)) if feed_source != 'all': feeds = feeds.filter(user__id=feed_source) dump = {} for feed in feeds: dump[feed.pk] = {'likes': feed.likes, 'comments': feed.comments} data = json.dumps(dump) return HttpResponse(data, content_type='application/json')
def profile(request, username): page_user = get_object_or_404(User, username=username) all_feeds = Feed.get_feeds().filter(user=page_user) paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) from_feed = -1 if feeds: from_feed = feeds[0].id return render(request, 'core/profile.html', { 'page_user': page_user, 'feeds': feeds, 'from_feed': from_feed, 'page': 1 })
def feeds(request): all_feeds = Feed.get_feeds() products = Post.objects.all().order_by("-timestamp") paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) from_feed = -1 if feeds: from_feed = feeds[0].id return render(request, 'feeds/feeds.html', { 'feeds': feeds, 'from_feed': from_feed, 'page': 1, 'products': products })