diff options
-rwxr-xr-x | README.md | 4 | ||||
-rwxr-xr-x | setup.py | 5 | ||||
-rwxr-xr-x | weblog/templates/weblog/index.html | 4 | ||||
-rwxr-xr-x | weblog/views.py | 43 |
4 files changed, 42 insertions, 14 deletions
@@ -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". @@ -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. |