aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYaroslsav-95 <contact@yaroslavps.com>2018-03-29 16:45:02 +0300
committerYaroslsav-95 <contact@yaroslavps.com>2018-03-29 16:45:02 +0300
commitd6c508bb46d660947718083e3fa214049253c42b (patch)
tree3e4d8bac2247dbdcb3573e1ed00b23d80baf2c56
parentbe41310b3dc4aec12d3a950cf9fe737811436499 (diff)
downloadw3blog-d6c508bb46d660947718083e3fa214049253c42b.tar.gz
w3blog-d6c508bb46d660947718083e3fa214049253c42b.zip
Fixed bugs, and compatibility issues with Django 2.0
-rw-r--r--README.md30
-rw-r--r--setup.py5
-rw-r--r--weblog/apps.py2
-rw-r--r--weblog/migrations/0008_auto_20180329_1316.py30
-rw-r--r--weblog/models.py16
-rw-r--r--weblog/templates/weblog/sidebar_archive.html8
-rw-r--r--weblog/templates/weblog_base.html4
-rw-r--r--weblog/templates/weblog_base_old.html35
-rw-r--r--weblog/templatetags/__pycache__/__init__.cpython-35.pycbin166 -> 0 bytes
-rw-r--r--weblog/templatetags/__pycache__/__init__.cpython-36.pycbin166 -> 0 bytes
-rw-r--r--weblog/templatetags/__pycache__/weblog_extras.cpython-35.pycbin2682 -> 0 bytes
-rw-r--r--weblog/templatetags/__pycache__/weblog_extras.cpython-36.pycbin1448 -> 0 bytes
-rw-r--r--weblog/templatetags/weblog_extras.py2
13 files changed, 68 insertions, 64 deletions
diff --git a/README.md b/README.md
index 3da5fa9..7ed11eb 100644
--- a/README.md
+++ b/README.md
@@ -17,18 +17,18 @@ This django app is still a work in progress. More features will be added/complet
4. You can configure and customize the blog by adding and modifying to your liking/needs the following settings to your settings.py:
- WEBLOG_ENABLE_COMMENTS = True #Should comments be allowed on your blog
- WEBLOG_ALLOW_ANON_COMMENTS = False #Are visitors allowed to leave comments without signing in (note that you should provide a way for them to register and login if you wish to allow only registered user's comments)
- WEBLOG_MULTILINGUAL = True #Enable multilingual features of the weblog app (i.e.: BlogPost and Category translations)
- WEBLOG_TITLE = 'Weblog Test' #The name/title of your blog (e.g.: Example Site Newsletter)
- WEBLOG_BASE_TEMPLATE = 'site_base.html' #Which base template to use (if not indicated, it will use its own base template)
- WEBLOG_SHOW_AUTHOR = True #Should the author of the post be shown (it uses the Django User model)
- WEBLOG_USE_AUTHORS_USERNAME = True #Show the username of the author instead of the fullname
- WEBLOG_SHOW_SIDEBAR = True #Enable the sidebar
- WEBLOG_SHOW_CATEGORIES = True #Show links to categories in the sidebar
- WEBLOG_SHOW_ARCHIVE = True #Show the archive treeview (Years>Months) in the sidebar
- WEBLOG_POSTS_PER_PAGE = 10 #Number of posts that should be shown per page
-
-5. Note that if you use your own base template, you will either need to link bootstrap in your base template's head, or write your own styles for the site based on the bootstrap classes. You will as well need to link files "weblog/css/weblog.css" and "weblog/js/weblog.js" in your html head.
-
-Note: This package depends on the following python packages (besides Django and their dependencies): django-summernote \ No newline at end of file
+ * WEBLOG_ENABLE_COMMENTS = True #Should comments be allowed on your blog
+ * WEBLOG_ALLOW_ANON_COMMENTS = False #Are visitors allowed to leave comments without signing in (note that you should provide a way for them to register and login if you wish to allow only registered user's comments)
+ * WEBLOG_MULTILINGUAL = True #Enable multilingual features of the weblog app (i.e.: BlogPost and Category translations)
+ * WEBLOG_TITLE = 'Weblog Test' #The name/title of your blog (e.g.: Example Site Newsletter)
+ * WEBLOG_BASE_TEMPLATE = 'site_base.html' #Which base template to use (if not indicated, it will use its own base template)
+ * WEBLOG_SHOW_AUTHOR = True #Should the author of the post be shown (it uses the Django User model)
+ * WEBLOG_USE_AUTHORS_USERNAME = True #Show the username of the author instead of the fullname
+ * WEBLOG_SHOW_SIDEBAR = True #Enable the sidebar
+ * WEBLOG_SHOW_CATEGORIES = True #Show links to categories in the sidebar
+ * WEBLOG_SHOW_ARCHIVE = True #Show the archive treeview (Years>Months) in the sidebar
+ * WEBLOG_POSTS_PER_PAGE = 10 #Number of posts that should be shown per page
+
+5. Note that if you use your own base template, you will either need to link bootstrap (v3.2 at the moment) in your base template's head, or write your own styles for the site based on the bootstrap classes. You will as well need to link files "weblog/css/weblog.css" and "weblog/js/weblog.js" in your html head, or write your own.
+
+Note: This package depends on the following python packages (besides Django and their dependencies): django-summernote
diff --git a/setup.py b/setup.py
index 88265df..3f90b2d 100644
--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,7 @@ os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
setup(
name='django-weblog',
- version='0.2.1',
+ version='0.2.2',
packages=find_packages(),
include_package_data=True,
license='BSD License',
@@ -22,6 +22,7 @@ setup(
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 1.11',
+ 'Framework :: Django :: 2.0',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
@@ -33,4 +34,4 @@ setup(
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
-) \ No newline at end of file
+)
diff --git a/weblog/apps.py b/weblog/apps.py
index 3389f92..05b5a20 100644
--- a/weblog/apps.py
+++ b/weblog/apps.py
@@ -5,7 +5,7 @@ SETTINGS = {
'allow_anon_comments': True,
'multilingual': True,
'blog_title': 'Django-Weblog',
- 'base_template': 'base.html',
+ 'base_template': 'weblog_base.html',
'show_author': True,
'use_authors_username': True,
'show_sidebar': True,
diff --git a/weblog/migrations/0008_auto_20180329_1316.py b/weblog/migrations/0008_auto_20180329_1316.py
new file mode 100644
index 0000000..f66aa65
--- /dev/null
+++ b/weblog/migrations/0008_auto_20180329_1316.py
@@ -0,0 +1,30 @@
+# Generated by Django 2.0.3 on 2018-03-29 13:16
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('weblog', '0007_auto_20180122_1943'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='blogpost',
+ name='author',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, verbose_name='Author'),
+ ),
+ migrations.AlterField(
+ model_name='category',
+ name='parent_category',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='weblog.Category', verbose_name='Parent category'),
+ ),
+ migrations.AlterField(
+ model_name='postcomment',
+ name='author',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, verbose_name='Author'),
+ ),
+ ]
diff --git a/weblog/models.py b/weblog/models.py
index 80e917e..63f3f2c 100644
--- a/weblog/models.py
+++ b/weblog/models.py
@@ -7,11 +7,11 @@ from django.utils.translation import ugettext_lazy as _, pgettext_lazy
class Category(models.Model):
name = models.CharField(max_length=250, verbose_name=pgettext_lazy('Noun, not personal name', 'Name'), blank=False, unique=True)
slug = models.SlugField(max_length=60, verbose_name=_('Slug (URL)'), db_index=True, unique=True)
- parent_category = models.ForeignKey('self', verbose_name=_('Parent category'), null=True, blank=True)
+ parent_category = models.ForeignKey('self', verbose_name=_('Parent category'), on_delete=models.PROTECT, null=True, blank=True)
def get_absolute_url(self):
return reverse('weblog:CategoryIndex', kwargs={'category_slug': self.slug})
-
+
def __str__(self):
return self.name
@@ -22,7 +22,7 @@ class Category(models.Model):
class CategoryTranslation(models.Model):
name = models.CharField(max_length=250, verbose_name=pgettext_lazy('Noun, not personal name', 'Name'), blank=False)
language = models.CharField(max_length=5, verbose_name=_('Language (ISO)'), blank=False)
- category = models.ForeignKey(Category, verbose_name = pgettext_lazy('Post category', 'Category'), blank=False)
+ category = models.ForeignKey(Category, verbose_name = pgettext_lazy('Post category', 'Category'), on_delete=models.CASCADE, blank=False)
def __str__(self):
return self.name
@@ -36,7 +36,7 @@ class CategoryTranslation(models.Model):
class BlogPost(models.Model):
- author = models.ForeignKey(User, verbose_name=_('Author'))
+ author = models.ForeignKey(User, verbose_name=_('Author'), on_delete=models.PROTECT)
title = models.CharField(max_length=100, verbose_name=pgettext_lazy('As in name', 'Title'), blank=False)
content = models.TextField(verbose_name=pgettext_lazy('Of post, comment, article, etc.', 'Content'), blank=False)
preview_image = models.ImageField(upload_to='weblog/preview_images/%Y/%m/%d/', blank=True, verbose_name=_('Preview image'))
@@ -63,7 +63,7 @@ class BlogPost(models.Model):
verbose_name_plural = _('Blog Posts')
class Translation(models.Model):
- post = models.ForeignKey(BlogPost, verbose_name=pgettext_lazy('Noun, as in blog post', 'Post'))
+ post = models.ForeignKey(BlogPost, verbose_name=pgettext_lazy('Noun, as in blog post', 'Post'), on_delete=models.CASCADE)
language = models.CharField(max_length=5, verbose_name=_('Language (ISO)'), blank=False)
title = models.CharField(max_length=100, verbose_name=pgettext_lazy('As in name', 'Title'), blank=False)
content = models.TextField(verbose_name=pgettext_lazy('Of post, comment, article, etc.', 'Content'), blank=False)
@@ -75,8 +75,8 @@ class Translation(models.Model):
verbose_name_plural = _('Translations')
class PostComment(models.Model):
- author = models.ForeignKey(User, verbose_name=_('Author'), null=True, blank=True)
- post = models.ForeignKey(BlogPost, verbose_name=pgettext_lazy('Noun, as in blog post', 'Post'))
+ author = models.ForeignKey(User, verbose_name=_('Author'), on_delete=models.SET_NULL, null=True, blank=True)
+ post = models.ForeignKey(BlogPost, verbose_name=pgettext_lazy('Noun, as in blog post', 'Post'), on_delete=models.CASCADE)
content = models.TextField(verbose_name=pgettext_lazy('Of post, comment, article, etc.', 'Content'), blank=False)
class Meta:
@@ -90,4 +90,4 @@ class PostCommentForm(ModelForm):
labels = {'content': ''}
widgets = {
'content': Textarea(attrs={'class': 'form-control', 'rows': '5'}),
- } \ No newline at end of file
+ }
diff --git a/weblog/templates/weblog/sidebar_archive.html b/weblog/templates/weblog/sidebar_archive.html
index 5953bfe..ca74018 100644
--- a/weblog/templates/weblog/sidebar_archive.html
+++ b/weblog/templates/weblog/sidebar_archive.html
@@ -1,5 +1,6 @@
{% load i18n %}
<h3>{% trans 'Archive' context 'Blog archive' %}</h3>
+{% if archive %}
<ul class='archive-list'>
{% for a_year in archive %}
<li><a class="node-toggle" node-target="{{ a_year.0 }}-list" node-state="closed" href="javascript:void(0)" onclick="toggleNode(this);">+</a> <a href="{% url 'weblog:ArchiveIndex' year=a_year.0 %}">{{ a_year.0 }}</a>
@@ -10,4 +11,9 @@
</ul>
</li>
{% endfor %}
-</ul> \ No newline at end of file
+{% else %}
+<div class="text-center">
+ <p>{% trans 'Nothing has been posted yet.' %}</p>
+</div>
+{% endif %}
+</ul>
diff --git a/weblog/templates/weblog_base.html b/weblog/templates/weblog_base.html
index 536e736..6a551ff 100644
--- a/weblog/templates/weblog_base.html
+++ b/weblog/templates/weblog_base.html
@@ -3,7 +3,7 @@
<html>
<head>
<meta charset="utf-8">
- <title>Simple blog - {% block title_block %} Home {% endblock %}</title>
+ <title>{% block title_block %} Home {% endblock %}</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="{% static '/weblog/css/weblog.css' %}">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js" defer></script>
@@ -25,4 +25,4 @@
{% endblock %}
</div>
</body>
-</html> \ No newline at end of file
+</html>
diff --git a/weblog/templates/weblog_base_old.html b/weblog/templates/weblog_base_old.html
deleted file mode 100644
index a4dbd30..0000000
--- a/weblog/templates/weblog_base_old.html
+++ /dev/null
@@ -1,35 +0,0 @@
-<!DOCTYPE html>
-{% load static %}
-<html>
- <head>
- <meta charset="utf-8">
- <title>Simple blog - {% block title_block %} Home {% endblock %}</title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
- <link rel="stylesheet" href="{% static '/weblog/css/weblog.css' %}">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js" defer></script>
- <script src="{% static '/weblog/js/weblog.js' %}" defer></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" defer></script>
- </head>
- <body>
- <nav class="navbar navbar-inverse">
- <div class="container nav-container">
- <div class="navbar-header">
- <a class="navbar-brand" href="{% url 'weblog:Index' %}">{{ blog_title }}</a>
- </div>
- <div class="collapse navbar-collapse">
- <ul class="nav navbar-nav navbar-right">
- <li><a href="{% url 'weblog:ChangeLanguage' language='en' %}?next={{ request.path }}">EN</a></li>
- <li><a href="{% url 'weblog:ChangeLanguage' language='es' %}?next={{ request.path }}">ES</a></li>
- <li><a href="{% url 'weblog:ChangeLanguage' language='ru' %}?next={{ request.path }}">RU</a></li>
- </ul>
- </div>
- </div>
- </nav>
- <div class="container">
- {% block content_block %}
- {% block blog_block %}
- {% endblock %}
- {% endblock %}
- </div>
- </body>
-</html> \ No newline at end of file
diff --git a/weblog/templatetags/__pycache__/__init__.cpython-35.pyc b/weblog/templatetags/__pycache__/__init__.cpython-35.pyc
deleted file mode 100644
index 8b2440b..0000000
--- a/weblog/templatetags/__pycache__/__init__.cpython-35.pyc
+++ /dev/null
Binary files differ
diff --git a/weblog/templatetags/__pycache__/__init__.cpython-36.pyc b/weblog/templatetags/__pycache__/__init__.cpython-36.pyc
deleted file mode 100644
index 8ec5021..0000000
--- a/weblog/templatetags/__pycache__/__init__.cpython-36.pyc
+++ /dev/null
Binary files differ
diff --git a/weblog/templatetags/__pycache__/weblog_extras.cpython-35.pyc b/weblog/templatetags/__pycache__/weblog_extras.cpython-35.pyc
deleted file mode 100644
index bcc8327..0000000
--- a/weblog/templatetags/__pycache__/weblog_extras.cpython-35.pyc
+++ /dev/null
Binary files differ
diff --git a/weblog/templatetags/__pycache__/weblog_extras.cpython-36.pyc b/weblog/templatetags/__pycache__/weblog_extras.cpython-36.pyc
deleted file mode 100644
index eb1b1e6..0000000
--- a/weblog/templatetags/__pycache__/weblog_extras.cpython-36.pyc
+++ /dev/null
Binary files differ
diff --git a/weblog/templatetags/weblog_extras.py b/weblog/templatetags/weblog_extras.py
index 1f72a86..bf84936 100644
--- a/weblog/templatetags/weblog_extras.py
+++ b/weblog/templatetags/weblog_extras.py
@@ -46,6 +46,8 @@ def get_sidebar_categories(selected_cat_slug=None):
@register.inclusion_tag('weblog/sidebar_archive.html')
def get_sidebar_archive():
+ if BlogPost.objects.all().count() < 1:
+ return {}
now = datetime.datetime.now()
oldest_post = BlogPost.objects.filter(published=True).reverse()[0]
first_year = oldest_post.publish_date.year