aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYaroslav <contact@yaroslavps.com>2019-01-10 23:30:05 +0300
committerYaroslav <contact@yaroslavps.com>2019-01-10 23:30:05 +0300
commitd22fe825fbf34842f9fa93c2f533677a34816984 (patch)
treecf5068a8cabfc61e289a7c4faa4e6a28672d2fca
parent96fc77becc1d89ca555dd65d1a79ffa178cc3a5c (diff)
downloadw3blog-d22fe825fbf34842f9fa93c2f533677a34816984.tar.gz
w3blog-d22fe825fbf34842f9fa93c2f533677a34816984.zip
improve post preview system, fix incorrect translation title on breadcrumbs
-rwxr-xr-xREADME.md4
-rwxr-xr-xsetup.py5
-rwxr-xr-xweblog/templates/weblog/index.html4
-rwxr-xr-xweblog/views.py43
4 files changed, 42 insertions, 14 deletions
diff --git a/README.md b/README.md
index 78f9b8a..15b2603 100755
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@ url(r'^blog/', include('weblog.urls')),
url(r'^summernote/', include('django_summernote.urls')),
```
-3. Migrate the models to the database by running "python manage.py makemigrations" and then "python manage.py migrate"
+3. Migrate the models to the database by running "python manage.py migrate".
4. You can configure and customize the blog by adding and modifying to your liking/needs the following settings to your settings.py:
@@ -65,3 +65,5 @@ This project was previously named django-weblog, however, I had to renamed it du
### Changelog ###
You can view a short summary of changes for each release in the releases section of the project's page on Github.
+
+Note: If you had already made migrations by yourself for this app before version 0.5.2, you might notice that django is telling you that there are new unapplied migrations. Apply them as you usually would, and if a "Programming Error: column "x" exists in..." happens, run "python manage.py migrate --fake weblog".
diff --git a/setup.py b/setup.py
index 2326a81..6e29e1a 100755
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
import os
from setuptools import find_packages, setup
@@ -10,7 +10,7 @@ os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
setup(
name='w3blog',
- version='0.5.2-testing',
+ version='0.5.2-testing-2',
packages=find_packages(),
include_package_data=True,
license='BSD License',
@@ -24,6 +24,7 @@ setup(
'Framework :: Django',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2.0',
+ 'Framework :: Django :: 2.1',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
diff --git a/weblog/templates/weblog/index.html b/weblog/templates/weblog/index.html
index 0f8d79a..7d8d723 100755
--- a/weblog/templates/weblog/index.html
+++ b/weblog/templates/weblog/index.html
@@ -40,7 +40,7 @@
<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 }}
+ <p>{{ post.preview_text|safe }}</p>
<hr>
<div class="text-right read-more-wrapper">
<a class="read-more" href="{{ post.url }}">{% trans 'Read more...' %}</a>
@@ -55,7 +55,7 @@
<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 }}
+ <p>{{ post.preview_text|safe }}</p>
<hr>
<div class="text-right read-more-wrapper">
<a class="read-more" href="{{ post.url }}">{% trans 'Read more...' %}</a>
diff --git a/weblog/views.py b/weblog/views.py
index d614cd6..64c4ec3 100755
--- a/weblog/views.py
+++ b/weblog/views.py
@@ -118,10 +118,17 @@ def Index(request, **kwargs):
post['title'] = post_raw.title
post['content'] = post_raw.content
post['preview_image'] = post_raw.preview_image
+ # If the author of the post provided custom preview text use it
if len(post_raw.preview_text) > 5:
post['preview_text'] = post_raw.preview_text
else:
- post['preview_text'] = post_raw.content.split('</p>', 1)[0]+'</p>'
+ try:
+ # Otherwise, find first paragraph and use it as preview text
+ # If none found, the preview is empty
+ post['preview_text'] = \
+ post_raw.content.split('<p>', 2)[1].split('</p>', 1)[0]
+ except IndexError:
+ post['preview_text'] = ''
else:
post_trans = None
orig_lang = post_raw.original_language
@@ -192,16 +199,23 @@ def PostView(request, category_slug, post_slug, language=None):
context_dict['category'] = category
# If we have the multilingual setting on, get the translation for the category
if IS_MULTILINGUAL:
- category_translations = CategoryTranslation.objects.filter(category=category)
+ category_translations =\
+ CategoryTranslation.objects.filter(category=category)
if category_translations.count() > 0:
for cat_trans in category_translations:
if current_language[0:2] == cat_trans.language[0:2]:
context_dict['category'] = cat_trans
# Put the necessary data about the category for the breadcrumbs
if category_slug == 'misc':
- context_dict['breadcrumbs'] = [{'url': reverse('weblog:CategoryIndex', kwargs={'category_slug': category_slug}), 'name': pgettext_lazy('Posts without category', 'Uncategorized')},]
+ context_dict['breadcrumbs'] = [{
+ 'url': reverse('weblog:CategoryIndex', kwargs={
+ 'category_slug': category_slug}),
+ 'name': pgettext_lazy('Posts without category', 'Uncategorized')},]
else:
- context_dict['breadcrumbs'] = [{'url': reverse('weblog:CategoryIndex', kwargs={'category_slug': category_slug}), 'name': context_dict['category']},]
+ context_dict['breadcrumbs'] = [{
+ 'url': reverse('weblog:CategoryIndex', kwargs={
+ 'category_slug': category_slug}),
+ 'name': context_dict['category']},]
# Put the necessary information about the author, based on the
# current project's settings
@@ -214,7 +228,8 @@ def PostView(request, category_slug, post_slug, language=None):
if ENABLE_COMMENTS:
context_dict['comments'] = PostComment.objects.filter(post=post)
- # If this is a POST request, it (probably) means that the user is attempting to post a comment
+ # If this is a POST request, it (probably) means that the user
+ # is attempting to post a comment
if request.method == 'POST':
form = PostCommentForm(request.POST)
context_dict['comment_submission'] = True
@@ -224,10 +239,16 @@ def PostView(request, category_slug, post_slug, language=None):
# Make sure that either anonymous comments are allowed or
# that the user is authenticated
if request.user.is_authenticated:
- new_comment = PostComment(author=request.user, post=post, content=comment_content, publish_date=datetime.datetime.now())
+ new_comment = PostComment(
+ author=request.user,
+ post=post,
+ content=comment_content,
+ publish_date=datetime.datetime.now())
new_comment.save()
elif ALLOW_ANON_COMMENTS:
- new_comment = PostComment(post=post, content=comment_content, publish_date=datetime.datetime.now())
+ new_comment = PostComment(post=post,
+ content=comment_content,
+ publish_date=datetime.datetime.now())
new_comment.save()
else:
context_dict['comment_submission_error'] = _('You need to sign in to submit a comment')
@@ -278,9 +299,13 @@ def PostView(request, category_slug, post_slug, language=None):
# If we are reading a translation, and not the original text,
# use those translations for the breadcrumbs, otherwise, use the original title
if 'post_translation' in context_dict:
- context_dict['breadcrumbs'].append({'url': post.get_absolute_url(), 'name': post_translation.title})
+ context_dict['breadcrumbs'].append({
+ 'url': post.get_absolute_url(),
+ 'name': context_dict['post_translation'].title})
else:
- context_dict['breadcrumbs'].append({'url': post.get_absolute_url(), 'name': post.title})
+ context_dict['breadcrumbs'].append({
+ 'url': post.get_absolute_url(),
+ 'name': post.title})
return render(request, 'weblog/post.html', context_dict)
# A dirty hack to change the language on the fly.