From 736ea0594dc3badc57396e951229006e2669123a Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Sun, 22 Sep 2019 22:26:12 +0200 Subject: [PATCH 1/1] Django 2.2. --- NOTICE | 4 +- README.rst | 2 +- apps/quiz/admin.py | 1 - apps/quiz/forms.py | 1 - apps/quiz/middleware.py | 3 +- apps/quiz/migrations/0001_initial.py | 15 ++- .../migrations/0002_auto_20190922_2220.py | 31 ++++++ apps/quiz/models.py | 30 +++--- apps/quiz/templatetags/quiz_tags.py | 1 - apps/quiz/urls.py | 14 +-- apps/quiz/views.py | 1 - fabfile.py | 11 --- koedquiz/settings.py | 99 +++++-------------- koedquiz/urls.py | 15 ++- requirements-dev.txt | 5 - requirements.txt | 3 +- 16 files changed, 92 insertions(+), 144 deletions(-) create mode 100644 apps/quiz/migrations/0002_auto_20190922_2220.py delete mode 100644 fabfile.py delete mode 100644 requirements-dev.txt diff --git a/NOTICE b/NOTICE index bd4e069..3aa74d2 100644 --- a/NOTICE +++ b/NOTICE @@ -1,7 +1,7 @@ KOED-Quiz - Copyright © 2011,2012 Fundacja Nowoczesna Polska + Copyright © 2011,2012,2014,2019 Fundacja Nowoczesna Polska For full list of contributors see AUTHORS section in README. @@ -16,4 +16,4 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . \ No newline at end of file + along with this program. If not, see . diff --git a/README.rst b/README.rst index e365622..0240f89 100644 --- a/README.rst +++ b/README.rst @@ -4,7 +4,7 @@ KOED-Quiz License ------- - Copyright © 2011,2012 Fundacja Nowoczesna Polska + Copyright © 2011,2012,2014,2019 Fundacja Nowoczesna Polska For full list of contributors see AUTHORS section at the end. diff --git a/apps/quiz/admin.py b/apps/quiz/admin.py index 6a2137c..ea058b5 100644 --- a/apps/quiz/admin.py +++ b/apps/quiz/admin.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of KOED-Quiz, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # diff --git a/apps/quiz/forms.py b/apps/quiz/forms.py index 2361cae..a51f632 100644 --- a/apps/quiz/forms.py +++ b/apps/quiz/forms.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of KOED-Quiz, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # diff --git a/apps/quiz/middleware.py b/apps/quiz/middleware.py index 3cde07d..1cc3173 100644 --- a/apps/quiz/middleware.py +++ b/apps/quiz/middleware.py @@ -1,5 +1,6 @@ +from django.utils.deprecation import MiddlewareMixin from .models import Quiz -class CurrentQuizMiddleware(object): +class CurrentQuizMiddleware(MiddlewareMixin): def process_request(self, request): request.current_quiz = Quiz.current(request) diff --git a/apps/quiz/migrations/0001_initial.py b/apps/quiz/migrations/0001_initial.py index ec6a003..eef1792 100644 --- a/apps/quiz/migrations/0001_initial.py +++ b/apps/quiz/migrations/0001_initial.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import models, migrations @@ -45,7 +42,7 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Quiz', fields=[ - ('site_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='sites.Site')), + ('site_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='sites.Site', on_delete=models.CASCADE)), ('description', models.TextField()), ('footer', models.TextField(null=True, blank=True)), ], @@ -62,7 +59,7 @@ class Migration(migrations.Migration): ('slug', models.SlugField()), ('title', models.CharField(max_length=255)), ('text', models.TextField()), - ('quiz', models.ForeignKey(to='quiz.Quiz')), + ('quiz', models.ForeignKey(to='quiz.Quiz', on_delete=models.CASCADE)), ], options={ 'ordering': ['quiz', 'title'], @@ -74,7 +71,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='question', name='quiz', - field=models.ForeignKey(to='quiz.Quiz'), + field=models.ForeignKey(to='quiz.Quiz', on_delete=models.CASCADE), preserve_default=True, ), migrations.AlterUniqueTogether( @@ -84,19 +81,19 @@ class Migration(migrations.Migration): migrations.AddField( model_name='answer', name='go_to', - field=models.ForeignKey(related_name='go_tos', blank=True, to='quiz.Question', null=True), + field=models.ForeignKey(related_name='go_tos', blank=True, to='quiz.Question', null=True, on_delete=models.CASCADE), preserve_default=True, ), migrations.AddField( model_name='answer', name='question', - field=models.ForeignKey(to='quiz.Question'), + field=models.ForeignKey(to='quiz.Question', on_delete=models.CASCADE), preserve_default=True, ), migrations.AddField( model_name='answer', name='result', - field=models.ForeignKey(blank=True, to='quiz.Result', null=True), + field=models.ForeignKey(blank=True, to='quiz.Result', null=True, on_delete=models.CASCADE), preserve_default=True, ), ] diff --git a/apps/quiz/migrations/0002_auto_20190922_2220.py b/apps/quiz/migrations/0002_auto_20190922_2220.py new file mode 100644 index 0000000..7db105b --- /dev/null +++ b/apps/quiz/migrations/0002_auto_20190922_2220.py @@ -0,0 +1,31 @@ +# Generated by Django 2.2.5 on 2019-09-22 22:20 + +import django.contrib.sites.models +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('quiz', '0001_initial'), + ] + + operations = [ + migrations.AlterModelManagers( + name='quiz', + managers=[ + ('objects', django.contrib.sites.models.SiteManager()), + ], + ), + migrations.AlterField( + model_name='answer', + name='go_to', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='go_tos', to='quiz.Question'), + ), + migrations.AlterField( + model_name='answer', + name='result', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='quiz.Result'), + ), + ] diff --git a/apps/quiz/models.py b/apps/quiz/models.py index 0690f12..f6cdc4a 100644 --- a/apps/quiz/models.py +++ b/apps/quiz/models.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- # This file is part of KOED-Quiz, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.db import models from django.contrib.sites.models import Site -from django.utils.encoding import python_2_unicode_compatible +from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from django.conf import settings @@ -20,14 +19,16 @@ class Quiz(Site): @classmethod def current(cls, request): - return cls.objects.get(domain=request.get_host().rstrip('.')) + try: + return cls.objects.get(domain=request.get_host().rstrip('.')) + except cls.DoesNotExist: + pass def start(self): return self.question_set.all()[0] - @models.permalink def get_absolute_url(self): - return ('quiz', ) + return reverse('quiz') def where_to(self): try: @@ -37,9 +38,8 @@ class Quiz(Site): return self.get_absolute_url() -@python_2_unicode_compatible class Result(models.Model): - quiz = models.ForeignKey(Quiz) + quiz = models.ForeignKey(Quiz, models.CASCADE) slug = models.SlugField(db_index=True) title = models.CharField(max_length=255) text = models.TextField() @@ -52,14 +52,12 @@ class Result(models.Model): def __str__(self): return self.title - @models.permalink def get_absolute_url(self): - return ('quiz_result', [self.slug]) + return reverse('quiz_result', args=[self.slug]) -@python_2_unicode_compatible class Question(models.Model): - quiz = models.ForeignKey(Quiz) + quiz = models.ForeignKey(Quiz, models.CASCADE) slug = models.SlugField(db_index=True) ordering = models.SmallIntegerField() title = models.CharField(max_length=255) @@ -75,9 +73,8 @@ class Question(models.Model): def __str__(self): return self.title - @models.permalink def get_absolute_url(self): - return ('quiz', [self.slug]) + return reverse('quiz', args=[self.slug]) def where_to(self): later = self.quiz.question_set.filter(ordering__gt=self.ordering) @@ -87,13 +84,12 @@ class Question(models.Model): return self.quiz.where_to() -@python_2_unicode_compatible class Answer(models.Model): title = models.CharField(max_length=255) - question = models.ForeignKey(Question) - go_to = models.ForeignKey(Question, null=True, blank=True, + question = models.ForeignKey(Question, models.CASCADE) + go_to = models.ForeignKey(Question, models.SET_NULL, null=True, blank=True, related_name='go_tos') - result = models.ForeignKey(Result, null=True, blank=True) + result = models.ForeignKey(Result, models.SET_NULL, null=True, blank=True) ordering = models.SmallIntegerField() class Meta: diff --git a/apps/quiz/templatetags/quiz_tags.py b/apps/quiz/templatetags/quiz_tags.py index 6f7af26..2f9c12d 100755 --- a/apps/quiz/templatetags/quiz_tags.py +++ b/apps/quiz/templatetags/quiz_tags.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of KOED-Quiz, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # diff --git a/apps/quiz/urls.py b/apps/quiz/urls.py index 6241cd8..17534d7 100644 --- a/apps/quiz/urls.py +++ b/apps/quiz/urls.py @@ -1,12 +1,12 @@ -# -*- coding: utf-8 -*- # This file is part of KOED-Quiz, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # -from django.conf.urls import patterns, url +from django.urls import path +from . import views -urlpatterns = patterns('quiz.views', - url(r'^$', 'question', name='quiz'), - url(r'^q/(?P[^/]*)/$', 'question', name='quiz'), - url(r'^r/(?P[^/]*)/$', 'result', name='quiz_result'), -) +urlpatterns = [ + path('', views.question, name='quiz'), + path('q//', views.question, name='quiz'), + path('r//', views.result, name='quiz_result'), +] diff --git a/apps/quiz/views.py b/apps/quiz/views.py index 75b918d..700371f 100644 --- a/apps/quiz/views.py +++ b/apps/quiz/views.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of KOED-Quiz, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # diff --git a/fabfile.py b/fabfile.py deleted file mode 100644 index 35dac8a..0000000 --- a/fabfile.py +++ /dev/null @@ -1,11 +0,0 @@ -from fnpdjango.deploy import * - - -env.project_name = 'koedquiz' -env.hosts = ['giewont.icm.edu.pl'] -env.user = 'rczajka' -env.app_path = '/srv/koedquiz' -env.services = [ - Supervisord('koedquiz'), - ] - diff --git a/koedquiz/settings.py b/koedquiz/settings.py index 6b17288..727a786 100644 --- a/koedquiz/settings.py +++ b/koedquiz/settings.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of KOED-Quiz, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -7,7 +6,6 @@ import os.path PROJECT_DIR = os.path.abspath(os.path.dirname(__file__)) DEBUG = False -TEMPLATE_DEBUG = DEBUG ADMINS = [ # ('Your Name', 'your_email@domain.com'), @@ -26,14 +24,7 @@ DATABASES = { } } -# Local time zone for this installation. Choices can be found here: -# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name -# although not all choices may be available on all operating systems. -# On Unix systems, a value of None will cause Django to use the same -# timezone as the operating system. -# If running in a Windows environment this must be set to the same as your -# system time zone. -TIME_ZONE = None +TIME_ZONE = 'Europe/Warsaw' # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html @@ -66,45 +57,29 @@ STATIC_ROOT = os.path.join(PROJECT_DIR, 'static/') # Example: "http://media.lawrence.com/static/" STATIC_URL = '/static/' -# URL prefix for admin static files -- CSS, JavaScript and images. -# Make sure to use a trailing slash. -# Examples: "http://foo.com/static/admin/", "/static/admin/". -ADMIN_MEDIA_PREFIX = '/static/admin/' - -# Additional locations of static files -STATICFILES_DIRS = ( - # Put strings here, like "/home/html/static" or "C:/www/django/static". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. -) - -# List of finder classes that know how to find static files in -# various locations. -STATICFILES_FINDERS = ( - 'django.contrib.staticfiles.finders.FileSystemFinder', - 'django.contrib.staticfiles.finders.AppDirectoriesFinder', -# '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', + 'DIRS': [ + os.path.join(PROJECT_DIR, 'templates'), + ], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + "django.contrib.auth.context_processors.auth", + "django.template.context_processors.debug", + "django.template.context_processors.i18n", + "django.template.context_processors.media", + "django.template.context_processors.static", + "django.template.context_processors.tz", + "django.contrib.messages.context_processors.messages", + "django.template.context_processors.request", + ] + }, + }, ] -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.core.context_processors.tz", - "django.contrib.messages.context_processors.messages", - "django.core.context_processors.request", -) - -MIDDLEWARE_CLASSES = [ +MIDDLEWARE = [ 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', @@ -115,12 +90,7 @@ MIDDLEWARE_CLASSES = [ ROOT_URLCONF = 'koedquiz.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'), -] +SITE_ID = 1 INSTALLED_APPS = [ 'django.contrib.auth', @@ -136,29 +106,6 @@ INSTALLED_APPS = [ 'quiz', ] -# 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, - }, - } -} - # Load localsettings, if they exist try: from .localsettings import * diff --git a/koedquiz/urls.py b/koedquiz/urls.py index 72de887..4907150 100644 --- a/koedquiz/urls.py +++ b/koedquiz/urls.py @@ -1,17 +1,14 @@ -# -*- coding: utf-8 -*- # This file is part of KOED-Quiz, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # -from django.conf.urls import patterns, include, url +from django.urls import include, path from django.views.generic import TemplateView from django.contrib import admin -admin.autodiscover() -urlpatterns = patterns('', - url(r'^$', TemplateView.as_view(template_name="quiz/home.html"), name='main_page'), +urlpatterns = [ + path('', TemplateView.as_view(template_name="quiz/home.html"), name='main_page'), - url(r'^quiz/', include('quiz.urls')), + path('quiz/', include('quiz.urls')), - url(r'^admin/doc/', include('django.contrib.admindocs.urls')), - url(r'^admin/', include(admin.site.urls)), -) + path('admin/', admin.site.urls), +] diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index e400248..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,5 +0,0 @@ --i http://pypi.nowoczesnapolska.org.pl/simple - -django-debug-toolbar -fnpdjango -Fabric diff --git a/requirements.txt b/requirements.txt index 0d48dc5..081bfff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ -# Django basics -Django>=1.7,<1.8 +Django==2.2.5 -- 2.20.1