From c0a7799619e217e2eac724b1a688ad37f0182253 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 29 Jul 2019 15:23:16 +0200 Subject: [PATCH] Some preparation for upgrade. --- src/api/fields.py | 2 +- src/api/migrations/0001_initial.py | 6 ++-- src/api/migrations/0003_bookuserdata.py | 8 ++--- src/api/models.py | 13 ++++---- src/catalogue/feeds.py | 3 +- .../management/commands/report_dead_links.py | 2 +- src/catalogue/migrations/0001_initial.py | 16 +++++----- .../migrations/0010_bookpopularity.py | 6 ++-- src/catalogue/models/book.py | 11 +++---- src/catalogue/models/bookmedia.py | 3 +- src/catalogue/models/collection.py | 5 ++- src/catalogue/models/fragment.py | 5 ++- src/catalogue/models/tag.py | 15 ++++----- src/catalogue/templatetags/catalogue_tags.py | 2 +- src/catalogue/views.py | 2 +- src/contact/forms.py | 3 +- src/contact/migrations/0001_initial.py | 6 ++-- src/contact/models.py | 7 ++--- src/dictionary/migrations/0001_initial.py | 6 ++-- .../migrations/0002_auto_20141006_1422.py | 8 ++--- src/dictionary/models.py | 5 ++- src/funding/migrations/0001_initial.py | 11 +++---- .../migrations/0004_auto_20190729_1450.py | 31 +++++++++++++++++++ src/funding/models.py | 11 +++---- src/funding/views.py | 3 +- src/infopages/models.py | 5 ++- src/isbn/migrations/0001_initial.py | 6 ++-- .../migrations/0005_auto_20190729_1450.py | 21 +++++++++++++ src/isbn/models.py | 3 +- src/isbn/views.py | 3 +- src/lesmianator/migrations/0001_initial.py | 8 ++--- .../migrations/0003_auto_20190729_1450.py | 22 +++++++++++++ src/lesmianator/models.py | 6 ++-- src/libraries/models.py | 8 ++--- src/newsletter/views.py | 3 +- src/opds/views.py | 2 +- src/paypal/migrations/0001_initial.py | 8 ++--- .../migrations/0003_auto_20190729_1450.py | 27 ++++++++++++++++ src/paypal/models.py | 5 ++- src/paypal/rest.py | 3 +- src/pdcounter/models.py | 9 ++---- src/picture/migrations/0001_initial.py | 6 ++-- src/picture/models.py | 8 ++--- src/picture/templatetags/picture_tags.py | 3 +- src/polls/migrations/0001_initial.py | 6 ++-- src/polls/models.py | 5 ++- src/polls/views.py | 3 +- src/push/views.py | 5 ++- src/search/context_processors.py | 3 +- src/social/migrations/0001_initial.py | 6 ++-- src/social/models.py | 4 +-- src/suggest/forms.py | 3 +- src/suggest/migrations/0001_initial.py | 8 ++--- .../migrations/0003_auto_20190729_1450.py | 27 ++++++++++++++++ src/suggest/models.py | 5 ++- src/suggest/views.py | 3 +- src/waiter/models.py | 3 +- .../migrations/getpaid/0001_initial.py | 6 ++-- 58 files changed, 245 insertions(+), 188 deletions(-) create mode 100644 src/funding/migrations/0004_auto_20190729_1450.py create mode 100644 src/isbn/migrations/0005_auto_20190729_1450.py create mode 100644 src/lesmianator/migrations/0003_auto_20190729_1450.py create mode 100644 src/paypal/migrations/0003_auto_20190729_1450.py create mode 100644 src/suggest/migrations/0003_auto_20190729_1450.py diff --git a/src/api/fields.py b/src/api/fields.py index 278af6aea..b6269da16 100644 --- a/src/api/fields.py +++ b/src/api/fields.py @@ -3,7 +3,7 @@ # from rest_framework import serializers from sorl.thumbnail import default -from django.core.urlresolvers import reverse +from django.urls import reverse from club.models import Membership diff --git a/src/api/migrations/0001_initial.py b/src/api/migrations/0001_initial.py index 4d20304bc..a4a8a8486 100644 --- a/src/api/migrations/0001_initial.py +++ b/src/api/migrations/0001_initial.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import models, migrations +import django.db.models.deletion class Migration(migrations.Migration): @@ -20,7 +18,7 @@ class Migration(migrations.Migration): ('category', models.CharField(db_index=True, max_length=64, null=True, blank=True)), ('created_at', models.DateTimeField(editable=False, db_index=True)), ('deleted_at', models.DateTimeField(auto_now_add=True, db_index=True)), - ('content_type', models.ForeignKey(to='contenttypes.ContentType')), + ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')), ], options={ }, diff --git a/src/api/migrations/0003_bookuserdata.py b/src/api/migrations/0003_bookuserdata.py index 11a2f8ff0..2a70fb5f5 100644 --- a/src/api/migrations/0003_bookuserdata.py +++ b/src/api/migrations/0003_bookuserdata.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import migrations, models +import django.db.models.deletion from django.conf import settings @@ -19,8 +17,8 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('complete', models.BooleanField(default=False)), - ('book', models.ForeignKey(to='catalogue.Book')), - ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)), + ('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='catalogue.Book')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], ), ] diff --git a/src/api/models.py b/src/api/models.py index 9a86c2c4b..1e25c36db 100644 --- a/src/api/models.py +++ b/src/api/models.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -15,7 +14,7 @@ from catalogue.models import Book, Tag class Deleted(models.Model): object_id = models.IntegerField() slug = models.SlugField(_('slug'), max_length=120, blank=True, db_index=True) - content_type = models.ForeignKey(ContentType) + content_type = models.ForeignKey(ContentType, models.CASCADE) category = models.CharField(max_length=64, null=True, blank=True, db_index=True) created_at = models.DateTimeField(editable=False, db_index=True) deleted_at = models.DateTimeField(auto_now_add=True, db_index=True) @@ -43,8 +42,8 @@ pre_delete.connect(_pre_delete_handler) class BookUserData(models.Model): - book = models.ForeignKey(Book) - user = models.ForeignKey(User) + book = models.ForeignKey(Book, models.CASCADE) + user = models.ForeignKey(User, models.CASCADE) complete = models.BooleanField(default=False) last_changed = models.DateTimeField(auto_now=True) @@ -86,7 +85,7 @@ class Consumer(models.Model): key = models.CharField(max_length=KEY_SIZE) secret = models.CharField(max_length=SECRET_SIZE) status = models.CharField(max_length=16, choices=CONSUMER_STATES, default='pending') - user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, related_name='consumers') + user = models.ForeignKey(settings.AUTH_USER_MODEL, models.CASCADE, null=True, blank=True, related_name='consumers') def __str__(self): return u"Consumer %s with key %s" % (self.name, self.key) @@ -102,8 +101,8 @@ class Token(models.Model): token_type = models.IntegerField(choices=TOKEN_TYPES) timestamp = models.IntegerField() is_approved = models.BooleanField(default=False) - user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, related_name='tokens') - consumer = models.ForeignKey(Consumer) + user = models.ForeignKey(settings.AUTH_USER_MODEL, models.CASCADE, null=True, blank=True, related_name='tokens') + consumer = models.ForeignKey(Consumer, models.CASCADE) def __str__(self): return u"%s Token %s for %s" % (self.get_token_type_display(), self.key, self.consumer) diff --git a/src/catalogue/feeds.py b/src/catalogue/feeds.py index 0b7e4d474..f0305e76f 100644 --- a/src/catalogue/feeds.py +++ b/src/catalogue/feeds.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.contrib.sites.models import Site from django.contrib.syndication.views import Feed -from django.core.urlresolvers import reverse +from django.urls import reverse from catalogue import models diff --git a/src/catalogue/management/commands/report_dead_links.py b/src/catalogue/management/commands/report_dead_links.py index a6ee2a9d5..ddcc2168f 100644 --- a/src/catalogue/management/commands/report_dead_links.py +++ b/src/catalogue/management/commands/report_dead_links.py @@ -11,7 +11,7 @@ class Command(BaseCommand): from catalogue.models import Book from picture.models import Picture from urllib.request import urlopen, HTTPError, URLError - from django.core.urlresolvers import reverse + from django.urls import reverse from django.contrib.sites.models import Site domain = Site.objects.get_current().domain diff --git a/src/catalogue/migrations/0001_initial.py b/src/catalogue/migrations/0001_initial.py index 37d502b8a..987d81178 100644 --- a/src/catalogue/migrations/0001_initial.py +++ b/src/catalogue/migrations/0001_initial.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import models, migrations +import django.db.models.deletion import fnpdjango.storage import jsonfield.fields import catalogue.fields @@ -45,7 +43,7 @@ class Migration(migrations.Migration): ('mobi_file', catalogue.fields.EbookField('mobi', default='', storage=fnpdjango.storage.BofhFileSystemStorage(), upload_to=catalogue.models.book._mobi_upload_to, max_length=255, blank=True, verbose_name='MOBI file')), ('html_file', catalogue.fields.EbookField('html', default='', storage=fnpdjango.storage.BofhFileSystemStorage(), upload_to=catalogue.models.book._html_upload_to, max_length=255, blank=True, verbose_name='HTML file')), ('xml_file', catalogue.fields.EbookField('xml', default='', storage=fnpdjango.storage.BofhFileSystemStorage(), upload_to=catalogue.models.book._xml_upload_to, max_length=255, blank=True, verbose_name='XML file')), - ('parent', models.ForeignKey(related_name='children', blank=True, to='catalogue.Book', null=True)), + ('parent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='children', blank=True, to='catalogue.Book', null=True)), ], options={ 'ordering': ('sort_key',), @@ -64,7 +62,7 @@ class Migration(migrations.Migration): ('uploaded_at', models.DateTimeField(auto_now_add=True, verbose_name='creation date', db_index=True)), ('extra_info', jsonfield.fields.JSONField(default={}, verbose_name='Additional information', editable=False)), ('source_sha1', models.CharField(max_length=40, null=True, editable=False, blank=True)), - ('book', models.ForeignKey(related_name='media', to='catalogue.Book')), + ('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='media', to='catalogue.Book')), ], options={ 'ordering': ('type', 'name'), @@ -114,7 +112,7 @@ class Migration(migrations.Migration): ('text', models.TextField()), ('short_text', models.TextField(editable=False)), ('anchor', models.CharField(max_length=120)), - ('book', models.ForeignKey(related_name='fragments', to='catalogue.Book')), + ('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='fragments', to='catalogue.Book')), ], options={ 'ordering': ('book', 'anchor'), @@ -188,7 +186,7 @@ class Migration(migrations.Migration): ('wiki_link_uk', models.CharField(max_length=240, null=True, blank=True)), ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='creation date', db_index=True)), ('changed_at', models.DateTimeField(auto_now=True, verbose_name='creation date', db_index=True)), - ('user', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, blank=True, to=settings.AUTH_USER_MODEL, null=True)), ], options={ 'ordering': ('sort_key',), @@ -202,8 +200,8 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('object_id', models.PositiveIntegerField(verbose_name='object id', db_index=True)), - ('content_type', models.ForeignKey(verbose_name='content type', to='contenttypes.ContentType')), - ('tag', models.ForeignKey(related_name='items', verbose_name='tag', to='catalogue.Tag')), + ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, verbose_name='content type', to='contenttypes.ContentType')), + ('tag', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', verbose_name='tag', to='catalogue.Tag')), ], options={ 'db_table': 'catalogue_tag_relation', diff --git a/src/catalogue/migrations/0010_bookpopularity.py b/src/catalogue/migrations/0010_bookpopularity.py index 42fd6cb7a..608af9ce1 100644 --- a/src/catalogue/migrations/0010_bookpopularity.py +++ b/src/catalogue/migrations/0010_bookpopularity.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import migrations, models +import django.db.models.deletion class Migration(migrations.Migration): @@ -16,7 +14,7 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('count', models.IntegerField(default=0)), - ('book', models.OneToOneField(related_name='popularity', to='catalogue.Book')), + ('book', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='popularity', to='catalogue.Book')), ], ), ] diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index 61d20fdc6..2b64ec802 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -10,10 +9,9 @@ import re import urllib from django.conf import settings from django.db import connection, models, transaction -from django.db.models import permalink import django.dispatch from django.contrib.contenttypes.fields import GenericRelation -from django.core.urlresolvers import reverse +from django.urls import reverse from django.utils.translation import ugettext_lazy as _, get_language from django.utils.deconstruct import deconstructible import jsonfield @@ -103,7 +101,7 @@ class Book(models.Model): ebook_formats = constants.EBOOK_FORMATS formats = ebook_formats + ['html', 'xml'] - parent = models.ForeignKey('self', blank=True, null=True, related_name='children') + parent = models.ForeignKey('self', models.CASCADE, blank=True, null=True, related_name='children') ancestor = models.ManyToManyField('self', blank=True, editable=False, related_name='descendant', symmetrical=False) cached_author = models.CharField(blank=True, max_length=240, db_index=True) @@ -207,9 +205,8 @@ class Book(models.Model): return ret - @permalink def get_absolute_url(self): - return 'book_detail', [self.slug] + return reverse('book_detail', args=[self.slug]) def gallery_path(self): return gallery_path(self.slug) @@ -829,5 +826,5 @@ add_file_fields() class BookPopularity(models.Model): - book = models.OneToOneField(Book, related_name='popularity') + book = models.OneToOneField(Book, models.CASCADE, related_name='popularity') count = models.IntegerField(default=0, db_index=True) diff --git a/src/catalogue/models/bookmedia.py b/src/catalogue/models/bookmedia.py index 4532c862e..9f71364a8 100644 --- a/src/catalogue/models/bookmedia.py +++ b/src/catalogue/models/bookmedia.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -35,7 +34,7 @@ class BookMedia(models.Model): file = models.FileField(_('file'), max_length=600, upload_to=_file_upload_to, storage=OverwriteStorage()) uploaded_at = models.DateTimeField(_('creation date'), auto_now_add=True, editable=False, db_index=True) extra_info = jsonfield.JSONField(_('extra information'), default={}, editable=False) - book = models.ForeignKey('Book', related_name='media') + book = models.ForeignKey('Book', models.CASCADE, related_name='media') source_sha1 = models.CharField(null=True, blank=True, max_length=40, editable=False) def __str__(self): diff --git a/src/catalogue/models/collection.py b/src/catalogue/models/collection.py index 3c4b475a6..f059cb3c9 100644 --- a/src/catalogue/models/collection.py +++ b/src/catalogue/models/collection.py @@ -1,9 +1,9 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.conf import settings from django.db import models +from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from ssify import flush_ssi_includes import re @@ -33,9 +33,8 @@ class Collection(models.Model): except AttributeError: return '' - @models.permalink def get_absolute_url(self): - return "collection", [self.slug] + return reverse("collection", args=[self.slug]) def get_query(self): slugs = self.book_slugs.split() diff --git a/src/catalogue/models/fragment.py b/src/catalogue/models/fragment.py index dc159a59f..ef15f85b4 100644 --- a/src/catalogue/models/fragment.py +++ b/src/catalogue/models/fragment.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.conf import settings from django.contrib.contenttypes.fields import GenericRelation -from django.core.urlresolvers import reverse +from django.urls import reverse from django.db import models from django.utils.translation import ugettext_lazy as _ from newtagging import managers @@ -17,7 +16,7 @@ class Fragment(models.Model): text = models.TextField() short_text = models.TextField(editable=False) anchor = models.CharField(max_length=120) - book = models.ForeignKey('Book', related_name='fragments') + book = models.ForeignKey('Book', models.CASCADE, related_name='fragments') objects = models.Manager() tagged = managers.ModelTaggedItemManager(Tag) diff --git a/src/catalogue/models/tag.py b/src/catalogue/models/tag.py index 1b4160121..dac96e248 100644 --- a/src/catalogue/models/tag.py +++ b/src/catalogue/models/tag.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -9,9 +8,9 @@ from django.core.cache import caches from django.contrib.auth.models import User from django.core.exceptions import ObjectDoesNotExist from django.db import models -from django.db.models import permalink from django.db.models.query import Prefetch from django.dispatch import Signal +from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from newtagging.models import TagManager, TaggedItemManager @@ -32,8 +31,8 @@ TAG_CATEGORIES = ( class TagRelation(models.Model): - tag = models.ForeignKey('Tag', verbose_name=_('tag'), related_name='items') - content_type = models.ForeignKey(ContentType, verbose_name=_('content type')) + tag = models.ForeignKey('Tag', models.CASCADE, verbose_name=_('tag'), related_name='items') + content_type = models.ForeignKey(ContentType, models.CASCADE, verbose_name=_('content type')) object_id = models.PositiveIntegerField(_('object id'), db_index=True) content_object = GenericForeignKey('content_type', 'object_id') @@ -65,7 +64,7 @@ class Tag(models.Model): for_books = models.BooleanField(default=False) for_pictures = models.BooleanField(default=False) - user = models.ForeignKey(User, blank=True, null=True) + user = models.ForeignKey(User, models.CASCADE, blank=True, null=True) gazeta_link = models.CharField(blank=True, max_length=240) culturepl_link = models.CharField(blank=True, max_length=240) wiki_link = models.CharField(blank=True, max_length=240) @@ -173,13 +172,11 @@ class Tag(models.Model): def category_plural(self): return self.category + 's' - @permalink def get_absolute_url(self): - return 'tagged_object_list', [self.url_chunk] + return reverse('tagged_object_list', args=[self.url_chunk]) - @permalink def get_absolute_gallery_url(self): - return 'tagged_object_list_gallery', [self.url_chunk] + return reverse('tagged_object_list_gallery', args=[self.url_chunk]) def has_description(self): return len(self.description) > 0 diff --git a/src/catalogue/templatetags/catalogue_tags.py b/src/catalogue/templatetags/catalogue_tags.py index 2670e58db..af0370a1b 100644 --- a/src/catalogue/templatetags/catalogue_tags.py +++ b/src/catalogue/templatetags/catalogue_tags.py @@ -8,7 +8,7 @@ from django.contrib.contenttypes.models import ContentType from django.conf import settings from django import template from django.template import Node, Variable, Template, Context -from django.core.urlresolvers import reverse +from django.urls import reverse from django.utils.cache import add_never_cache_headers from django.utils.safestring import mark_safe from django.utils.translation import ugettext as _ diff --git a/src/catalogue/views.py b/src/catalogue/views.py index 632eff868..b826fc21d 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -9,7 +9,7 @@ from django.http.response import HttpResponseForbidden from django.template.loader import render_to_string from django.shortcuts import get_object_or_404, render, redirect from django.http import HttpResponse, HttpResponseRedirect, Http404, HttpResponsePermanentRedirect -from django.core.urlresolvers import reverse +from django.urls import reverse from django.db.models import Q, QuerySet from django.contrib.auth.decorators import login_required, user_passes_test from django.utils.http import urlquote_plus diff --git a/src/contact/forms.py b/src/contact/forms.py index 3cdf59dee..ff1687adb 100644 --- a/src/contact/forms.py +++ b/src/contact/forms.py @@ -1,13 +1,12 @@ -# -*- coding: utf-8 -*- from django.contrib.sites.models import Site from django.core.exceptions import ValidationError from django.core.files.uploadedfile import UploadedFile from django.core.mail import send_mail, mail_managers -from django.core.urlresolvers import reverse from django.core.validators import validate_email from django import forms from django.template.loader import render_to_string from django.template import RequestContext +from django.urls import reverse from django.utils.translation import ugettext_lazy as _ diff --git a/src/contact/migrations/0001_initial.py b/src/contact/migrations/0001_initial.py index 1c0a565b4..216c4c508 100644 --- a/src/contact/migrations/0001_initial.py +++ b/src/contact/migrations/0001_initial.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import migrations, models +import django.db.models.deletion import jsonfield.fields @@ -38,6 +36,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='attachment', name='contact', - field=models.ForeignKey(to='contact.Contact'), + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contact.Contact'), ), ] diff --git a/src/contact/models.py b/src/contact/models.py index e44bd9bb0..aae3f2dcd 100644 --- a/src/contact/models.py +++ b/src/contact/models.py @@ -1,7 +1,7 @@ -# -*- coding: utf-8 -*- import yaml from hashlib import sha1 from django.db import models +from django.urls import reverse from django.utils.encoding import smart_text from django.utils.translation import ugettext_lazy as _ from jsonfield import JSONField @@ -49,13 +49,12 @@ class Contact(models.Model): class Attachment(models.Model): - contact = models.ForeignKey(Contact) + contact = models.ForeignKey(Contact, models.CASCADE) tag = models.CharField(max_length=64) file = models.FileField(upload_to='contact/attachment') - @models.permalink def get_absolute_url(self): - return 'contact_attachment', [self.contact_id, self.tag] + return reverse('contact_attachment', args=[self.contact_id, self.tag]) __import__(app_settings.FORMS_MODULE) diff --git a/src/dictionary/migrations/0001_initial.py b/src/dictionary/migrations/0001_initial.py index 1908a840a..60ea4b684 100644 --- a/src/dictionary/migrations/0001_initial.py +++ b/src/dictionary/migrations/0001_initial.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import models, migrations +import django.db.models.deletion class Migration(migrations.Migration): @@ -18,7 +16,7 @@ class Migration(migrations.Migration): ('anchor', models.CharField(max_length=64)), ('html', models.TextField()), ('sort_key', models.CharField(max_length=128, db_index=True)), - ('book', models.ForeignKey(to='catalogue.Book')), + ('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='catalogue.Book')), ], options={ 'ordering': ['sort_key'], diff --git a/src/dictionary/migrations/0002_auto_20141006_1422.py b/src/dictionary/migrations/0002_auto_20141006_1422.py index a9bad32b9..f51e83f00 100644 --- a/src/dictionary/migrations/0002_auto_20141006_1422.py +++ b/src/dictionary/migrations/0002_auto_20141006_1422.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import models, migrations +import django.db.models.deletion class Migration(migrations.Migration): @@ -17,8 +15,8 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('anchor', models.CharField(max_length=64)), - ('book', models.ForeignKey(to='catalogue.Book')), - ('note', models.ForeignKey(to='dictionary.Note')), + ('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='catalogue.Book')), + ('note', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dictionary.Note')), ], options={ 'ordering': ['book'], diff --git a/src/dictionary/models.py b/src/dictionary/models.py index c8e086fb4..c2891e1c9 100644 --- a/src/dictionary/models.py +++ b/src/dictionary/models.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -37,8 +36,8 @@ class Note(models.Model): class NoteSource(models.Model): """Represents a single annotation from a book.""" - note = models.ForeignKey(Note) - book = models.ForeignKey(Book) + note = models.ForeignKey(Note, models.CASCADE) + book = models.ForeignKey(Book, models.CASCADE) anchor = models.CharField(max_length=64) class Meta: diff --git a/src/funding/migrations/0001_initial.py b/src/funding/migrations/0001_initial.py index f802027cf..cd46551e6 100644 --- a/src/funding/migrations/0001_initial.py +++ b/src/funding/migrations/0001_initial.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import models, migrations import django.db.models.deletion @@ -47,7 +44,7 @@ class Migration(migrations.Migration): ('cover', models.ImageField(upload_to='funding/covers', verbose_name='Cover')), ('notified_near', models.DateTimeField(null=True, verbose_name='Near-end notifications sent', blank=True)), ('notified_end', models.DateTimeField(null=True, verbose_name='End notifications sent', blank=True)), - ('book', models.ForeignKey(blank=True, to='catalogue.Book', help_text='Published book.', null=True)), + ('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, blank=True, to='catalogue.Book', help_text='Published book.', null=True)), ('poll', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, blank=True, to='polls.Poll', help_text='Poll', null=True)), ], options={ @@ -65,7 +62,7 @@ class Migration(migrations.Migration): ('name', models.CharField(max_length=255, verbose_name='name')), ('long_name', models.CharField(max_length=255, verbose_name='long name')), ('end_date', models.DateField(null=True, verbose_name='end date', blank=True)), - ('offer', models.ForeignKey(verbose_name='offer', blank=True, to='funding.Offer', null=True)), + ('offer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, verbose_name='offer', blank=True, to='funding.Offer', null=True)), ], options={ 'ordering': ['-price'], @@ -80,7 +77,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('amount', models.DecimalField(verbose_name='amount', max_digits=10, decimal_places=2)), ('timestamp', models.DateField(verbose_name='when')), - ('book', models.ForeignKey(to='catalogue.Book')), + ('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='catalogue.Book')), ], options={ 'ordering': ['-timestamp'], @@ -92,7 +89,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='funding', name='offer', - field=models.ForeignKey(verbose_name='offer', to='funding.Offer'), + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, verbose_name='offer', to='funding.Offer'), preserve_default=True, ), migrations.AddField( diff --git a/src/funding/migrations/0004_auto_20190729_1450.py b/src/funding/migrations/0004_auto_20190729_1450.py new file mode 100644 index 000000000..17822eed2 --- /dev/null +++ b/src/funding/migrations/0004_auto_20190729_1450.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-07-29 12:50 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('funding', '0003_auto_20180416_1336'), + ] + + operations = [ + migrations.AlterField( + model_name='funding', + name='offer', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='funding.Offer', verbose_name='offer'), + ), + migrations.AlterField( + model_name='offer', + name='book', + field=models.ForeignKey(blank=True, help_text='Published book.', null=True, on_delete=django.db.models.deletion.PROTECT, to='catalogue.Book'), + ), + migrations.AlterField( + model_name='spent', + name='book', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='catalogue.Book'), + ), + ] diff --git a/src/funding/models.py b/src/funding/models.py index 6ca02615f..2b4372fe1 100644 --- a/src/funding/models.py +++ b/src/funding/models.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -6,11 +5,11 @@ from datetime import date, datetime from urllib.parse import urlencode from django.conf import settings from django.contrib.sites.models import Site -from django.core.urlresolvers import reverse from django.core.mail import send_mail from django.db import models from django.dispatch import receiver from django.template.loader import render_to_string +from django.urls import reverse from django.utils.timezone import utc from django.utils.translation import ugettext_lazy as _, override import getpaid @@ -31,7 +30,7 @@ class Offer(models.Model): start = models.DateField(_('start'), db_index=True) end = models.DateField(_('end'), db_index=True) redakcja_url = models.URLField(_('redakcja URL'), blank=True) - book = models.ForeignKey(Book, null=True, blank=True, help_text=_('Published book.')) + book = models.ForeignKey(Book, models.PROTECT, null=True, blank=True, help_text=_('Published book.')) cover = models.ImageField(_('Cover'), upload_to='funding/covers') poll = models.ForeignKey(Poll, help_text=_('Poll'), null=True, blank=True, on_delete=models.SET_NULL) @@ -207,7 +206,7 @@ class Perk(models.Model): If no attached to a particular Offer, applies to all. """ - offer = models.ForeignKey(Offer, verbose_name=_('offer'), null=True, blank=True) + offer = models.ForeignKey(Offer, models.CASCADE, verbose_name=_('offer'), null=True, blank=True) price = models.DecimalField(_('price'), decimal_places=2, max_digits=10) name = models.CharField(_('name'), max_length=255) long_name = models.CharField(_('long name'), max_length=255) @@ -228,7 +227,7 @@ class Funding(models.Model): The payment was completed if and only if payed_at is set. """ - offer = models.ForeignKey(Offer, verbose_name=_('offer')) + offer = models.ForeignKey(Offer, models.PROTECT, verbose_name=_('offer')) name = models.CharField(_('name'), max_length=127, blank=True) email = models.EmailField(_('email'), blank=True, db_index=True) amount = models.DecimalField(_('amount'), decimal_places=2, max_digits=10) @@ -309,7 +308,7 @@ getpaid.register_to_payment(Funding, unique=False, related_name='payment') class Spent(models.Model): """ Some of the remaining money spent on a book. """ - book = models.ForeignKey(Book) + book = models.ForeignKey(Book, models.PROTECT) amount = models.DecimalField(_('amount'), decimal_places=2, max_digits=10) timestamp = models.DateField(_('when')) diff --git a/src/funding/views.py b/src/funding/views.py index 74530a4af..d6d6570bf 100644 --- a/src/funding/views.py +++ b/src/funding/views.py @@ -1,11 +1,10 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.core.paginator import Paginator, InvalidPage -from django.core.urlresolvers import reverse from django.http import Http404 from django.shortcuts import get_object_or_404, redirect, render +from django.urls import reverse from django.views.decorators.csrf import csrf_exempt from django.views.generic import TemplateView, FormView, ListView from getpaid.models import Payment diff --git a/src/infopages/models.py b/src/infopages/models.py index 8999d99bd..0060a7036 100644 --- a/src/infopages/models.py +++ b/src/infopages/models.py @@ -1,8 +1,8 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.db import models +from django.urls import reverse from django.utils.translation import ugettext_lazy as _ @@ -23,6 +23,5 @@ class InfoPage(models.Model): def __str__(self): return self.title - @models.permalink def get_absolute_url(self): - return 'infopage', [self.slug] + return reverse('infopage', args=[self.slug]) diff --git a/src/isbn/migrations/0001_initial.py b/src/isbn/migrations/0001_initial.py index c4c09ad98..b3c9aec50 100644 --- a/src/isbn/migrations/0001_initial.py +++ b/src/isbn/migrations/0001_initial.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import migrations, models +import django.db.models.deletion import jsonfield.fields @@ -38,7 +36,7 @@ class Migration(migrations.Migration): ('language', models.CharField(max_length=4)), ('imprint', models.CharField(max_length=256)), ('publishing_date', models.DateField()), - ('isbn_pool', models.ForeignKey(to='isbn.ISBNPool')), + ('isbn_pool', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='isbn.ISBNPool')), ], ), ] diff --git a/src/isbn/migrations/0005_auto_20190729_1450.py b/src/isbn/migrations/0005_auto_20190729_1450.py new file mode 100644 index 000000000..fc43a3662 --- /dev/null +++ b/src/isbn/migrations/0005_auto_20190729_1450.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-07-29 12:50 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('isbn', '0004_auto_20180215_1042'), + ] + + operations = [ + migrations.AlterField( + model_name='onixrecord', + name='isbn_pool', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='isbn.ISBNPool'), + ), + ] diff --git a/src/isbn/models.py b/src/isbn/models.py index ca8dbee15..d65ca606c 100644 --- a/src/isbn/models.py +++ b/src/isbn/models.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -53,7 +52,7 @@ class ISBNPool(models.Model): class ONIXRecord(models.Model): - isbn_pool = models.ForeignKey(ISBNPool) + isbn_pool = models.ForeignKey(ISBNPool, models.PROTECT) datestamp = models.DateField(auto_now=True) suffix = models.IntegerField() product_form = models.CharField(max_length=4) diff --git a/src/isbn/views.py b/src/isbn/views.py index 8073c75a8..399a25dad 100644 --- a/src/isbn/views.py +++ b/src/isbn/views.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- from django.contrib.auth.decorators import permission_required -from django.core.urlresolvers import reverse from django.http.response import HttpResponseRedirect from django.shortcuts import render +from django.urls import reverse from django.views.decorators.http import require_POST from isbn.forms import WLISBNForm, WLConfirmForm, FNPISBNForm diff --git a/src/lesmianator/migrations/0001_initial.py b/src/lesmianator/migrations/0001_initial.py index 1980b26b9..f8741e4cb 100644 --- a/src/lesmianator/migrations/0001_initial.py +++ b/src/lesmianator/migrations/0001_initial.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import models, migrations +import django.db.models.deletion import jsonfield.fields from django.conf import settings @@ -20,7 +18,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('pickle', models.FileField(upload_to='lesmianator', verbose_name='Continuations file')), ('object_id', models.PositiveIntegerField()), - ('content_type', models.ForeignKey(to='contenttypes.ContentType')), + ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')), ], options={ }, @@ -36,7 +34,7 @@ class Migration(migrations.Migration): ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='creation date')), ('seen_at', models.DateTimeField(auto_now_add=True, verbose_name='last view date')), ('view_count', models.IntegerField(default=1, verbose_name='view count')), - ('created_by', models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True)), + ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, null=True)), ], options={ }, diff --git a/src/lesmianator/migrations/0003_auto_20190729_1450.py b/src/lesmianator/migrations/0003_auto_20190729_1450.py new file mode 100644 index 000000000..d43a9c77d --- /dev/null +++ b/src/lesmianator/migrations/0003_auto_20190729_1450.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-07-29 12:50 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('lesmianator', '0002_auto_20151221_1225'), + ] + + operations = [ + migrations.AlterField( + model_name='poem', + name='created_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/src/lesmianator/models.py b/src/lesmianator/models.py index 47b431542..f12f1d778 100644 --- a/src/lesmianator/models.py +++ b/src/lesmianator/models.py @@ -11,11 +11,11 @@ from django.core.files.base import ContentFile from django.db import models from django.utils.timezone import utc from django.utils.translation import ugettext_lazy as _ -from django.core.urlresolvers import reverse from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.fields import GenericForeignKey from django.conf import settings +from django.urls import reverse from jsonfield import JSONField from catalogue.models import Book, Tag @@ -24,7 +24,7 @@ from catalogue.models import Book, Tag class Poem(models.Model): slug = models.SlugField(_('slug'), max_length=120, db_index=True) text = models.TextField(_('text')) - created_by = models.ForeignKey(User, null=True) + created_by = models.ForeignKey(User, models.SET_NULL, null=True) created_from = JSONField(_('extra information'), null=True, blank=True) created_at = models.DateTimeField(_('creation date'), auto_now_add=True, editable=False) seen_at = models.DateTimeField(_('last view date'), auto_now_add=True, editable=False) @@ -101,7 +101,7 @@ class Poem(models.Model): class Continuations(models.Model): pickle = models.FileField(_('Continuations file'), upload_to='lesmianator') - content_type = models.ForeignKey(ContentType) + content_type = models.ForeignKey(ContentType, models.CASCADE) object_id = models.PositiveIntegerField() content_object = GenericForeignKey('content_type', 'object_id') diff --git a/src/libraries/models.py b/src/libraries/models.py index 0ad058610..3e80301e7 100644 --- a/src/libraries/models.py +++ b/src/libraries/models.py @@ -1,8 +1,8 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.db import models +from django.urls import reverse from django.utils.translation import ugettext_lazy as _ @@ -19,9 +19,8 @@ class Catalog(models.Model): def __str__(self): return self.name - @models.permalink def get_absolute_url(self): - return 'libraries_catalog_view', [self.slug] + return reverse('libraries_catalog_view', args=[self.slug]) class Library(models.Model): @@ -40,6 +39,5 @@ class Library(models.Model): def __str__(self): return self.name - @models.permalink def get_absolute_url(self): - return ('libraries_library_view', [self.catalog.slug, self.slug]) + return reverse('libraries_library_view', args=[self.catalog.slug, self.slug]) diff --git a/src/newsletter/views.py b/src/newsletter/views.py index 342fc5067..7fd67b278 100644 --- a/src/newsletter/views.py +++ b/src/newsletter/views.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- -from django.core.urlresolvers import reverse from django.http import Http404 from django.http.response import HttpResponseRedirect from django.shortcuts import render, get_object_or_404 +from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from newsletter.forms import UnsubscribeForm, SubscribeForm diff --git a/src/opds/views.py b/src/opds/views.py index f14696bba..c71822fa8 100644 --- a/src/opds/views.py +++ b/src/opds/views.py @@ -6,8 +6,8 @@ import os.path from urllib.parse import urljoin from django.contrib.syndication.views import Feed -from django.core.urlresolvers import reverse from django.shortcuts import get_object_or_404 +from django.urls import reverse from django.utils.feedgenerator import Atom1Feed from django.conf import settings from django.http import Http404 diff --git a/src/paypal/migrations/0001_initial.py b/src/paypal/migrations/0001_initial.py index 879901ae8..6380c0faf 100644 --- a/src/paypal/migrations/0001_initial.py +++ b/src/paypal/migrations/0001_initial.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import migrations, models +import django.db.models.deletion from django.conf import settings @@ -31,11 +29,11 @@ class Migration(migrations.Migration): migrations.AddField( model_name='billingagreement', name='plan', - field=models.ForeignKey(to='paypal.BillingPlan'), + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='paypal.BillingPlan'), ), migrations.AddField( model_name='billingagreement', name='user', - field=models.ForeignKey(to=settings.AUTH_USER_MODEL), + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), ), ] diff --git a/src/paypal/migrations/0003_auto_20190729_1450.py b/src/paypal/migrations/0003_auto_20190729_1450.py new file mode 100644 index 000000000..4c47ec75f --- /dev/null +++ b/src/paypal/migrations/0003_auto_20190729_1450.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-07-29 12:50 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('paypal', '0002_billingagreement_token'), + ] + + operations = [ + migrations.AlterField( + model_name='billingagreement', + name='plan', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='paypal.BillingPlan'), + ), + migrations.AlterField( + model_name='billingagreement', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/src/paypal/models.py b/src/paypal/models.py index 426688231..2ce3635a7 100644 --- a/src/paypal/models.py +++ b/src/paypal/models.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -14,8 +13,8 @@ class BillingPlan(models.Model): class BillingAgreement(models.Model): agreement_id = models.CharField(max_length=32) - user = models.ForeignKey(User) - plan = models.ForeignKey(BillingPlan) + user = models.ForeignKey(User, models.PROTECT) + plan = models.ForeignKey(BillingPlan, models.PROTECT) active = models.BooleanField(max_length=32) token = models.CharField(max_length=32) diff --git a/src/paypal/rest.py b/src/paypal/rest.py index 8927cabbf..57c150b18 100644 --- a/src/paypal/rest.py +++ b/src/paypal/rest.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -7,7 +6,7 @@ from datetime import timedelta import paypalrestsdk import pytz from django.contrib.sites.models import Site -from django.core.urlresolvers import reverse +from django.urls import reverse from django.utils import timezone from django.conf import settings from .models import BillingPlan, BillingAgreement diff --git a/src/pdcounter/models.py b/src/pdcounter/models.py index 4454e5af0..7d6181d60 100644 --- a/src/pdcounter/models.py +++ b/src/pdcounter/models.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.conf import settings from django.db import models -from django.db.models import permalink +from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from datetime import datetime from django.db.models.signals import post_save, post_delete @@ -34,9 +33,8 @@ class Author(models.Model): def __repr__(self): return "Author(slug=%r)" % self.slug - @permalink def get_absolute_url(self): - return 'tagged_object_list', [self.url_chunk] + return reverse('tagged_object_list', args=[self.url_chunk]) def has_description(self): return len(self.description) > 0 @@ -74,9 +72,8 @@ class BookStub(models.Model): def __str__(self): return self.title - @permalink def get_absolute_url(self): - return 'book_detail', [self.slug] + return reverse('book_detail', args=[self.slug]) def in_pd(self): return self.pd is not None and self.pd <= datetime.now().year diff --git a/src/picture/migrations/0001_initial.py b/src/picture/migrations/0001_initial.py index 6280cf21e..11321d40b 100644 --- a/src/picture/migrations/0001_initial.py +++ b/src/picture/migrations/0001_initial.py @@ -1,9 +1,7 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from os.path import join from django.conf import settings from django.db import models, migrations +import django.db.models.deletion import sorl.thumbnail.fields import jsonfield.fields import django.core.files.storage @@ -49,7 +47,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('area', jsonfield.fields.JSONField(default={}, verbose_name='area', editable=False)), ('kind', models.CharField(db_index=True, max_length=10, verbose_name='form', choices=[('thing', 'thing'), ('theme', 'motif')])), - ('picture', models.ForeignKey(related_name='areas', to='picture.Picture')), + ('picture', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='areas', to='picture.Picture')), ], options={ }, diff --git a/src/picture/models.py b/src/picture/models.py index 4d8dac819..c853bb9b3 100644 --- a/src/picture/models.py +++ b/src/picture/models.py @@ -1,14 +1,13 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.db import models, transaction import catalogue.models -from django.db.models import permalink from sorl.thumbnail import ImageField from django.conf import settings from django.contrib.contenttypes.fields import GenericRelation from django.core.files.storage import FileSystemStorage +from django.urls import reverse from slugify import slugify from ssify import flush_ssi_includes @@ -34,7 +33,7 @@ picture_storage = FileSystemStorage(location=path.join( class PictureArea(models.Model): - picture = models.ForeignKey('picture.Picture', related_name='areas') + picture = models.ForeignKey('picture.Picture', models.CASCADE, related_name='areas') area = jsonfield.JSONField(_('area'), default={}, editable=False) kind = models.CharField( _('kind'), max_length=10, blank=False, null=False, db_index=True, @@ -142,9 +141,8 @@ class Picture(models.Model): def tags_by_category(self): return split_tags(self.tags) - @permalink def get_absolute_url(self): - return 'picture_detail', [self.slug] + return reverse('picture_detail', args=[self.slug]) def get_initial(self): try: diff --git a/src/picture/templatetags/picture_tags.py b/src/picture/templatetags/picture_tags.py index 973d862f9..3330b61d6 100644 --- a/src/picture/templatetags/picture_tags.py +++ b/src/picture/templatetags/picture_tags.py @@ -1,11 +1,10 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # import logging from random import randint from django import template -from django.core.urlresolvers import reverse +from django.urls import reverse from django.utils.cache import add_never_cache_headers import sorl.thumbnail.default from ssify import ssi_variable diff --git a/src/polls/migrations/0001_initial.py b/src/polls/migrations/0001_initial.py index fb2c17faf..79592e9f4 100644 --- a/src/polls/migrations/0001_initial.py +++ b/src/polls/migrations/0001_initial.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import models, migrations +import django.db.models.deletion class Migration(migrations.Migration): @@ -30,7 +28,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('content', models.TextField(verbose_name='content')), ('vote_count', models.IntegerField(default=0, verbose_name='vote count')), - ('poll', models.ForeignKey(related_name='items', to='polls.Poll')), + ('poll', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='polls.Poll')), ], options={ 'verbose_name': 'vote item', diff --git a/src/polls/models.py b/src/polls/models.py index 4b1882df2..2785f353e 100644 --- a/src/polls/models.py +++ b/src/polls/models.py @@ -1,11 +1,10 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.db import models from django.utils.translation import ugettext_lazy as _ from django.core.exceptions import ValidationError -from django.core.urlresolvers import reverse +from django.urls import reverse USED_POLLS_KEY = 'used_polls' @@ -42,7 +41,7 @@ class Poll(models.Model): class PollItem(models.Model): - poll = models.ForeignKey(Poll, related_name='items') + poll = models.ForeignKey(Poll, models.CASCADE, related_name='items') content = models.TextField(_('content')) vote_count = models.IntegerField(_('vote count'), default=0) diff --git a/src/polls/views.py b/src/polls/views.py index ffafd2a98..22d35b50e 100644 --- a/src/polls/views.py +++ b/src/polls/views.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # -from django.core.urlresolvers import reverse from django.shortcuts import get_object_or_404, redirect, render +from django.urls import reverse from django.views.decorators import cache from django.views.decorators.http import require_http_methods diff --git a/src/push/views.py b/src/push/views.py index bbcf89d6d..9de754edf 100644 --- a/src/push/views.py +++ b/src/push/views.py @@ -1,11 +1,10 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.contrib.auth.decorators import permission_required -from django.core.urlresolvers import reverse from django.http.response import HttpResponseRedirect from django.shortcuts import render +from django.urls import reverse from push.forms import NotificationForm @@ -23,4 +22,4 @@ def notification_form(request): def notification_sent(request): - return render(request, 'push/notification_sent.html') \ No newline at end of file + return render(request, 'push/notification_sent.html') diff --git a/src/search/context_processors.py b/src/search/context_processors.py index 63e328583..d5760d10b 100644 --- a/src/search/context_processors.py +++ b/src/search/context_processors.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # -from django.core.urlresolvers import reverse +from django.urls import reverse from search.forms import SearchForm diff --git a/src/social/migrations/0001_initial.py b/src/social/migrations/0001_initial.py index 63523cd1c..056918bee 100644 --- a/src/social/migrations/0001_initial.py +++ b/src/social/migrations/0001_initial.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import models, migrations +import django.db.models.deletion class Migration(migrations.Migration): @@ -27,7 +25,7 @@ class Migration(migrations.Migration): ('image_link', models.URLField(null=True, verbose_name='link', blank=True)), ('image_license', models.CharField(max_length=255, null=True, verbose_name='license name', blank=True)), ('image_license_link', models.URLField(null=True, verbose_name='license link', blank=True)), - ('book', models.ForeignKey(verbose_name='book', blank=True, to='catalogue.Book', null=True)), + ('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, verbose_name='book', blank=True, to='catalogue.Book', null=True)), ], options={ 'ordering': ('vip', 'text'), diff --git a/src/social/models.py b/src/social/models.py index 6f1f697fa..c9334d833 100644 --- a/src/social/models.py +++ b/src/social/models.py @@ -5,7 +5,7 @@ from random import randint from django.db import models from django.conf import settings from django.core.exceptions import ValidationError -from django.core.urlresolvers import reverse +from django.urls import reverse from django.utils.translation import ugettext_lazy as _, string_concat from ssify import flush_ssi_includes from catalogue.models import Book @@ -36,7 +36,7 @@ class BannerGroup(models.Model): class Cite(models.Model): - book = models.ForeignKey(Book, verbose_name=_('book'), null=True, blank=True) + book = models.ForeignKey(Book, models.CASCADE, verbose_name=_('book'), null=True, blank=True) text = models.TextField(_('text'), blank=True) small = models.BooleanField(_('small'), default=False, help_text=_('Make this cite display smaller.')) vip = models.CharField(_('VIP'), max_length=128, null=True, blank=True) diff --git a/src/suggest/forms.py b/src/suggest/forms.py index cfcaab566..72fd31124 100644 --- a/src/suggest/forms.py +++ b/src/suggest/forms.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -6,8 +5,8 @@ from django import forms from django.contrib.sites.models import Site from django.core.exceptions import ValidationError from django.core.mail import send_mail, mail_managers -from django.core.urlresolvers import reverse from django.core.validators import validate_email +from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext diff --git a/src/suggest/migrations/0001_initial.py b/src/suggest/migrations/0001_initial.py index b02889762..6e43ed17c 100644 --- a/src/suggest/migrations/0001_initial.py +++ b/src/suggest/migrations/0001_initial.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import models, migrations +import django.db.models.deletion from django.conf import settings @@ -21,7 +19,7 @@ class Migration(migrations.Migration): ('audiobooks', models.TextField(null=True, verbose_name='audiobooks', blank=True)), ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='creation date')), ('ip', models.GenericIPAddressField(verbose_name='IP address')), - ('user', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, blank=True, to=settings.AUTH_USER_MODEL, null=True)), ], options={ 'ordering': ('-created_at',), @@ -38,7 +36,7 @@ class Migration(migrations.Migration): ('description', models.TextField(verbose_name='Description', blank=True)), ('created_at', models.DateTimeField(auto_now=True, verbose_name='creation date')), ('ip', models.GenericIPAddressField(verbose_name='IP address')), - ('user', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, blank=True, to=settings.AUTH_USER_MODEL, null=True)), ], options={ 'ordering': ('-created_at',), diff --git a/src/suggest/migrations/0003_auto_20190729_1450.py b/src/suggest/migrations/0003_auto_20190729_1450.py new file mode 100644 index 000000000..6d0a3f445 --- /dev/null +++ b/src/suggest/migrations/0003_auto_20190729_1450.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-07-29 12:50 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('suggest', '0002_auto_20151221_1225'), + ] + + operations = [ + migrations.AlterField( + model_name='publishingsuggestion', + name='user', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='suggestion', + name='user', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/src/suggest/models.py b/src/suggest/models.py index b5fb06f9b..a5742d897 100644 --- a/src/suggest/models.py +++ b/src/suggest/models.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -15,7 +14,7 @@ class Suggestion(models.Model): description = models.TextField(_('description'), blank=True) created_at = models.DateTimeField(_('creation date'), auto_now=True) ip = models.GenericIPAddressField(_('IP address')) - user = models.ForeignKey(User, blank=True, null=True) + user = models.ForeignKey(User, models.SET_NULL, blank=True, null=True) class Meta: ordering = ('-created_at',) @@ -32,7 +31,7 @@ class PublishingSuggestion(models.Model): audiobooks = models.TextField(_('audiobooks'), null=True, blank=True) created_at = models.DateTimeField(_('creation date'), auto_now_add=True) ip = models.GenericIPAddressField(_('IP address')) - user = models.ForeignKey(User, blank=True, null=True) + user = models.ForeignKey(User, models.SET_NULL, blank=True, null=True) class Meta: ordering = ('-created_at',) diff --git a/src/suggest/views.py b/src/suggest/views.py index 706c549ab..060ac591e 100644 --- a/src/suggest/views.py +++ b/src/suggest/views.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # -from django.core.urlresolvers import reverse_lazy +from django.urls import reverse_lazy from django.utils.translation import ugettext_lazy as _ from ajaxable.utils import AjaxableFormView diff --git a/src/waiter/models.py b/src/waiter/models.py index 112e75499..09516a689 100644 --- a/src/waiter/models.py +++ b/src/waiter/models.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from os.path import join, isfile -from django.core.urlresolvers import reverse +from django.urls import reverse from django.db import models from waiter.settings import WAITER_URL, WAITER_MAX_QUEUE from waiter.utils import check_abspath diff --git a/src/wolnelektury/migrations/getpaid/0001_initial.py b/src/wolnelektury/migrations/getpaid/0001_initial.py index 36824d956..1271201c7 100644 --- a/src/wolnelektury/migrations/getpaid/0001_initial.py +++ b/src/wolnelektury/migrations/getpaid/0001_initial.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import models, migrations +import django.db.models.deletion import getpaid.abstract_mixin @@ -25,7 +23,7 @@ class Migration(migrations.Migration): ('amount_paid', models.DecimalField(default=0, verbose_name='amount paid', max_digits=20, decimal_places=4)), ('external_id', models.CharField(max_length=64, null=True, verbose_name='external id', blank=True)), ('description', models.CharField(max_length=128, null=True, verbose_name='Description', blank=True)), - ('order', models.ForeignKey(related_name='payment', to='funding.Funding')), + ('order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payment', to='funding.Funding')), ], options={ 'ordering': ('-created_on',), -- 2.20.1