diff --git a/aldryn_config.py b/aldryn_config.py index 0a1eabc..d6f6ca1 100644 --- a/aldryn_config.py +++ b/aldryn_config.py @@ -4,5 +4,5 @@ class Form(forms.BaseForm): def to_settings(self, data, settings): # No need to setup django-parler. That is already done in aldryn-django-cms - settings['MIDDLEWARE_CLASSES'].insert(0, 'aldryn_redirects.middleware.RedirectFallbackMiddleware') + settings['MIDDLEWARE'].insert(0, 'aldryn_redirects.middleware.RedirectFallbackMiddleware') return settings diff --git a/aldryn_redirects/admin.py b/aldryn_redirects/admin.py index f4ab150..b13548d 100644 --- a/aldryn_redirects/admin.py +++ b/aldryn_redirects/admin.py @@ -4,7 +4,7 @@ from django.conf import settings from django.contrib import admin, messages -from django.core.urlresolvers import reverse +from django.urls import reverse from django.http import HttpResponse from django.shortcuts import redirect, render from django.utils import timezone @@ -19,9 +19,9 @@ class DeletionMixin(object): - actions = ['delete_selected'] + actions = ['delete_selected_redirect'] - def delete_selected(self, request, queryset): + def delete_selected_redirect(self, request, queryset): max_items_deletion = getattr(settings, 'DATA_UPLOAD_MAX_NUMBER_FIELDS', 1000) # COMPAT: Django<1.10 if queryset.count() > max_items_deletion: @@ -37,7 +37,7 @@ def delete_selected(self, request, queryset): object_label = self.opts.verbose_name_plural if deleted_qty > 1 else self.opts.verbose_name msg = _('Successfully deleted {qty} {object_label}.').format(qty=deleted_qty, object_label=object_label) self.message_user(request, msg) - delete_selected.short_description = _('Delete selected objects') + delete_selected_redirect.short_description = _('Delete selected objects') class RedirectAdmin(DeletionMixin, AllTranslationsMixin, TranslatableAdmin): @@ -47,6 +47,11 @@ class RedirectAdmin(DeletionMixin, AllTranslationsMixin, TranslatableAdmin): radio_fields = {'site': admin.VERTICAL} export_filename = 'redirects-%Y-%m-%d.csv' export_headers = ['Domain', 'Old', 'New', 'Language'] + actions = DeletionMixin.actions + + def get_actions(self, request): + print("Ignoring the debug mate") + return [] def get_urls(self): from django.conf.urls import url @@ -138,6 +143,7 @@ class StaticRedirectAdmin(DeletionMixin, admin.ModelAdmin): list_filter = ('sites',) list_display = ('inbound_route', 'outbound_route') search_fields = list_display + actions = DeletionMixin.actions # Custom attributes export_filename = 'static-redirects-%Y-%m-%d.csv' diff --git a/aldryn_redirects/middleware.py b/aldryn_redirects/middleware.py index c7a5ac9..6967f9b 100644 --- a/aldryn_redirects/middleware.py +++ b/aldryn_redirects/middleware.py @@ -4,11 +4,12 @@ from django.conf import settings from django.contrib.sites.models import Site from django.db.models import Q +from django.utils.deprecation import MiddlewareMixin from .models import Redirect, StaticRedirect -class RedirectFallbackMiddleware(object): +class RedirectFallbackMiddleware(MiddlewareMixin): def process_request(self, request): static_redirect = StaticRedirect.objects.get_for_request(request) if static_redirect: diff --git a/aldryn_redirects/migrations/0001_initial.py b/aldryn_redirects/migrations/0001_initial.py index ccd3c35..6d5b9be 100644 --- a/aldryn_redirects/migrations/0001_initial.py +++ b/aldryn_redirects/migrations/0001_initial.py @@ -16,7 +16,7 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('old_path', models.CharField(help_text="This should be an absolute path, excluding the domain name. Example: '/events/search/'.", max_length=200, verbose_name='redirect from', db_index=True)), - ('site', models.ForeignKey(related_name='redirects_hvad_set', to='sites.Site')), + ('site', models.ForeignKey(on_delete=models.deletion.CASCADE, related_name='redirects_hvad_set', to='sites.Site')), ], options={ 'ordering': ('old_path',), @@ -30,7 +30,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('new_path', models.CharField(help_text="This can be either an absolute path (as above) or a full URL starting with 'http://'.", max_length=200, verbose_name='redirect to', blank=True)), ('language_code', models.CharField(max_length=15, db_index=True)), - ('master', models.ForeignKey(related_name='translations', editable=False, to='aldryn_redirects.Redirect', null=True)), + ('master', models.ForeignKey(on_delete=models.deletion.CASCADE, related_name='translations', editable=False, to='aldryn_redirects.Redirect', null=True)), ], options={ 'managed': True, diff --git a/aldryn_redirects/models.py b/aldryn_redirects/models.py index 5ac35b2..f9d8f1d 100644 --- a/aldryn_redirects/models.py +++ b/aldryn_redirects/models.py @@ -2,7 +2,7 @@ from django.db import models from django.contrib.sites.models import Site -from django.core.urlresolvers import reverse +from django.urls import reverse from django.utils.encoding import python_2_unicode_compatible from django.utils.translation import ugettext_lazy as _, ugettext @@ -17,7 +17,7 @@ @python_2_unicode_compatible class Redirect(TranslatableModel): site = models.ForeignKey( - Site, related_name='aldryn_redirects_redirect_set') + Site, related_name='aldryn_redirects_redirect_set', on_delete=models.CASCADE) old_path = models.CharField( _('redirect from'), max_length=400, db_index=True, help_text=_( diff --git a/aldryn_redirects/south_migrations/0001_initial.py b/aldryn_redirects/south_migrations/0001_initial.py deleted file mode 100644 index e68cc36..0000000 --- a/aldryn_redirects/south_migrations/0001_initial.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- -import datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models - - -class Migration(SchemaMigration): - - def forwards(self, orm): - # Adding model 'RedirectTranslation' - db.create_table(u'aldryn_redirects_redirect_translation', ( - (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('new_path', self.gf('django.db.models.fields.CharField')(max_length=200, blank=True)), - ('language_code', self.gf('django.db.models.fields.CharField')(max_length=15, db_index=True)), - ('master', self.gf('django.db.models.fields.related.ForeignKey')(related_name='translations', null=True, to=orm['aldryn_redirects.Redirect'])), - )) - db.send_create_signal(u'aldryn_redirects', ['RedirectTranslation']) - - # Adding unique constraint on 'RedirectTranslation', fields ['language_code', 'master'] - db.create_unique(u'aldryn_redirects_redirect_translation', ['language_code', 'master_id']) - - # Adding model 'Redirect' - db.create_table(u'aldryn_redirects_redirect', ( - (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('site', self.gf('django.db.models.fields.related.ForeignKey')(related_name='redirects_hvad_set', to=orm['sites.Site'])), - ('old_path', self.gf('django.db.models.fields.CharField')(max_length=200, db_index=True)), - )) - db.send_create_signal(u'aldryn_redirects', ['Redirect']) - - # Adding unique constraint on 'Redirect', fields ['site', 'old_path'] - db.create_unique(u'aldryn_redirects_redirect', ['site_id', 'old_path']) - - def backwards(self, orm): - # Removing unique constraint on 'Redirect', fields ['site', 'old_path'] - db.delete_unique(u'aldryn_redirects_redirect', ['site_id', 'old_path']) - - # Removing unique constraint on 'RedirectTranslation', fields ['language_code', 'master'] - db.delete_unique(u'aldryn_redirects_redirect_translation', ['language_code', 'master_id']) - - # Deleting model 'RedirectTranslation' - db.delete_table(u'aldryn_redirects_redirect_translation') - - # Deleting model 'Redirect' - db.delete_table(u'aldryn_redirects_redirect') - - models = { - u'aldryn_redirects.redirect': { - 'Meta': {'ordering': "('old_path',)", 'unique_together': "(('site', 'old_path'),)", 'object_name': 'Redirect'}, - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'old_path': ('django.db.models.fields.CharField', [], {'max_length': '200', 'db_index': 'True'}), - 'site': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'redirects_hvad_set'", 'to': u"orm['sites.Site']"}) - }, - u'aldryn_redirects.redirecttranslation': { - 'Meta': {'unique_together': "[('language_code', 'master')]", 'object_name': 'RedirectTranslation', 'db_table': "u'aldryn_redirects_redirect_translation'"}, - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'language_code': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}), - 'master': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'translations'", 'null': 'True', 'to': u"orm['aldryn_redirects.Redirect']"}), - 'new_path': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}) - }, - u'sites.site': { - 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"}, - 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) - } - } - - complete_apps = ['aldryn_redirects'] diff --git a/aldryn_redirects/south_migrations/__init__.py b/aldryn_redirects/south_migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/requirements.txt b/tests/requirements.txt index ca06b8c..2a88b15 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,4 +1,4 @@ -djangocms-helper>=0.9.2,<0.10 +djangocms-helper>1.2 tox>=2.9.1 coverage>=4.4.2 flake8>=3.0.4 diff --git a/tests/settings.py b/tests/settings.py index 9a0fa81..11306ce 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -2,8 +2,31 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals, print_function, division + +class DisableMigrations(object): + """ + Django-cms disables all migrations when they run their tests. + It would be better to not do it. Right now we are forced to disable our + migrations because we inherit one of our models from django-cms. + The error in question is due to an incompability of sqlite3 and + with atomic transactions. + + Error: "django.db.utils.NotSupportedError: Renaming the 'cms_title' table while in a + transaction is not supported on SQLite because it would break referential integrity. + Try adding `atomic = False` to the Migration class. + """ + def __contains__(self, item): + return True + + def __getitem__(self, item): + return None + + HELPER_SETTINGS = { - 'MIDDLEWARE_CLASSES': [ + 'MIDDLEWARE': [ + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', 'aldryn_redirects.middleware.RedirectFallbackMiddleware', ], 'INSTALLED_APPS': [ @@ -26,6 +49,7 @@ ('en', 'English'), ('pt-br', 'Brazilian Portugues'), ], + 'MIGRATION_MODULES': DisableMigrations(), } diff --git a/tox.ini b/tox.ini index 4bcd2c5..903f8ed 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] envlist = flake8 - py{36,35,27}-dj{18,19,110,111}-cms{34,33} + py{35,36,37}-dj{111,20,21,22}-cms{36,37,40} skip_missing_interpreters=True @@ -9,12 +9,16 @@ skip_missing_interpreters=True [testenv] deps = -r{toxinidir}/tests/requirements.txt - dj18: Django>=1.8,<1.9 - dj19: Django>=1.9,<1.10 - dj110: Django>=1.10,<1.11 - dj111: Django>=1.11,<1.12 - cms33: django-cms>=3.3,<3.4 - cms34: django-cms>=3.4,<3.5 + # django + dj111: Django>=1.11,<2.0 + dj20: Django>=2.0,<2.1 + dj21: Django>=2.1,<2.2 + dj22: Django>=2.2,<3.0 + # django CMS + cms36: django-cms>=3.6,<3.7 + cms37: django-cms>=3.7,<3.8 + cms40: https://github.com/divio/django-cms/archive/release/4.0.x.zip + commands = {envpython} --version {env:COMMAND:coverage} erase