From: Brett Parker Date: Thu, 22 Jun 2017 13:32:06 +0000 (+0100) Subject: Fix up for django 1.10 X-Git-Url: https://git.sommitrealweird.co.uk/sommitrealweird.git/commitdiff_plain/4ad54bc9a9429a2c5c288192c663f75ae1e7aad9?ds=sidebyside Fix up for django 1.10 --- diff --git a/.gitignore b/.gitignore index bbb7c87..acbc6d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.py[oc] /sommitrealweird.db /sommitrealweird/localsettings.py +/media/admin /media/photos /media/thumbs /tmp diff --git a/sommitrealweird/blog/migrations/0001_initial.py b/sommitrealweird/blog/migrations/0001_initial.py new file mode 100644 index 0000000..7f42c9e --- /dev/null +++ b/sommitrealweird/blog/migrations/0001_initial.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-06-22 09:40 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='BlogEntry', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=150)), + ('islive', models.BooleanField(default=False)), + ('format', models.CharField(choices=[(b'rst', b'reStructuredText'), (b'html', b'HTML')], max_length=10)), + ('slug', models.SlugField()), + ('publish_date', models.DateTimeField()), + ('content', models.TextField()), + ], + options={ + 'ordering': ['-publish_date'], + }, + ), + migrations.CreateModel( + name='BlogSection', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=150)), + ('slug', models.SlugField()), + ], + ), + migrations.AddField( + model_name='blogentry', + name='sections', + field=models.ManyToManyField(to='blog.BlogSection'), + ), + ] diff --git a/sommitrealweird/blog/migrations/__init__.py b/sommitrealweird/blog/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sommitrealweird/blog/models.py b/sommitrealweird/blog/models.py index fa2e954..9548a32 100644 --- a/sommitrealweird/blog/models.py +++ b/sommitrealweird/blog/models.py @@ -1,4 +1,3 @@ -from django.contrib.comments.moderation import CommentModerator, moderator from django.db import models from django.conf import settings from django.contrib import admin @@ -29,17 +28,6 @@ class BlogEntry(models.Model): class Meta: ordering = ['-publish_date'] -class BlogEntryCommentModerator(CommentModerator): - email_notification = True - - def moderate(self, comment, content_object, request): - if request.user.is_authenticated(): - return False - else: - return True - -moderator.register(BlogEntry, BlogEntryCommentModerator) - class BlogSection(models.Model): title = models.CharField(max_length=150) slug = models.SlugField() diff --git a/sommitrealweird/blog/templates/blog/blog_index.html b/sommitrealweird/blog/templates/blog/blog_index.html index 950e4cd..f2ede84 100644 --- a/sommitrealweird/blog/templates/blog/blog_index.html +++ b/sommitrealweird/blog/templates/blog/blog_index.html @@ -1,6 +1,5 @@ {% extends "base.html" %} {% load xhtml11rst %} -{% load comments %} {% block extrahead %} @@ -26,8 +25,7 @@ {% endif %} {% endif %} {% endfor %} - {% get_comment_count for entry as comment_count %} - | permalink | Comments: {{ comment_count }}

+ | permalink

{% endfor %} {% if paginated and has_more_than_one_page %}

Pages: diff --git a/sommitrealweird/blog/templates/blog/single_entry_rst.html b/sommitrealweird/blog/templates/blog/single_entry_rst.html index 5dd4258..695df77 100644 --- a/sommitrealweird/blog/templates/blog/single_entry_rst.html +++ b/sommitrealweird/blog/templates/blog/single_entry_rst.html @@ -1,7 +1,6 @@ {% extends "base.html" %} {% load xhtml11rst %} -{% load comments %} {%block title %}{{ entry.title }}{% endblock %} @@ -25,22 +24,6 @@ {% endif %} {% endfor %} {% endif %} - {% get_comment_count for entry as comment_count %} - | permalink | Comments: {{ comment_count }} + | permalink

-{% if comment_count %} -
- - {% get_comment_list for entry as comment_list %} - {% for comment in comment_list %} -
-

{{ comment.user_name }} - {{ comment.submit_date|date:"Y-m-d H:i" }}

- {{ comment.comment }} -
- {% endfor %} -
-{% endif %} -
- {% render_comment_form for entry %} -
{% endblock %} diff --git a/sommitrealweird/blog/urls.py b/sommitrealweird/blog/urls.py index 19678eb..eeeb25b 100644 --- a/sommitrealweird/blog/urls.py +++ b/sommitrealweird/blog/urls.py @@ -1,13 +1,14 @@ -from django.conf.urls import patterns +from django.conf.urls import url +import blog.views from settings import MEDIA_ROOT, MEDIA_URL -urlpatterns = patterns('', - (r'^(?P[0-9]{4})/(?P[0-9]{2})/(?P[0-9]{2})/(?P[^/]+)(/|)$', 'blog.views.blog_view'), - (r'^(?P[0-9]{4})(?P[0-9]{2})(?P[0-9]{2})-(?P[^/]+)\.html$', 'blog.views.blog_view'), - (r'^(?P[0-9]{4})(?P[0-9]{2})(?P[0-9]{2})(?P[0-9]{2})(?P[0-9]{2})-(?P[^/]+)\.html$', 'blog.views.blog_view'), - (r'^(?P[0-9]{4})/(?P[0-9]{2})/(?P[0-9]{2})/$', 'blog.views.blog_view'), - (r'^(?P[0-9]{4})/(?P[0-9]{2})/$', 'blog.views.blog_view'), - (r'^(?P[0-9]{4})/$', 'blog.views.blog_view'), - (r'^section/(?P
[^/]*)/$', 'blog.views.blog_index'), - (r'^$', 'blog.views.blog_index'), -) +urlpatterns = [ + url(r'^(?P[0-9]{4})/(?P[0-9]{2})/(?P[0-9]{2})/(?P[^/]+)(/|)$', blog.views.blog_view), + url(r'^(?P[0-9]{4})(?P[0-9]{2})(?P[0-9]{2})-(?P[^/]+)\.html$', blog.views.blog_view), + url(r'^(?P[0-9]{4})(?P[0-9]{2})(?P[0-9]{2})(?P[0-9]{2})(?P[0-9]{2})-(?P[^/]+)\.html$', blog.views.blog_view), + url(r'^(?P[0-9]{4})/(?P[0-9]{2})/(?P[0-9]{2})/$', blog.views.blog_view), + url(r'^(?P[0-9]{4})/(?P[0-9]{2})/$', blog.views.blog_view), + url(r'^(?P[0-9]{4})/$', blog.views.blog_view), + url(r'^section/(?P
[^/]*)/$', blog.views.blog_index), + url(r'^$', blog.views.blog_index), +] diff --git a/sommitrealweird/blog/views.py b/sommitrealweird/blog/views.py index 09ff5e4..52fab00 100644 --- a/sommitrealweird/blog/views.py +++ b/sommitrealweird/blog/views.py @@ -1,5 +1,6 @@ from blog.models import BlogEntry, BlogSection from django.http import Http404, HttpResponse +from django.shortcuts import render from django.template import RequestContext, loader from django.core.paginator import Paginator from django.conf import settings @@ -19,9 +20,7 @@ def blog_index(request, section=None): try: paginated_entries = paginator.page(page) pages = paginator.page_range - t = loader.get_template("blog/blog_index.html") - c = RequestContext(request, - { + c = { "entries": paginated_entries.object_list, "title": settings.BLOG_TITLE, "page": page, @@ -32,8 +31,8 @@ def blog_index(request, section=None): "has_prev": paginated_entries.has_previous(), "next": page + 1, "prev": page - 1 - }) - return HttpResponse(t.render(c)) + } + return render(request, 'blog/blog_index.html', c) except: raise Http404 else: @@ -49,14 +48,11 @@ def blog_view(request, year=None, month=None, day=None, hour=None, minutes=None, try: blog_entry = BlogEntry.objects.get(publish_date__year=year, publish_date__month=month, publish_date__day=day, slug__exact=slug) template_name = "blog/single_entry_%s.html" %(blog_entry.format,) - t = loader.get_template(template_name) - c = RequestContext(request, - { + c = { "entry": blog_entry, "publish_date": blog_entry.publish_date } - ) - return HttpResponse(t.render(c)) + return render(request, template_name, c) except: raise Http404 else: @@ -84,9 +80,7 @@ def blog_view(request, year=None, month=None, day=None, hour=None, minutes=None, try: paginated_entries = paginator.page(page) pages = paginator.page_range - t = loader.get_template("blog/blog_index.html") - c = RequestContext(request, - { + c = { "entries": paginated_entries.object_list, "title": settings.BLOG_TITLE, "page": page, @@ -97,8 +91,8 @@ def blog_view(request, year=None, month=None, day=None, hour=None, minutes=None, "has_prev": paginated_entries.has_previous(), "next": page + 1, "prev": page - 1 - }) - return HttpResponse(t.render(c)) + } + return render(request, "blog/blog_index.html", c) except: raise Http404 else: diff --git a/sommitrealweird/bpcms/migrations/0001_initial.py b/sommitrealweird/bpcms/migrations/0001_initial.py new file mode 100644 index 0000000..0671562 --- /dev/null +++ b/sommitrealweird/bpcms/migrations/0001_initial.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-06-22 09:39 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='CSSDocument', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=150)), + ('slug', models.SlugField()), + ('content', models.TextField()), + ], + ), + migrations.CreateModel( + name='Document', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=150)), + ('islive', models.BooleanField(default=False)), + ('format', models.CharField(choices=[(b'rst', b'reStructuredText'), (b'html', b'HTML')], max_length=10)), + ('slug', models.SlugField()), + ('content', models.TextField()), + ('extracss', models.ManyToManyField(blank=True, null=True, to='bpcms.CSSDocument')), + ], + options={ + 'ordering': ['folder'], + }, + ), + migrations.CreateModel( + name='Folder', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=150)), + ('slug', models.SlugField()), + ('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='bpcms.Folder')), + ], + ), + migrations.AddField( + model_name='document', + name='folder', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='bpcms.Folder'), + ), + ] diff --git a/sommitrealweird/bpcms/migrations/__init__.py b/sommitrealweird/bpcms/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sommitrealweird/bpcms/models.py b/sommitrealweird/bpcms/models.py index 38f18ff..6493902 100644 --- a/sommitrealweird/bpcms/models.py +++ b/sommitrealweird/bpcms/models.py @@ -66,14 +66,14 @@ class Document(models.Model): def get_absolute_url(self): if self.slug == 'index': if self.folder.parent: - return reverse('bpcms.views.document_view', kwargs={'folders': self.folder.parent.get_path(), 'slug': self.folder.slug}) + return reverse('bpcms-document-view', kwargs={'folders': self.folder.parent.get_path(), 'slug': self.folder.slug}) else: - return reverse('bpcms.views.document_view', kwargs={'slug': self.folder.slug}) + return reverse('bpcms-document-view', kwargs={'slug': self.folder.slug}) else: if self.folder: - return reverse('bpcms.views.document_view', kwargs={'folders': self.get_folder_path(), 'slug': self.slug}) + return reverse('bpcms-document-view', kwargs={'folders': self.get_folder_path(), 'slug': self.slug}) else: - return reverse('bpcms.views.document_view', kwargs={'slug': self.slug}) + return reverse('bpcms-document-view', kwargs={'slug': self.slug}) class Folder(models.Model): title = models.CharField(max_length=150) @@ -106,6 +106,6 @@ class Folder(models.Model): def get_absolute_url(self): if self.parent: - return reverse('bpcms.views.document_view', kwargs={'folders': self.parent.get_path(), 'slug': self.slug}) + return reverse('bpcms-document-view', kwargs={'folders': self.parent.get_path(), 'slug': self.slug}) else: - return reverse('bpcms.views.document_view', kwargs={'slug': self.slug}) + return reverse('bpcms-document-view', kwargs={'slug': self.slug}) diff --git a/sommitrealweird/bpcms/urls.py b/sommitrealweird/bpcms/urls.py index 2d24d30..1a9111f 100644 --- a/sommitrealweird/bpcms/urls.py +++ b/sommitrealweird/bpcms/urls.py @@ -1,9 +1,10 @@ -from django.conf.urls import patterns +from django.conf.urls import url +import bpcms.views -urlpatterns = patterns('', - (r'^$', 'bpcms.views.document_view', {'slug': 'index'}), - (r'^css-docs/(?P[^/]+)$', 'bpcms.views.css_view'), - (r'^(?P[^/]+)/$', 'bpcms.views.document_view'), - (r'^(?P.*)/(?P[^/]+)/$', 'bpcms.views.document_view'), -) +urlpatterns = [ + url(r'^$', bpcms.views.document_view, {'slug': 'index'}, name='bpcms-document-view'), + url(r'^css-docs/(?P[^/]+)$', bpcms.views.css_view), + url(r'^(?P[^/]+)/$', bpcms.views.document_view, name='bpcms-document-view'), + url(r'^(?P.*)/(?P[^/]+)/$', bpcms.views.document_view, name='bpcms-document-view'), +] diff --git a/sommitrealweird/bpcms/views.py b/sommitrealweird/bpcms/views.py index 9cb3e42..0396bf8 100644 --- a/sommitrealweird/bpcms/views.py +++ b/sommitrealweird/bpcms/views.py @@ -1,5 +1,6 @@ from bpcms.models import CSSDocument, Document, Folder -from django.http import Http404, HttpResponse +from django.http import Http404 +from django.shortcuts import render from django.template import RequestContext, loader def document_view(request, slug=None, folders=None): @@ -57,14 +58,12 @@ def document_view(request, slug=None, folders=None): except: raise Http404 template_name = "bpcms/%s.html" %(doc.format,) - t = loader.get_template(template_name) - c = RequestContext(request, - { + c = { "content" : doc.content, "title" : doc.title, "extracss" : doc.extracss.all(), - }) - return HttpResponse(t.render(c)) + } + return render(request, template_name, c) def css_view(request, slug): cssdoc = CSSDocument.objects.get(slug=slug) @@ -72,4 +71,4 @@ def css_view(request, slug): raise Http404() return HttpResponse(cssdoc.content, content_type="text/css") - + diff --git a/sommitrealweird/photo/migrations/0001_initial.py b/sommitrealweird/photo/migrations/0001_initial.py new file mode 100644 index 0000000..d42465c --- /dev/null +++ b/sommitrealweird/photo/migrations/0001_initial.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-06-22 09:40 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import photo.models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Album', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=120)), + ('caption', models.TextField(blank=True, null=True)), + ('slug', models.SlugField()), + ], + ), + migrations.CreateModel( + name='Photo', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('image', models.ImageField(null=True, upload_to=photo.models.get_upload_path)), + ('caption', models.TextField(blank=True, null=True)), + ('order', models.IntegerField(blank=True, null=True)), + ('album', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='photo.Album')), + ], + ), + ] diff --git a/sommitrealweird/photo/migrations/__init__.py b/sommitrealweird/photo/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sommitrealweird/settings.py b/sommitrealweird/settings.py index 723ff4d..70594da 100644 --- a/sommitrealweird/settings.py +++ b/sommitrealweird/settings.py @@ -50,15 +50,10 @@ SECRET_KEY = [random.choice(key_chars) for a in range(0,50)] CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', - 'LOCATION': '%s/tmp' %(topdir), + 'LOCATION': '%s/tmp' %(topdir), } } -TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', -) - MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -70,9 +65,28 @@ MIDDLEWARE_CLASSES = ( ROOT_URLCONF = 'urls' -TEMPLATE_DIRS = ( - os.path.join(topdir, 'templates'), -) +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(topdir, 'templates'),], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.contrib.auth.context_processors.auth', + 'django.template.context_processors.debug', + 'django.template.context_processors.i18n', + 'django.template.context_processors.media', + 'bpcms.context_processors.content_menu', + 'bpcms.context_processors.content_submenu', + 'bpcms.context_processors.content_breadcrumb', + 'blog.context_processors.content_breadcrumb', + 'blog.context_processors.blog_feed', + 'photo.context_processors.content_breadcrumb', + ], + 'debug': True, + }, + }, +] INSTALLED_APPS = ( 'django.contrib.auth', @@ -80,25 +94,12 @@ INSTALLED_APPS = ( 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', - 'django.contrib.comments', 'bpcms', 'generic', 'blog', 'photo', ) -TEMPLATE_CONTEXT_PROCESSORS = ( - 'django.contrib.auth.context_processors.auth', - 'django.core.context_processors.debug', - 'django.core.context_processors.i18n', - 'generic.context_processors.media', - 'bpcms.context_processors.content_menu', - 'bpcms.context_processors.content_submenu', - 'bpcms.context_processors.content_breadcrumb', - 'blog.context_processors.content_breadcrumb', - 'blog.context_processors.blog_feed', - 'photo.context_processors.content_breadcrumb', -) APPEND_SLASH=False diff --git a/sommitrealweird/urls.py b/sommitrealweird/urls.py index 6c9c006..0a4b5f3 100644 --- a/sommitrealweird/urls.py +++ b/sommitrealweird/urls.py @@ -1,6 +1,8 @@ from django.conf.urls import include, url from django.conf.urls.static import static -from settings import MEDIA_ROOT, MEDIA_URL +import bpcms.views +import django.views.static +from settings import MEDIA_ROOT, MEDIA_URL, STATIC_URL from blog.feeds import LatestBlogEntries, LatestBlogEntriesRss from django.contrib import admin @@ -21,15 +23,14 @@ urlpatterns = [ # (r'^sommitrealweird/', include('sommitrealweird.foo.urls')), # Uncomment this for admin: - url(r'^$', 'bpcms.views.document_view', {'slug': 'index'}), - url(r'^media/(?P.*)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT, 'show_indexes': True}), + url(r'^$', bpcms.views.document_view, {'slug': 'index'}), + url(r'^media/(?P.*)$', django.views.static.serve, {'document_root': MEDIA_ROOT, 'show_indexes': True}), url(r'^admin/', include(admin.site.urls)), url(r'^blog/', include('blog.urls')), url(r'^photo/', include('photo.urls')), #url(r'^photos/', include('photo.urls')), - url(r'^css-doc/(?P.*)$', 'bpcms.views.css_view'), + url(r'^css-doc/(?P.*)$', bpcms.views.css_view), url(r'^feeds/rss/blog/', LatestBlogEntriesRss()), url(r'^feeds/blog/', LatestBlogEntries()), - url(r'^comments/', include('django.contrib.comments.urls')), url(r'^', include('bpcms.urls')) -] + static(MEDIA_URL, MEDIA_ROOT) +] + static(STATIC_URL, document_root=MEDIA_ROOT)