From 5c0c2a2c07cc51aecf9e3745382ab95b53b2efb9 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 10 Jan 2025 15:23:37 +0530 Subject: [PATCH] migrate to python3 and update django --- camp/settings.py | 8 +-- camp/urls.py | 53 ++++++++++--------- content/admin.py | 2 +- content/apps.py | 7 +-- content/migrations/0001_initial.py | 2 +- content/migrations/0002_auto_20170621_0915.py | 2 +- content/migrations/0003_auto_20171218_1103.py | 2 +- content/migrations/0004_auto_20171218_1149.py | 2 +- content/migrations/0005_auto_20171219_1032.py | 2 +- content/migrations/0006_auto_20171219_1243.py | 2 +- content/migrations/0007_content_gallery.py | 2 +- content/migrations/0008_auto_20171219_1311.py | 2 +- content/migrations/0009_auto_20171219_1320.py | 2 +- content/migrations/0010_auto_20180222_1319.py | 2 +- content/migrations/0011_auto_20180822_1832.py | 2 +- .../0012_content_related_content.py | 2 +- content/migrations/0013_related.py | 2 +- content/migrations/0014_migrate_shortname.py | 2 +- content/models.py | 44 +++++++-------- content/templatetags/available_content.py | 2 +- content/tests.py | 2 +- content/views.py | 2 +- manage.py | 7 +-- requirements.txt | 4 +- 24 files changed, 77 insertions(+), 82 deletions(-) diff --git a/camp/settings.py b/camp/settings.py index be1ac9e..15ec172 100644 --- a/camp/settings.py +++ b/camp/settings.py @@ -142,18 +142,20 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'static') MARKDOWNX_MEDIA_PATH = 'images/markdown' MARKDOWNX_EDITOR_RESIZABLE = True -MEDIA_URL = '/static/images/' +MEDIA_URL = '/images/' MEDIA_ROOT = os.path.join(BASE_DIR, 'data/images') -IMAGE_PREFIX = 'http://studio.camp/images/' +IMAGE_PREFIX = 'https://studio.camp/images/' CONTACT_FROM_EMAIL = 'contact@studio.camp' CONTACT_TO_EMAIL = ['contact@studio.camp'] DATA_UPLOAD_MAX_MEMORY_SIZE = 150 * 1024 * 1024 +DEFAULT_AUTO_FIELD = "django.db.models.AutoField" + try: - from local_settings import * + from .local_settings import * except: pass diff --git a/camp/urls.py b/camp/urls.py index 764d40c..cae8afd 100644 --- a/camp/urls.py +++ b/camp/urls.py @@ -14,7 +14,8 @@ Including another URLconf 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf import settings -from django.conf.urls import url, include +from django.urls import include, re_path + from django.conf.urls.static import static from django.contrib import admin from django.views.generic import RedirectView @@ -27,40 +28,40 @@ from content import views urlpatterns = [ - url(r'^admin/', admin.site.urls), - url(r'^$', views.index, name='index'), + re_path(r'^admin/', admin.site.urls), + re_path(r'^$', views.index, name='index'), - url(r'^.*index.php$', views.redirect_index, name='redirect_index'), - url(r'^.*event.php$', views.redirect_event, name='redirect_event'), - url(r'^.*(/images/.*)$', views.redirect_images, name='redirect_images'), - url(r'directions.html', RedirectView.as_view(url='/directions/')), - url(r'campstudio.html', RedirectView.as_view(url='/directions/')), + re_path(r'^.*index.php$', views.redirect_index, name='redirect_index'), + re_path(r'^.*event.php$', views.redirect_event, name='redirect_event'), + re_path(r'^.*(/images/.*)$', views.redirect_images, name='redirect_images'), + re_path(r'directions.html', RedirectView.as_view(url='/directions/')), + re_path(r'campstudio.html', RedirectView.as_view(url='/directions/')), - url(r'^contact/$', views.contact), + re_path(r'^contact/$', views.contact), - url(r'^texts/index/$', views.section_list, {'section': 'Texts'}, name='texts_list'), - url(r'^events/index/$', views.section_list, {'section': 'Events'}, name='events_list'), - url(r'^projects/index/$', views.section_list, {'section': 'Projects'}, name='projects_list'), - url(r'^works/index/$', views.section_list, {'section': 'Works'}, name='works_list'), + re_path(r'^texts/index/$', views.section_list, {'section': 'Texts'}, name='texts_list'), + re_path(r'^events/index/$', views.section_list, {'section': 'Events'}, name='events_list'), + re_path(r'^projects/index/$', views.section_list, {'section': 'Projects'}, name='projects_list'), + re_path(r'^works/index/$', views.section_list, {'section': 'Works'}, name='works_list'), - url(r'^texts/(?P.+)/$', views.texts, name='text'), - url(r'^events/(?P.+)/$', views.events, name='event'), - url(r'^projects/(?P.+)/$', views.projects, name='project'), - url(r'^works/(?P.+)/$', views.works, name='work'), - url(r'^works/$', views.works, name='works'), - url(r'^projects/$', views.projects, name='projects'), - url(r'^events/$', views.events, name='events'), - url(r'^texts/$', views.texts, name='texts'), - url(r'^search/$', views.search, name='search'), - url(r'^markdownx/', include(markdownx)), - url(r'^photologue/', include('photologue.urls', namespace='photologue')), - url(r'^gallerylist/$', GalleryListView.as_view(), name='gallery-list'), + re_path(r'^texts/(?P.+)/$', views.texts, name='text'), + re_path(r'^events/(?P.+)/$', views.events, name='event'), + re_path(r'^projects/(?P.+)/$', views.projects, name='project'), + re_path(r'^works/(?P.+)/$', views.works, name='work'), + re_path(r'^works/$', views.works, name='works'), + re_path(r'^projects/$', views.projects, name='projects'), + re_path(r'^events/$', views.events, name='events'), + re_path(r'^texts/$', views.texts, name='texts'), + re_path(r'^search/$', views.search, name='search'), + re_path(r'^markdownx/', include(markdownx)), + re_path(r'^photologue/', include('photologue.urls', namespace='photologue')), + re_path(r'^gallerylist/$', GalleryListView.as_view(), name='gallery-list'), ] if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns += [ - url(r'^(?P\w+)/$', views.page, name='page') + re_path(r'^(?P\w+)/$', views.page, name='page') ] diff --git a/content/admin.py b/content/admin.py index ec542b0..4adbf87 100644 --- a/content/admin.py +++ b/content/admin.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals + from django import forms from django.contrib import admin from markdownx.admin import MarkdownxModelAdmin diff --git a/content/apps.py b/content/apps.py index fd66892..bb66ec0 100644 --- a/content/apps.py +++ b/content/apps.py @@ -1,8 +1,5 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.apps import AppConfig -class ContentConfig(AppConfig): - name = 'content' +class RegistrarConfig(AppConfig): + name = "content" diff --git a/content/migrations/0001_initial.py b/content/migrations/0001_initial.py index c1e953d..bdcb008 100644 --- a/content/migrations/0001_initial.py +++ b/content/migrations/0001_initial.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Generated by Django 1.11.1 on 2017-06-10 11:51 -from __future__ import unicode_literals + from django.db import migrations, models import django.db.models.deletion diff --git a/content/migrations/0002_auto_20170621_0915.py b/content/migrations/0002_auto_20170621_0915.py index b86aad6..8baa8d2 100644 --- a/content/migrations/0002_auto_20170621_0915.py +++ b/content/migrations/0002_auto_20170621_0915.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Generated by Django 1.11.1 on 2017-06-21 09:15 -from __future__ import unicode_literals + from django.db import migrations, models import markdownx.models diff --git a/content/migrations/0003_auto_20171218_1103.py b/content/migrations/0003_auto_20171218_1103.py index af82c55..e8d0cf1 100644 --- a/content/migrations/0003_auto_20171218_1103.py +++ b/content/migrations/0003_auto_20171218_1103.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Generated by Django 1.11.8 on 2017-12-18 11:03 -from __future__ import unicode_literals + import django.core.validators from django.db import migrations, models diff --git a/content/migrations/0004_auto_20171218_1149.py b/content/migrations/0004_auto_20171218_1149.py index 397cb21..d23e2ae 100644 --- a/content/migrations/0004_auto_20171218_1149.py +++ b/content/migrations/0004_auto_20171218_1149.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Generated by Django 1.11.8 on 2017-12-18 11:49 -from __future__ import unicode_literals + from django.db import migrations, models import markdownx.models diff --git a/content/migrations/0005_auto_20171219_1032.py b/content/migrations/0005_auto_20171219_1032.py index 59f17c1..99c8565 100644 --- a/content/migrations/0005_auto_20171219_1032.py +++ b/content/migrations/0005_auto_20171219_1032.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Generated by Django 1.11.7 on 2017-12-19 10:32 -from __future__ import unicode_literals + from django.db import migrations, models import django.db.models.deletion diff --git a/content/migrations/0006_auto_20171219_1243.py b/content/migrations/0006_auto_20171219_1243.py index 1fa9495..a54c961 100644 --- a/content/migrations/0006_auto_20171219_1243.py +++ b/content/migrations/0006_auto_20171219_1243.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Generated by Django 1.11.7 on 2017-12-19 12:43 -from __future__ import unicode_literals + from django.db import migrations, models diff --git a/content/migrations/0007_content_gallery.py b/content/migrations/0007_content_gallery.py index d867345..63a74e8 100644 --- a/content/migrations/0007_content_gallery.py +++ b/content/migrations/0007_content_gallery.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Generated by Django 1.11.8 on 2017-12-19 13:06 -from __future__ import unicode_literals + from django.db import migrations, models import django.db.models.deletion diff --git a/content/migrations/0008_auto_20171219_1311.py b/content/migrations/0008_auto_20171219_1311.py index bc3415f..9e7a33a 100644 --- a/content/migrations/0008_auto_20171219_1311.py +++ b/content/migrations/0008_auto_20171219_1311.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Generated by Django 1.11.8 on 2017-12-19 13:11 -from __future__ import unicode_literals + from django.db import migrations, models diff --git a/content/migrations/0009_auto_20171219_1320.py b/content/migrations/0009_auto_20171219_1320.py index 359c876..a79e809 100644 --- a/content/migrations/0009_auto_20171219_1320.py +++ b/content/migrations/0009_auto_20171219_1320.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Generated by Django 1.11.8 on 2017-12-19 13:20 -from __future__ import unicode_literals + from django.db import migrations, models diff --git a/content/migrations/0010_auto_20180222_1319.py b/content/migrations/0010_auto_20180222_1319.py index b927b62..3070efb 100644 --- a/content/migrations/0010_auto_20180222_1319.py +++ b/content/migrations/0010_auto_20180222_1319.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Generated by Django 1.11.7 on 2018-02-22 13:19 -from __future__ import unicode_literals + from django.db import migrations, models import photologue.models diff --git a/content/migrations/0011_auto_20180822_1832.py b/content/migrations/0011_auto_20180822_1832.py index b610160..8c5d51e 100644 --- a/content/migrations/0011_auto_20180822_1832.py +++ b/content/migrations/0011_auto_20180822_1832.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Generated by Django 1.11.8 on 2018-08-22 18:32 -from __future__ import unicode_literals + import django.core.validators from django.db import migrations, models diff --git a/content/migrations/0012_content_related_content.py b/content/migrations/0012_content_related_content.py index fe71183..af78035 100644 --- a/content/migrations/0012_content_related_content.py +++ b/content/migrations/0012_content_related_content.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Generated by Django 1.11.8 on 2018-08-22 19:08 -from __future__ import unicode_literals + from django.db import migrations import sortedm2m.fields diff --git a/content/migrations/0013_related.py b/content/migrations/0013_related.py index ff9ab5a..85e3df2 100644 --- a/content/migrations/0013_related.py +++ b/content/migrations/0013_related.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Generated by Django 1.11.8 on 2018-08-22 19:08 -from __future__ import unicode_literals + from django.db import migrations diff --git a/content/migrations/0014_migrate_shortname.py b/content/migrations/0014_migrate_shortname.py index dd520eb..8eac7ca 100644 --- a/content/migrations/0014_migrate_shortname.py +++ b/content/migrations/0014_migrate_shortname.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Generated by Django 1.11.8 on 2018-08-22 19:08 -from __future__ import unicode_literals + from django.db import migrations diff --git a/content/models.py b/content/models.py index b4330e4..cf79f41 100644 --- a/content/models.py +++ b/content/models.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals + from django.conf import settings from django.core.validators import MaxLengthValidator from django.db import models from django.utils.html import mark_safe -from django.utils.encoding import python_2_unicode_compatible from django.db.models.signals import m2m_changed from django.dispatch import receiver from django.utils.functional import cached_property @@ -75,9 +74,8 @@ class Comments(models.Model): #not used db_table = 'comments' -@python_2_unicode_compatible class Content(models.Model): - type = models.ForeignKey("ContentTypes", db_column="type") + type = models.ForeignKey("ContentTypes", db_column="type", on_delete=models.CASCADE) shortname = models.CharField('Slug', db_column='shortName', max_length=255, unique=True) title = models.CharField(max_length=255) header = MarkdownxField(blank=True, null=True, default='') @@ -91,7 +89,7 @@ class Content(models.Model): opttext3 = models.TextField(db_column='optText3', blank=True, null=True) # Field name made lowercase. technotes = models.TextField(db_column='technotes', blank=True, null=True) image = models.CharField(max_length=150, blank=True, null=True, editable=False) - photo = models.ForeignKey(Photo, null=True, blank=True, related_name="main_photo") + photo = models.ForeignKey(Photo, null=True, blank=True, related_name="main_photo", on_delete=models.SET_NULL) postedby = models.CharField(db_column='postedBy', max_length=50, blank=True, null=True) # Field name made lowercase. datestart = models.DateField(db_column='dateStart', blank=True, null=True) # Field name made lowercase. @@ -100,14 +98,14 @@ class Content(models.Model): datemodified = models.DateTimeField(db_column='dateModified', blank=True, null=True, auto_now=True) # Field name made lowercase. published = models.BooleanField(default=False) featured = models.BooleanField(default=False) - view = models.ForeignKey("Views", null=True, blank=True, db_column="view", editable=False) + view = models.ForeignKey("Views", null=True, blank=True, db_column="view", editable=False, on_delete=models.SET_NULL) place = models.CharField(max_length=255, null=True, blank=True) parents = models.ManyToManyField('Content', through='ContentContent', related_name="children") - related_content = SortedManyToManyField('Content', null=True, blank=True, related_name='reverse_related_content') + related_content = SortedManyToManyField('Content', blank=True, related_name='reverse_related_content') resources = models.ManyToManyField('Resources', through='ContentResource', related_name="content") - gallery = models.ForeignKey(Gallery, null=True, blank=True, related_name="content") + gallery = models.ForeignKey(Gallery, null=True, blank=True, related_name="content", on_delete=models.SET_NULL) # delete after migration parentid = models.IntegerField(null=True, db_column='parentID', blank=True, editable=False) @@ -154,7 +152,7 @@ class Content(models.Model): else: src = settings.IMAGE_PREFIX + self.image if src: - return mark_safe(u''.format(self.get_absolute_url(), src)) + return mark_safe(''.format(self.get_absolute_url(), src)) @cached_property def image_url(self): @@ -216,10 +214,9 @@ def post_save_reverse(sender, **kwargs): c = kwargs['instance'] c.reverse() -@python_2_unicode_compatible class ContentContent(models.Model): - contentid1 = models.ForeignKey("content", db_column='contentID1', related_name="child") # Field name made lowercase. - contentid2 = models.ForeignKey("content", db_column='contentID2', related_name="parent") # Field name made lowercase. + contentid1 = models.ForeignKey("content", db_column='contentID1', related_name="child", on_delete=models.CASCADE) # Field name made lowercase. + contentid2 = models.ForeignKey("content", db_column='contentID2', related_name="parent", on_delete=models.CASCADE) # Field name made lowercase. def __str__(self): return self.contentid1.title @@ -247,10 +244,9 @@ class ContentKeyword(models.Model): db_table = 'content_keyword' -@python_2_unicode_compatible class ContentResource(models.Model): - contentid = models.ForeignKey('Content', db_column='contentID') - resourceid = models.ForeignKey('Resources', db_column='resourceID') + contentid = models.ForeignKey('Content', db_column='contentID', on_delete=models.CASCADE) + resourceid = models.ForeignKey('Resources', db_column='resourceID', on_delete=models.CASCADE) def __str__(self): return self.resource.href @@ -260,7 +256,6 @@ class ContentResource(models.Model): db_table = 'content_resource' -@python_2_unicode_compatible class ContentTypes(models.Model): id = models.IntegerField(primary_key=True) name = models.CharField(max_length=255) @@ -283,7 +278,6 @@ class Keywords(models.Model): db_table = 'keywords' -@python_2_unicode_compatible class People(models.Model): #not used name = models.CharField(max_length=255, blank=True, null=True) email = models.CharField(max_length=255, blank=True, null=True) @@ -306,8 +300,8 @@ class People(models.Model): #not used class PersonContent(models.Model): - personid = models.ForeignKey("people", db_column="personID") - contentid = models.ForeignKey("content", db_column="contentID") + personid = models.ForeignKey("people", db_column="personID", on_delete=models.CASCADE) + contentid = models.ForeignKey("content", db_column="contentID", on_delete=models.CASCADE) level = models.IntegerField() class Meta: @@ -316,8 +310,8 @@ class PersonContent(models.Model): class PersonResource(models.Model): - personid = models.ForeignKey("people", db_column="personID") - resourceid = models.ForeignKey("resources", db_column="resourceID") + personid = models.ForeignKey("people", db_column="personID", on_delete=models.CASCADE) + resourceid = models.ForeignKey("resources", db_column="resourceID", on_delete=models.CASCADE) class Meta: # managed = False @@ -370,7 +364,7 @@ class Resources(models.Model): db_table = 'resources' class File(models.Model): - content = models.ForeignKey('Content') + content = models.ForeignKey('Content', on_delete=models.CASCADE) file = models.FileField(upload_to='files') description = models.TextField(blank=True, null=True) date = models.DateTimeField(auto_now_add=True) @@ -387,15 +381,14 @@ class File(models.Model): return self.description or self.file.name class Image(models.Model): - content = models.ForeignKey('Content', related_name='images') + content = models.ForeignKey('Content', related_name='images', on_delete=models.CASCADE) image = models.ImageField(upload_to='camp/static/images') description = models.TextField(blank=True, null=True) date = models.DateTimeField(auto_now_add=True) order = models.IntegerField(blank=True, null=True) -@python_2_unicode_compatible class Link(models.Model): - content = models.ForeignKey('Content') + content = models.ForeignKey('Content', on_delete=models.CASCADE) url = models.URLField(max_length=4096) description = models.TextField(blank=True, null=True) date = models.DateTimeField(auto_now_add=True) @@ -424,7 +417,6 @@ class Videos(models.Model): # not used db_table = 'videos' -@python_2_unicode_compatible class Views(models.Model): name = models.CharField(max_length=255) href = models.CharField(max_length=255, blank=True, null=True) diff --git a/content/templatetags/available_content.py b/content/templatetags/available_content.py index 74cf4e1..3f06e7a 100644 --- a/content/templatetags/available_content.py +++ b/content/templatetags/available_content.py @@ -8,7 +8,7 @@ from ..models import Content register = template.Library() -@register.assignment_tag +@register.simple_tag def available_content(): sections = [] diff --git a/content/tests.py b/content/tests.py index 5982e6b..f067dca 100644 --- a/content/tests.py +++ b/content/tests.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals + from django.test import TestCase diff --git a/content/views.py b/content/views.py index 256bdc4..f76e420 100644 --- a/content/views.py +++ b/content/views.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals + from datetime import datetime, timedelta import re diff --git a/manage.py b/manage.py index ded56ea..4f2d8aa 100755 --- a/manage.py +++ b/manage.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import sys @@ -6,7 +6,8 @@ def activate_venv(base): if os.path.exists(base): old_os_path = os.environ.get('PATH', '') os.environ['PATH'] = os.path.join(base, 'bin') + os.pathsep + old_os_path - site_packages = os.path.join(base, 'lib', 'python%s' % sys.version[:3], 'site-packages') + version = "%s.%s" % (sys.version_info.major, sys.version_info.minor) + site_packages = os.path.join(base, "lib", "python%s" % version, "site-packages") prev_sys_path = list(sys.path) import site site.addsitedir(site_packages) @@ -23,7 +24,7 @@ def activate_venv(base): if __name__ == "__main__": root_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) - activate_venv(os.path.normpath(os.path.join(root_dir, 'venv'))) + activate_venv(os.path.normpath(os.path.join(root_dir, '.venv'))) os.environ.setdefault("DJANGO_SETTINGS_MODULE", "camp.settings") from django.core.management import execute_from_command_line diff --git a/requirements.txt b/requirements.txt index e73e603..165ed24 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -django<2.0 +django<5.0 django-markdownx django-photologue django-braces @@ -6,3 +6,5 @@ django-app-namespace-template-loader ox gunicorn django_extensions +psycopg2-binary +lxml