From bb97581d650e2d994e7b2e63297dbb2d8784f5f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20de=20la=20Pe=C3=B1a=20Smirnov?= Date: Sun, 7 Oct 2018 23:20:39 +0300 Subject: urls for ajax next page loading --- weblog/views.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'weblog/views.py') diff --git a/weblog/views.py b/weblog/views.py index cd5f6e8..3152edc 100755 --- a/weblog/views.py +++ b/weblog/views.py @@ -1,12 +1,14 @@ from django.shortcuts import render, get_object_or_404, redirect, reverse -from django.http import Http404, HttpResponseRedirect +from django.http import Http404, HttpResponseRedirect, HttpResponse from django.conf import settings from django.utils import translation from django.utils.translation import ugettext_lazy as _, pgettext_lazy +from django.core import serializers from .apps import SETTINGS as blog_settings from .models import BlogPost, Translation, PostComment, Category, CategoryTranslation, PostCommentForm from .templatetags.weblog_extras import MONTHS import datetime +import json #Need to change the way this works later IS_MULTILINGUAL = blog_settings['multilingual'] @@ -58,6 +60,8 @@ def Index(request, **kwargs): page = int(request.GET['page'])-1 if page * POSTS_PER_PAGE + 1 > post_count: page = 0 + if 'nxtpage' in kwargs: + page = int(kwargs['nxtpage']) - 1 context_dict['current_page'] = page+1 slice_start = page*POSTS_PER_PAGE slice_end = page*POSTS_PER_PAGE + POSTS_PER_PAGE @@ -149,6 +153,11 @@ def Index(request, **kwargs): pinned_posts.append(post) else: posts.append(post) + + # If ajax is asking for the next page through the kwargs, + # just send the posts for the requested page without the other page elements + if 'nxtpage' in kwargs: + return render(request, 'weblog/nxtpage.html', { 'posts': posts }) context_dict['posts'] = posts context_dict['pinned_posts'] = pinned_posts return render(request, 'weblog/index.html', context_dict) -- cgit v1.2.3