migrate to python3 and update django

This commit is contained in:
j 2025-01-10 15:23:37 +05:30
parent 0a5af976b8
commit 5c0c2a2c07
24 changed files with 77 additions and 82 deletions

View File

@ -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

View File

@ -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<shortname>.+)/$', views.texts, name='text'),
url(r'^events/(?P<shortname>.+)/$', views.events, name='event'),
url(r'^projects/(?P<shortname>.+)/$', views.projects, name='project'),
url(r'^works/(?P<shortname>.+)/$', 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<shortname>.+)/$', views.texts, name='text'),
re_path(r'^events/(?P<shortname>.+)/$', views.events, name='event'),
re_path(r'^projects/(?P<shortname>.+)/$', views.projects, name='project'),
re_path(r'^works/(?P<shortname>.+)/$', 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<shortname>\w+)/$', views.page, name='page')
re_path(r'^(?P<shortname>\w+)/$', views.page, name='page')
]

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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'<a href="{}"><img src="{}"></a>'.format(self.get_absolute_url(), src))
return mark_safe('<a href="{}"><img src="{}"></a>'.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)

View File

@ -8,7 +8,7 @@ from ..models import Content
register = template.Library()
@register.assignment_tag
@register.simple_tag
def available_content():
sections = []

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from datetime import datetime, timedelta
import re

View File

@ -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

View File

@ -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