aboutsummaryrefslogtreecommitdiff
path: root/weblog
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <contact@yaroslavps.com>2018-10-07 23:20:39 +0300
committerYaroslav de la Peña Smirnov <contact@yaroslavps.com>2018-10-07 23:20:39 +0300
commitbb97581d650e2d994e7b2e63297dbb2d8784f5f3 (patch)
tree716a7612ce3467e268eba57c1cb3078383f49aec /weblog
parent0eb94a690c477cc8e5b73e29805db17514128bde (diff)
downloadw3blog-bb97581d650e2d994e7b2e63297dbb2d8784f5f3.tar.gz
w3blog-bb97581d650e2d994e7b2e63297dbb2d8784f5f3.zip
urls for ajax next page loading
Diffstat (limited to 'weblog')
-rwxr-xr-xweblog/apps.py2
-rwxr-xr-xweblog/static/weblog/js/weblog.js3
-rwxr-xr-xweblog/templates/weblog/index.html9
-rw-r--r--weblog/templates/weblog/nxtpage.html15
-rwxr-xr-xweblog/urls.py4
-rwxr-xr-xweblog/views.py11
6 files changed, 43 insertions, 1 deletions
diff --git a/weblog/apps.py b/weblog/apps.py
index cc800c1..3197cef 100755
--- a/weblog/apps.py
+++ b/weblog/apps.py
@@ -12,6 +12,8 @@ SETTINGS = {
'show_categories': False,
'show_archive': True,
'posts_per_page': 10,
+ 'dynamic_load': False,
+ 'infinite_load': False,
'enable_rss': True,
}
diff --git a/weblog/static/weblog/js/weblog.js b/weblog/static/weblog/js/weblog.js
index af9b9ea..3d93770 100755
--- a/weblog/static/weblog/js/weblog.js
+++ b/weblog/static/weblog/js/weblog.js
@@ -11,3 +11,6 @@ function toggleNode(caller){
}
target.classList.toggle('show');
}
+
+function loadBlogPosts(page = 2, category = null){
+}
diff --git a/weblog/templates/weblog/index.html b/weblog/templates/weblog/index.html
index 8dc1d93..b30c0ff 100755
--- a/weblog/templates/weblog/index.html
+++ b/weblog/templates/weblog/index.html
@@ -103,4 +103,13 @@
{% else %}
<div class="text-center"><h3>{% trans 'Nothing has been posted yet.' %}</h3></div>
{% endif %}
+ {% if dynamic_load %}
+ <script>
+ var current_page = {{ current_page }};
+ var last_page = {{ last_page }};
+ {% if infinite_load %}
+ {% else %}
+ {% endif %}
+ </script>
+ {% endif %}
{% endblock %}
diff --git a/weblog/templates/weblog/nxtpage.html b/weblog/templates/weblog/nxtpage.html
new file mode 100644
index 0000000..67d244a
--- /dev/null
+++ b/weblog/templates/weblog/nxtpage.html
@@ -0,0 +1,15 @@
+{% load i18n %}
+{% for post in posts %}
+<div class="blogpost">
+ <h2 class="post-title"><a href="{{ post.url }}">{{ post.title }}</a></h2>
+ <p class="publish-info">{% blocktrans with publish_date=post.publish_date %}Published on <span class="post-publish-date">{{ publish_date }}</span>{% endblocktrans %}{% if post.author %}{% blocktrans with author=post.author context 'Written by (Author)' %}, by <span class="post-author">{{ author }}</span>{% endblocktrans %}{% endif %}</p>
+ <hr>
+ {% if post.preview_image %}<img class="img-fluid preview-img" src="{{ post.preview_image.url }}">{% endif %}
+ {{ post.preview_text|safe }}
+ <hr>
+ <div class="text-right read-more-wrapper">
+ <a class="read-more" href="{{ post.url }}">{% trans 'Read more...' %}</a>
+ </div>
+</div>
+{% endfor %}
+
diff --git a/weblog/urls.py b/weblog/urls.py
index ddc2c9f..7ddd7f1 100755
--- a/weblog/urls.py
+++ b/weblog/urls.py
@@ -15,6 +15,10 @@ if blog_settings['enable_rss']:
urlpatterns += [
url(r'^$', views.Index, name='Index'),
+ url(r'^ajaxnxtpage/page-(?P<nxtpage>[0-9]+)/$', views.Index, name='GetPosts'),
+ url(r'^ajaxnxtpage/(?P<year>[0-9]{4})/page-(?P<nxtpage>[0-9]+)/$', views.Index, name='GetArchivePosts'),
+ url(r'^ajaxnxtpage/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/page-(?P<nxtpage>[0-9]+)/$', views.Index, name='GetArchivePosts'),
+ url(r'^ajaxnxtpage/(?P<category_slug>[-\w]+)/page-(?P<nxtpage>[0-9]+)/$', views.Index, name='GetCategoryPosts'),
url(r'^change-language/(?P<language>[-\w]+)/$', views.ChangeLanguage, name='ChangeLanguage'),
url(r'^(?P<year>[0-9]{4})/$', views.Index, name='ArchiveIndex'),
url(r'^(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/$', views.Index, name='ArchiveIndex'),
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)