From: Brett Parker Date: Wed, 25 Oct 2023 09:14:06 +0000 (+0100) Subject: fix: quick and dirty update to django 4.2 X-Git-Url: https://git.sommitrealweird.co.uk/sommitrealweird.git/commitdiff_plain/29f2eef0ba05968f84c3afad30e1fa105fc56ed3 fix: quick and dirty update to django 4.2 --- diff --git a/sommitrealweird/blog/migrations/0003_alter_blogentry_id_alter_blogsection_id.py b/sommitrealweird/blog/migrations/0003_alter_blogentry_id_alter_blogsection_id.py new file mode 100644 index 0000000..ae77d7c --- /dev/null +++ b/sommitrealweird/blog/migrations/0003_alter_blogentry_id_alter_blogsection_id.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.6 on 2023-10-25 09:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('blog', '0002_auto_20190723_1612'), + ] + + operations = [ + migrations.AlterField( + model_name='blogentry', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='blogsection', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + ] diff --git a/sommitrealweird/blog/templates/blog/blog_index.html b/sommitrealweird/blog/templates/blog/blog_index.html index f2ede84..1773278 100644 --- a/sommitrealweird/blog/templates/blog/blog_index.html +++ b/sommitrealweird/blog/templates/blog/blog_index.html @@ -37,11 +37,11 @@ {% else %} | {% endif %} - {% ifequal paginator_page page %} + {% if paginator_page == page %} {{ page }} {% else %} {{ paginator_page }} - {% endifequal %} + {% endif %} {% endfor %} {% if has_next %} | Next diff --git a/sommitrealweird/blog/urls.py b/sommitrealweird/blog/urls.py index eeeb25b..7ce99ef 100644 --- a/sommitrealweird/blog/urls.py +++ b/sommitrealweird/blog/urls.py @@ -1,14 +1,14 @@ -from django.conf.urls import url +from django.urls import re_path import blog.views from settings import MEDIA_ROOT, MEDIA_URL 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), + re_path(r'^(?P[0-9]{4})/(?P[0-9]{2})/(?P[0-9]{2})/(?P[^/]+)(/|)$', blog.views.blog_view), + re_path(r'^(?P[0-9]{4})(?P[0-9]{2})(?P[0-9]{2})-(?P[^/]+)\.html$', blog.views.blog_view), + re_path(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), + re_path(r'^(?P[0-9]{4})/(?P[0-9]{2})/(?P[0-9]{2})/$', blog.views.blog_view), + re_path(r'^(?P[0-9]{4})/(?P[0-9]{2})/$', blog.views.blog_view), + re_path(r'^(?P[0-9]{4})/$', blog.views.blog_view), + re_path(r'^section/(?P
[^/]*)/$', blog.views.blog_index), + re_path(r'^$', blog.views.blog_index), ] diff --git a/sommitrealweird/bpcms/context_processors.py b/sommitrealweird/bpcms/context_processors.py index e92e8ce..1d254b1 100644 --- a/sommitrealweird/bpcms/context_processors.py +++ b/sommitrealweird/bpcms/context_processors.py @@ -44,9 +44,16 @@ def content_submenu(request): # find where we are in the tree first folderpath = request.path folderpath = re.sub(u'^%s' %(settings.BPCMS_ROOT), '', folderpath) + # right - that should be any prefix got rid of, now traverse the tree till # we've got something - menu_items = cache.get('bpcms_contentmenu_%s' %(folderpath)) + try: + menu_items = cache.get('bpcms_contentmenu_%s' %(folderpath)) + except: + # fail on cache engine or bad key, ignore + return { + 'content_submenu': {}, + } if not menu_items: folder = None diff --git a/sommitrealweird/bpcms/migrations/0003_alter_cssdocument_id_alter_document_folder_and_more.py b/sommitrealweird/bpcms/migrations/0003_alter_cssdocument_id_alter_document_folder_and_more.py new file mode 100644 index 0000000..7a6220d --- /dev/null +++ b/sommitrealweird/bpcms/migrations/0003_alter_cssdocument_id_alter_document_folder_and_more.py @@ -0,0 +1,39 @@ +# Generated by Django 4.2.6 on 2023-10-25 09:33 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('bpcms', '0002_auto_20190723_1612'), + ] + + operations = [ + migrations.AlterField( + model_name='cssdocument', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='document', + name='folder', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='bpcms.folder'), + ), + migrations.AlterField( + model_name='document', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='folder', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='folder', + name='parent', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='bpcms.folder'), + ), + ] diff --git a/sommitrealweird/bpcms/urls.py b/sommitrealweird/bpcms/urls.py index 1a9111f..264af0a 100644 --- a/sommitrealweird/bpcms/urls.py +++ b/sommitrealweird/bpcms/urls.py @@ -1,10 +1,10 @@ -from django.conf.urls import url +from django.urls import re_path import bpcms.views 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'), + re_path(r'^$', bpcms.views.document_view, {'slug': 'index'}, name='bpcms-document-view'), + re_path(r'^css-docs/(?P[^/]+)$', bpcms.views.css_view), + re_path(r'^(?P[^/]+)/$', bpcms.views.document_view, name='bpcms-document-view'), + re_path(r'^(?P.*)/(?P[^/]+)/$', bpcms.views.document_view, name='bpcms-document-view'), ] diff --git a/sommitrealweird/generic/templatetags/xhtml11rst.py b/sommitrealweird/generic/templatetags/xhtml11rst.py index 6d122ba..c3621d4 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_bytes, force_text +from django.utils.encoding import smart_bytes, force_str from django.utils.safestring import mark_safe from generic import docutils_xhtml11 @@ -12,11 +12,11 @@ def restructuredtext(value): except ImportError: if settings.DEBUG: raise template.TemplateSyntaxError("Error in {% restructuredtext %} filter: The Python docutils library isn't installed.") - return force_text(value) + return force_str(value) else: docutils_settings = getattr(settings, "RESTRUCTUREDTEXT_FILTER_SETTINGS", {}) parts = publish_parts(source=smart_bytes(value), writer=docutils_xhtml11.Writer(), settings_overrides=docutils_settings) - return mark_safe(force_text(parts["fragment"])) + return mark_safe(force_str(parts["fragment"])) restructuredtext.is_safe = True register.filter(restructuredtext) diff --git a/sommitrealweird/photo/migrations/0002_alter_album_id_alter_photo_id.py b/sommitrealweird/photo/migrations/0002_alter_album_id_alter_photo_id.py new file mode 100644 index 0000000..1d15883 --- /dev/null +++ b/sommitrealweird/photo/migrations/0002_alter_album_id_alter_photo_id.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.6 on 2023-10-25 09:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('photo', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='album', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='photo', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + ] diff --git a/sommitrealweird/photo/templates/photo/album_list.html b/sommitrealweird/photo/templates/photo/album_list.html index ab5ae6c..9314827 100644 --- a/sommitrealweird/photo/templates/photo/album_list.html +++ b/sommitrealweird/photo/templates/photo/album_list.html @@ -32,11 +32,11 @@ {% else %} | {% endif %} - {% ifequal paginator_page page_obj.number %} + {% if paginator_page == page_obj.number %} {{ paginator_page }} {% else %} {{ paginator_page }} - {% endifequal %} + {% endif %} {% endfor %} {% if page_obj.has_next %} | Next diff --git a/sommitrealweird/photo/templates/photo/photo_list.html b/sommitrealweird/photo/templates/photo/photo_list.html index 5581243..8ccd2dd 100644 --- a/sommitrealweird/photo/templates/photo/photo_list.html +++ b/sommitrealweird/photo/templates/photo/photo_list.html @@ -28,11 +28,11 @@ {% else %} | {% endif %} - {% ifequal paginator_page page_obj.number %} + {% if paginator_page == page_obj.number %} {{ paginator_page }} {% else %} {{ paginator_page }} - {% endifequal %} + {% endif %} {% endfor %} {% if page_obj.has_next %} | Next diff --git a/sommitrealweird/photo/urls.py b/sommitrealweird/photo/urls.py index 3e9d28c..c5de1db 100644 --- a/sommitrealweird/photo/urls.py +++ b/sommitrealweird/photo/urls.py @@ -1,9 +1,9 @@ -from django.conf.urls import url +from django.urls import re_path from photo.models import Album from photo.views import AlbumListView, PhotoListView, PhotoView urlpatterns = [ - url(r'^$', AlbumListView.as_view()), - url(r'^(?P[^/]*)/$', PhotoListView.as_view()), - url(r'^(?P[^/]*)/(?P[0-9]+)/$', PhotoView.as_view()), + re_path(r'^$', AlbumListView.as_view()), + re_path(r'^(?P[^/]*)/$', PhotoListView.as_view()), + re_path(r'^(?P[^/]*)/(?P[0-9]+)/$', PhotoView.as_view()), ] diff --git a/sommitrealweird/settings.py b/sommitrealweird/settings.py index 6eb539f..0f8dae9 100644 --- a/sommitrealweird/settings.py +++ b/sommitrealweird/settings.py @@ -15,6 +15,8 @@ ALLOWED_HOSTS = [ "www.sommitrealweird.co.uk", "www.sommitrealweird.co.uk.", "10.0.3.191", + "127.0.0.1", + "localhost", ] MANAGERS = ADMINS @@ -26,6 +28,11 @@ DATABASES = { } } +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" + +DEBUG = True + + TIME_ZONE = 'Europe/London' LANGUAGE_CODE = 'en-gb' @@ -41,7 +48,7 @@ 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_ROOT = '/home/brettp/python-envs/django/lib/python3.11/site-packages/django/contrib/admin/static/' STATIC_URL = '/static/' import random @@ -62,7 +69,6 @@ MIDDLEWARE = ( 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.admindocs.middleware.XViewMiddleware', ) ROOT_URLCONF = 'urls' @@ -74,6 +80,7 @@ TEMPLATES = [ 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ + 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'django.template.context_processors.debug', diff --git a/sommitrealweird/urls.py b/sommitrealweird/urls.py index 6e7cf99..7313793 100644 --- a/sommitrealweird/urls.py +++ b/sommitrealweird/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import include, url +from django.urls import include, re_path from django.conf.urls.static import static import bpcms.views import django.views.static @@ -23,15 +23,15 @@ 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'^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')), + re_path(r'^$', bpcms.views.document_view, {'slug': 'index'}), + re_path(r'^media/(?P.*)$', django.views.static.serve, {'document_root': MEDIA_ROOT, 'show_indexes': True}), + re_path(r'^static/(?P.*)$', django.views.static.serve, {'document_root': STATIC_ROOT, 'show_indexes': True}), + re_path(r'^admin/', admin.site.urls), + re_path(r'^blog/', include('blog.urls')), + re_path(r'^photo/', include('photo.urls')), #url(r'^photos/', include('photo.urls')), - url(r'^css-doc/(?P.*)$', bpcms.views.css_view), - url(r'^feeds/rss/blog/', LatestBlogEntriesRss()), - url(r'^feeds/blog/', LatestBlogEntries()), - url(r'^', include('bpcms.urls')) + re_path(r'^css-doc/(?P.*)$', bpcms.views.css_view), + re_path(r'^feeds/rss/blog/', LatestBlogEntriesRss()), + re_path(r'^feeds/blog/', LatestBlogEntries()), + re_path(r'^', include('bpcms.urls')) ]