Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 2.x compatibility and upgraded test suite #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aldryn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 10 additions & 4 deletions aldryn_redirects/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion aldryn_redirects/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions aldryn_redirects/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',),
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions aldryn_redirects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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=_(
Expand Down
69 changes: 0 additions & 69 deletions aldryn_redirects/south_migrations/0001_initial.py

This file was deleted.

Empty file.
2 changes: 1 addition & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
26 changes: 25 additions & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand All @@ -26,6 +49,7 @@
('en', 'English'),
('pt-br', 'Brazilian Portugues'),
],
'MIGRATION_MODULES': DisableMigrations(),
}


Expand Down
18 changes: 11 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
[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


[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
Expand Down