From: Radek Czajka Date: Wed, 3 Apr 2019 10:22:54 +0000 (+0200) Subject: Django 2.2 X-Git-Url: https://git.mdrn.pl/turniej.git/commitdiff_plain/479cb324a4cbc258f3f6de8de1025e7dccb1da2d?hp=32597f46cd79051f9cf213aa53d4996dd3093b8a Django 2.2 --- diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..434b784 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +.PHONY: deploy + + +deploy: turniej/localsettings.py + pip install -r requirements.txt + ./manage.py migrate --noinput + ./manage.py collectstatic --noinput diff --git a/apps/edition1/urls.py b/apps/edition1/urls.py old mode 100755 new mode 100644 index 285808f..76dadd5 --- a/apps/edition1/urls.py +++ b/apps/edition1/urls.py @@ -1,12 +1,14 @@ -from django.conf.urls import patterns, url +from django.conf.urls import url from django.views.generic import TemplateView +from . import views -urlpatterns = patterns('', - url(r'^$', 'edition1.views.home', name='e1_main_page'), + +urlpatterns = [ + url(r'^$', views.home, name='e1_main_page'), url(r'^regulamin/$', TemplateView.as_view(template_name='edition1/rules.html'), name='e1_rules_page'), url(r'^wiecej/$', TemplateView.as_view(template_name='edition1/more.html'), name='e1_more_page'), url(r'^technikalia/$', TemplateView.as_view(template_name='edition1/technical.html'), name='e1_technical_page'), -) +] diff --git a/apps/edition2/urls.py b/apps/edition2/urls.py index 93c4c8c..0cb0f57 100755 --- a/apps/edition2/urls.py +++ b/apps/edition2/urls.py @@ -1,7 +1,7 @@ -from django.conf.urls import patterns, url +from django.conf.urls import url from django.views.generic import TemplateView -urlpatterns = patterns('', +urlpatterns = [ url(r'^$', TemplateView.as_view(template_name='edition2/home.html'), name='e2_main_page'), url(r'^regulamin/$', TemplateView.as_view(template_name='edition2/rules.html'), @@ -10,4 +10,4 @@ urlpatterns = patterns('', name='e2_more_page'), url(r'^technikalia/$', TemplateView.as_view(template_name='edition2/technical.html'), name='e2_technical_page'), -) +] diff --git a/apps/poetry/migrations/0001_initial.py b/apps/poetry/migrations/0001_initial.py index 0586896..81c630c 100644 --- a/apps/poetry/migrations/0001_initial.py +++ b/apps/poetry/migrations/0001_initial.py @@ -47,7 +47,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='poem', name='poet', - field=models.ForeignKey(to='poetry.Poet'), + field=models.ForeignKey(to='poetry.Poet', on_delete=models.CASCADE), preserve_default=True, ), ] diff --git a/apps/poetry/models.py b/apps/poetry/models.py index c0e6c93..58b8caf 100644 --- a/apps/poetry/models.py +++ b/apps/poetry/models.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- import os import subprocess from django.db import models -from django.core.urlresolvers import reverse +from django.urls import reverse from django.conf import settings from poetry.utils import get_hash @@ -61,7 +60,7 @@ class Poem(models.Model): slug = models.SlugField(max_length=50, db_index=True) title = models.CharField(max_length=255, null=True, blank=True) text = models.TextField() - poet = models.ForeignKey(Poet) + poet = models.ForeignKey(Poet, on_delete=models.CASCADE) created_at = models.DateTimeField(auto_now_add=True, editable=False, db_index=True) seen_at = models.DateTimeField(auto_now_add=True, editable=False) view_count = models.IntegerField(default=1) diff --git a/apps/poetry/urls.py b/apps/poetry/urls.py index 50017a5..eb9b4f3 100644 --- a/apps/poetry/urls.py +++ b/apps/poetry/urls.py @@ -1,12 +1,13 @@ -from django.conf.urls import patterns, url +from django.conf.urls import url +from . import views -urlpatterns = patterns('poetry.views', - url(r'^wiersz/(?P[a-zA-Z0-9-]+)/$', 'poem', name='poetry_poem'), - url(r"^$", "main", name="poetry_main"), - url(r"^nowy/$", 'new', name="poetry_new"), - url(r"^konkurs/$", 'contest', name="poetry_contest"), - url(r"^(?P[a-zA-Z0-9-]+)/$", "poet", name="poetry_poet"), - url(r"^(?P[a-zA-Z0-9-]+)/nowy/$", 'new', name="poetry_new"), +urlpatterns = [ + url(r'^wiersz/(?P[a-zA-Z0-9-]+)/$', views.poem, name='poetry_poem'), -) + url(r"^$", views.main, name="poetry_main"), + url(r"^nowy/$", views.new, name="poetry_new"), + url(r"^konkurs/$", views.contest, name="poetry_contest"), + url(r"^(?P[a-zA-Z0-9-]+)/$", views.poet, name="poetry_poet"), + url(r"^(?P[a-zA-Z0-9-]+)/nowy/$", views.new, name="poetry_new"), +] diff --git a/apps/poetry/utils.py b/apps/poetry/utils.py index 0286505..6366f08 100644 --- a/apps/poetry/utils.py +++ b/apps/poetry/utils.py @@ -7,4 +7,4 @@ from hashlib import sha1 def get_hash(seed): sha_digest = sha1(('%d%s' % (time.time(), str(seed)) ).encode('utf-8', 'replace')).digest() - return urlsafe_b64encode(sha_digest).replace(b'=', b'').replace(b'_', b'-').lower() + return urlsafe_b64encode(sha_digest).decode('latin1').replace('=', '').replace('_', '-').lower() diff --git a/fabfile.py b/fabfile.py deleted file mode 100644 index 049085c..0000000 --- a/fabfile.py +++ /dev/null @@ -1,9 +0,0 @@ -from fnpdjango.deploy import * - -env.project_name = 'turniej' -env.hosts = ['giewont.icm.edu.pl'] -env.user = 'lektury' -env.app_path = '/srv/turniej.wolnelektury.pl' -env.services = [ - DebianGunicorn('turniej'), -] diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index aec394f..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1 +0,0 @@ -django-debug-toolbar diff --git a/requirements.txt b/requirements.txt index f7f889f..dcccc9b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ --i https://py.mdrn.pl:8443/simple +-i https://py.mdrn.pl/simple -Django>=1.7,<1.8 -fnpdjango>=0.2,<0.3 +Django>=2.2,<2.3 +fnpdjango==0.4 django-piwik diff --git a/turniej/settings.py b/turniej/settings.py index d09e780..03e2586 100644 --- a/turniej/settings.py +++ b/turniej/settings.py @@ -1,11 +1,9 @@ -# -*- coding: utf-8 -*- # Django settings for turniej project. import os.path PROJECT_DIR = os.path.abspath(os.path.dirname(__file__)) DEBUG = False -TEMPLATE_DEBUG = DEBUG ADMINS = [ # ('Your Name', 'your_email@domain.com'), @@ -88,53 +86,36 @@ STATICFILES_FINDERS = ( # 'django.contrib.staticfiles.finders.DefaultStorageFinder', ) -# List of callables that know how to import templates from various sources. -TEMPLATE_LOADERS = [ - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', -# 'django.template.loaders.eggs.Loader', +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'APP_DIRS': True, + 'DIRS': [ + os.path.join(PROJECT_DIR, 'templates'), + ], + 'OPTIONS': { + 'context_processors': [ + "django.template.context_processors.debug", + "django.template.context_processors.i18n", + "django.template.context_processors.media", + "django.template.context_processors.static", + "django.contrib.messages.context_processors.messages", + "django.template.context_processors.request", + ], + }, + }, ] -MIDDLEWARE_CLASSES = [ +MIDDLEWARE = [ 'django.middleware.common.CommonMiddleware', - #'django.contrib.sessions.middleware.SessionMiddleware', - #'django.middleware.csrf.CsrfViewMiddleware', - #'django.contrib.auth.middleware.AuthenticationMiddleware', - #'django.contrib.messages.middleware.MessageMiddleware', ] ROOT_URLCONF = 'turniej.urls' -TEMPLATE_DIRS = [ - # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. - os.path.join(PROJECT_DIR, 'templates'), -] - -TEMPLATE_CONTEXT_PROCESSORS = ( - #"django.contrib.auth.context_processors.auth", - "django.core.context_processors.debug", - "django.core.context_processors.i18n", - "django.core.context_processors.media", - "django.core.context_processors.static", - "django.contrib.messages.context_processors.messages", - "django.core.context_processors.request", -) -TEMPLATE_CONTEXT_PROCESSORS += ( -) - INSTALLED_APPS = [ - #'django.contrib.auth', - #'django.contrib.contenttypes', - #'django.contrib.sessions', 'django.contrib.sites', - #'django.contrib.messages', 'django.contrib.staticfiles', - # 'django.contrib.admin', - # 'django.contrib.admindocs', - 'piwik', 'fnpdjango', @@ -143,29 +124,6 @@ INSTALLED_APPS = [ 'edition2', ] -# A sample logging configuration. The only tangible logging -# performed by this configuration is to send an email to -# the site admins on every HTTP 500 error. -# See http://docs.djangoproject.com/en/dev/topics/logging for -# more details on how to customize your logging configuration. -LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'handlers': { - 'mail_admins': { - 'level': 'ERROR', - 'class': 'django.utils.log.AdminEmailHandler' - } - }, - 'loggers': { - 'django.request': { - 'handlers': ['mail_admins'], - 'level': 'ERROR', - 'propagate': True, - }, - } -} - POETRY_POEMS_FOR_CONTEST = 20 ALLOWED_HOSTS = [ diff --git a/turniej/urls.py b/turniej/urls.py index 56baf14..eafb8c9 100644 --- a/turniej/urls.py +++ b/turniej/urls.py @@ -1,10 +1,8 @@ -from django.conf.urls import patterns, include, url -from edition2.urls import urlpatterns as e2_urlpatterns +from django.conf.urls import include, url -# from django.contrib import admin -# admin.autodiscover() -urlpatterns = patterns('', +urlpatterns = [ url(r'^2011/', include('edition1.urls')), url(r'^poezja/', include('poetry.urls')), -) + e2_urlpatterns + url(r'', include('edition2.urls')), +]