From: Brett Parker Date: Tue, 23 Jul 2019 17:45:13 +0000 (+0000) Subject: Changes to make it work with django 1.11 and python3 X-Git-Url: https://git.sommitrealweird.co.uk/sommitrealweird.git/commitdiff_plain/2f8f1efa5214444b2e867bde2a6f5297d1f3caea?hp=9e81338188b8277ee838ac19a083c552320097ef Changes to make it work with django 1.11 and python3 --- diff --git a/sommitrealweird/blog/admin.py b/sommitrealweird/blog/admin.py index 88ebb87..daeaa50 100644 --- a/sommitrealweird/blog/admin.py +++ b/sommitrealweird/blog/admin.py @@ -1,4 +1,4 @@ -from models import BlogEntry, BlogSection +from blog.models import BlogEntry, BlogSection from django.contrib import admin class BlogEntryAdmin(admin.ModelAdmin): diff --git a/sommitrealweird/blog/migrations/0002_auto_20190723_1612.py b/sommitrealweird/blog/migrations/0002_auto_20190723_1612.py new file mode 100644 index 0000000..fd86cdb --- /dev/null +++ b/sommitrealweird/blog/migrations/0002_auto_20190723_1612.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.22 on 2019-07-23 16:12 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('blog', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='blogentry', + name='format', + field=models.CharField(choices=[('rst', 'reStructuredText'), ('html', 'HTML')], max_length=10), + ), + ] diff --git a/sommitrealweird/bpcms/admin.py b/sommitrealweird/bpcms/admin.py index cb6d396..972ca06 100644 --- a/sommitrealweird/bpcms/admin.py +++ b/sommitrealweird/bpcms/admin.py @@ -1,4 +1,4 @@ -from models import CSSDocument, Document, Folder +from bpcms.models import CSSDocument, Document, Folder from django.contrib import admin class CSSDocumentAdmin(admin.ModelAdmin): diff --git a/sommitrealweird/bpcms/context_processors.py b/sommitrealweird/bpcms/context_processors.py index 72c335d..e92e8ce 100644 --- a/sommitrealweird/bpcms/context_processors.py +++ b/sommitrealweird/bpcms/context_processors.py @@ -33,7 +33,7 @@ def content_menu(request): pass menu_items.sort( \ - cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower())) + key=lambda x: x['title'].lower()) cache.set('bpcms_mainmenu', menu_items, 3600) return { @@ -87,7 +87,7 @@ def content_submenu(request): ) menu_items.sort( \ - cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower())) + key=lambda x: x['title'].lower()) cache.set('bpcms_contentmenu_%s' %("/".join(folderpath)), menu_items) diff --git a/sommitrealweird/bpcms/migrations/0002_auto_20190723_1612.py b/sommitrealweird/bpcms/migrations/0002_auto_20190723_1612.py new file mode 100644 index 0000000..4b0e00f --- /dev/null +++ b/sommitrealweird/bpcms/migrations/0002_auto_20190723_1612.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.22 on 2019-07-23 16:12 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bpcms', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='document', + name='extracss', + field=models.ManyToManyField(blank=True, to='bpcms.CSSDocument'), + ), + migrations.AlterField( + model_name='document', + name='format', + field=models.CharField(choices=[('rst', 'reStructuredText'), ('html', 'HTML')], max_length=10), + ), + ] diff --git a/sommitrealweird/bpcms/models.py b/sommitrealweird/bpcms/models.py index 6493902..5df5a43 100644 --- a/sommitrealweird/bpcms/models.py +++ b/sommitrealweird/bpcms/models.py @@ -23,7 +23,7 @@ class CSSDocument(models.Model): class Document(models.Model): title = models.CharField(max_length=150) islive = models.BooleanField(default=False) - extracss = models.ManyToManyField(CSSDocument, null=True, blank=True) + extracss = models.ManyToManyField(CSSDocument, blank=True) folder = models.ForeignKey('Folder', null=True, blank=True) format = models.CharField(max_length=10, choices=FORMAT_CHOICES) slug = models.SlugField() diff --git a/sommitrealweird/generic/helpers.py b/sommitrealweird/generic/helpers.py index 6c85aa1..e095d12 100644 --- a/sommitrealweird/generic/helpers.py +++ b/sommitrealweird/generic/helpers.py @@ -54,7 +54,7 @@ def make_thumbnail(imagefile,width=None,height=None): newimg.save("%sw%d/%s" %(thumbs_dir, width, imagefile)) return "%s%s/w%d/%s" %(settings.MEDIA_URL, thumbsdirectory, width, imagefile) - except Exception, e: + except Exception as e: sys.stderr.write("Got exception: %s" %(e,)) elif height != None: diff --git a/sommitrealweird/generic/templatetags/xhtml11rst.py b/sommitrealweird/generic/templatetags/xhtml11rst.py index 3bc212a..6d122ba 100644 --- a/sommitrealweird/generic/templatetags/xhtml11rst.py +++ b/sommitrealweird/generic/templatetags/xhtml11rst.py @@ -1,6 +1,6 @@ from django import template from django.conf import settings -from django.utils.encoding import smart_str, force_unicode +from django.utils.encoding import smart_bytes, force_text from django.utils.safestring import mark_safe from generic import docutils_xhtml11 @@ -11,12 +11,12 @@ def restructuredtext(value): from docutils.core import publish_parts except ImportError: if settings.DEBUG: - raise template.TemplateSyntaxError, "Error in {% restructuredtext %} filter: The Python docutils library isn't installed." - return force_unicode(value) + raise template.TemplateSyntaxError("Error in {% restructuredtext %} filter: The Python docutils library isn't installed.") + return force_text(value) else: docutils_settings = getattr(settings, "RESTRUCTUREDTEXT_FILTER_SETTINGS", {}) - parts = publish_parts(source=smart_str(value), writer=docutils_xhtml11.Writer(), settings_overrides=docutils_settings) - return mark_safe(force_unicode(parts["fragment"])) + parts = publish_parts(source=smart_bytes(value), writer=docutils_xhtml11.Writer(), settings_overrides=docutils_settings) + return mark_safe(force_text(parts["fragment"])) restructuredtext.is_safe = True register.filter(restructuredtext) diff --git a/sommitrealweird/manage.py b/sommitrealweird/manage.py index f9726f9..4eb6f34 100755 --- a/sommitrealweird/manage.py +++ b/sommitrealweird/manage.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import sys diff --git a/sommitrealweird/photo/admin.py b/sommitrealweird/photo/admin.py index 6f71cbe..5a7ae2f 100644 --- a/sommitrealweird/photo/admin.py +++ b/sommitrealweird/photo/admin.py @@ -1,4 +1,4 @@ -from models import Album, Photo +from photo.models import Album, Photo from django.contrib import admin class AlbumAdmin(admin.ModelAdmin): diff --git a/sommitrealweird/photo/context_processors.py b/sommitrealweird/photo/context_processors.py index b00e5e1..74e4f8f 100644 --- a/sommitrealweird/photo/context_processors.py +++ b/sommitrealweird/photo/context_processors.py @@ -1,5 +1,5 @@ from django.conf import settings -from models import Album, Photo +from photo.models import Album, Photo import re def content_breadcrumb(request): diff --git a/sommitrealweird/photo/urls.py b/sommitrealweird/photo/urls.py index d5666e5..3e9d28c 100644 --- a/sommitrealweird/photo/urls.py +++ b/sommitrealweird/photo/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import url -from models import Album -from views import AlbumListView, PhotoListView, PhotoView +from photo.models import Album +from photo.views import AlbumListView, PhotoListView, PhotoView urlpatterns = [ url(r'^$', AlbumListView.as_view()), diff --git a/sommitrealweird/photo/views.py b/sommitrealweird/photo/views.py index 8501a6f..fea7dd3 100644 --- a/sommitrealweird/photo/views.py +++ b/sommitrealweird/photo/views.py @@ -1,6 +1,6 @@ from django.views.generic import ListView, DetailView from django.http import Http404 -from models import Album, Photo +from photo.models import Album, Photo class AlbumListView(ListView): model = Album diff --git a/sommitrealweird/settings.py b/sommitrealweird/settings.py index 70594da..67b8f32 100644 --- a/sommitrealweird/settings.py +++ b/sommitrealweird/settings.py @@ -40,11 +40,12 @@ USE_I18N = True MEDIA_ROOT = os.path.join(topdir, 'media') + os.sep MEDIA_URL = '/media/' +STATIC_ROOT = '/usr/lib/python3/dist-packages/django/contrib/admin/static/' STATIC_URL = '/static/' import random import string -key_chars = "%s%s%s" % (string.letters, string.digits, '+-()_#~') +key_chars = "%s%s%s" % (string.ascii_letters, string.digits, '+-()_#~') SECRET_KEY = [random.choice(key_chars) for a in range(0,50)] CACHES = { @@ -73,6 +74,7 @@ TEMPLATES = [ 'OPTIONS': { 'context_processors': [ 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', 'django.template.context_processors.debug', 'django.template.context_processors.i18n', 'django.template.context_processors.media', diff --git a/sommitrealweird/urls.py b/sommitrealweird/urls.py index 0a4b5f3..6e7cf99 100644 --- a/sommitrealweird/urls.py +++ b/sommitrealweird/urls.py @@ -2,7 +2,7 @@ from django.conf.urls import include, url from django.conf.urls.static import static import bpcms.views import django.views.static -from settings import MEDIA_ROOT, MEDIA_URL, STATIC_URL +from settings import MEDIA_ROOT, MEDIA_URL, STATIC_ROOT, STATIC_URL from blog.feeds import LatestBlogEntries, LatestBlogEntriesRss from django.contrib import admin @@ -25,7 +25,8 @@ urlpatterns = [ # 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'^admin/', include(admin.site.urls)), + url(r'^static/(?P.*)$', django.views.static.serve, {'document_root': STATIC_ROOT, 'show_indexes': True}), + url(r'^admin/', admin.site.urls), url(r'^blog/', include('blog.urls')), url(r'^photo/', include('photo.urls')), #url(r'^photos/', include('photo.urls')), @@ -33,4 +34,4 @@ urlpatterns = [ url(r'^feeds/rss/blog/', LatestBlogEntriesRss()), url(r'^feeds/blog/', LatestBlogEntries()), url(r'^', include('bpcms.urls')) -] + static(STATIC_URL, document_root=MEDIA_ROOT) +] diff --git a/templates/base.html b/templates/base.html index 552a510..eacc07e 100644 --- a/templates/base.html +++ b/templates/base.html @@ -3,7 +3,8 @@ {% block title %}{{ title }}{% endblock %} - + {% load static %} + {% block extrahead %}{% endblock %}