Skip to content

Commit

Permalink
Django 1.10 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
yakky committed Aug 22, 2016
1 parent 70a5c61 commit d42a8a9
Show file tree
Hide file tree
Showing 22 changed files with 310 additions and 40 deletions.
51 changes: 50 additions & 1 deletion .travis.yml
Expand Up @@ -35,6 +35,11 @@ env:
- FRONTEND=1 INTEGRATION=1 INTEGRATION_TESTS_BUCKET=1 DJANGO=1.8 DATABASE_URL='sqlite://localhost/testdb.sqlite' MIGRATE_OPTION='--migrate'
- FRONTEND=1 INTEGRATION=1 INTEGRATION_TESTS_BUCKET=2 DJANGO=1.8 DATABASE_URL='sqlite://localhost/testdb.sqlite' MIGRATE_OPTION='--migrate'
- FRONTEND=1 INTEGRATION=1 INTEGRATION_TESTS_BUCKET=3 DJANGO=1.8 DATABASE_URL='sqlite://localhost/testdb.sqlite' MIGRATE_OPTION='--migrate'
- DJANGO=1.10 DATABASE_URL='sqlite://localhost/:memory:' MIGRATE_OPTION='--migrate'
- DJANGO=1.10 DATABASE_URL='mysql://root@127.0.0.1/djangocms_test'
- DJANGO=1.10 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' MIGRATE_OPTION='--migrate'
- DJANGO=1.10 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' AUTH_USER_MODEL='emailuserapp.EmailUser'
- DJANGO=1.10 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' AUTH_USER_MODEL='customuserapp.User'
- DJANGO=1.9 DATABASE_URL='sqlite://localhost/:memory:' MIGRATE_OPTION='--migrate'
- DJANGO=1.9 DATABASE_URL='mysql://root@127.0.0.1/djangocms_test'
- DJANGO=1.9 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' MIGRATE_OPTION='--migrate'
Expand Down Expand Up @@ -86,6 +91,17 @@ notifications:
matrix:
exclude:

- python: 3.3
env: DJANGO=1.10 DATABASE_URL='sqlite://localhost/:memory:' MIGRATE_OPTION='--migrate'
- python: 3.3
env: DJANGO=1.10 DATABASE_URL='mysql://root@127.0.0.1/djangocms_test'
- python: 3.3
env: DJANGO=1.10 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' MIGRATE_OPTION='--migrate'
- python: 3.3
env: DJANGO=1.10 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' AUTH_USER_MODEL='emailuserapp.EmailUser'
- python: 3.3
env: DJANGO=1.10 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' AUTH_USER_MODEL='customuserapp.User'

- python: 3.3
env: DJANGO=1.9 DATABASE_URL='sqlite://localhost/:memory:' MIGRATE_OPTION='--migrate'
- python: 3.3
Expand Down Expand Up @@ -141,10 +157,43 @@ matrix:
env: FRONTEND=1 INTEGRATION=1 INTEGRATION_TESTS_BUCKET=3 DJANGO=1.8 DATABASE_URL='sqlite://localhost/testdb.sqlite' MIGRATE_OPTION='--migrate'

allow_failures:

- python: 3.5
env: DJANGO=1.10 DATABASE_URL='sqlite://localhost/:memory:' MIGRATE_OPTION='--migrate'
- python: 3.5
env: DJANGO=1.10 DATABASE_URL='mysql://root@127.0.0.1/djangocms_test'
- python: 3.5
env: DJANGO=1.10 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' MIGRATE_OPTION='--migrate'
- python: 3.5
env: DJANGO=1.10 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' AUTH_USER_MODEL='emailuserapp.EmailUser'
- python: 3.5
env: DJANGO=1.10 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' AUTH_USER_MODEL='customuserapp.User'

- python: 3.4
env: DJANGO=1.10 DATABASE_URL='sqlite://localhost/:memory:' MIGRATE_OPTION='--migrate'
- python: 3.4
env: DJANGO=1.10 DATABASE_URL='mysql://root@127.0.0.1/djangocms_test'
- python: 3.4
env: DJANGO=1.10 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' MIGRATE_OPTION='--migrate'
- python: 3.4
env: DJANGO=1.10 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' AUTH_USER_MODEL='emailuserapp.EmailUser'
- python: 3.4
env: DJANGO=1.10 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' AUTH_USER_MODEL='customuserapp.User'

- python: 2.7
env: DJANGO=1.8 DATABASE_URL='mysql://root@127.0.0.1/djangocms_test'
env: DJANGO=1.10 DATABASE_URL='sqlite://localhost/:memory:' MIGRATE_OPTION='--migrate'
- python: 2.7
env: DJANGO=1.10 DATABASE_URL='mysql://root@127.0.0.1/djangocms_test'
- python: 2.7
env: DJANGO=1.10 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' MIGRATE_OPTION='--migrate'
- python: 2.7
env: DJANGO=1.10 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' AUTH_USER_MODEL='emailuserapp.EmailUser'
- python: 2.7
env: DJANGO=1.10 DATABASE_URL='postgres://postgres@127.0.0.1/djangocms_test' AUTH_USER_MODEL='customuserapp.User'

- python: 2.7
env: DJANGO=1.8 DATABASE_URL='mysql://root@127.0.0.1/djangocms_test'
- python: 2.7
env: DJANGO=1.9 DATABASE_URL='mysql://root@127.0.0.1/djangocms_test'

- python: 3.4
Expand Down
7 changes: 5 additions & 2 deletions cms/appresolver.py
Expand Up @@ -13,7 +13,7 @@

from cms.apphook_pool import apphook_pool
from cms.models.pagemodel import Page
from cms.utils.compat import DJANGO_1_8
from cms.utils.compat import DJANGO_1_8, DJANGO_1_9
from cms.utils.i18n import get_language_list

APP_RESOLVERS = []
Expand Down Expand Up @@ -149,7 +149,10 @@ def _set_permissions(patterns, exclude_permissions):
_set_permissions(pattern.url_patterns, exclude_permissions)
else:
from cms.utils.decorators import cms_perms
pattern._callback = cms_perms(pattern.callback)
if DJANGO_1_9:
pattern._callback = cms_perms(pattern.callback)
else:
pattern.callback = cms_perms(pattern.callback)


def get_app_urls(urls):
Expand Down
13 changes: 2 additions & 11 deletions cms/forms/widgets.py
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-

from itertools import chain

from django.contrib.admin.templatetags.admin_static import static
from django.contrib.auth import get_permission_codename
from django.contrib.sites.models import Site
Expand Down Expand Up @@ -175,7 +173,7 @@ class UserSelectAdminWidget(Select):
attribute.
"""
def render(self, name, value, attrs=None, choices=()):
output = [super(UserSelectAdminWidget, self).render(name, value, attrs, choices)]
output = [super(UserSelectAdminWidget, self).render(name, value, attrs)]
if hasattr(self, 'user') and (self.user.is_superuser or \
self.user.has_perm(PageUser._meta.app_label + '.' + get_permission_codename('add', PageUser._meta))):
# append + icon
Expand Down Expand Up @@ -225,13 +223,6 @@ def render_option(self, selected_choices, option_value, option_label):
force_text(option_label),
)

def render_options(self, choices, selected_choices):
selected_choices = set(force_text(v) for v in selected_choices)
output = []
for option_value, option_label in chain(self.choices, choices):
output.append(self.render_option(selected_choices, option_value, option_label))
return '\n'.join(output)


class ApplicationConfigSelect(Select):
"""
Expand All @@ -255,7 +246,7 @@ def __init__(self, attrs=None, choices=(), app_configs={}):
super(ApplicationConfigSelect, self).__init__(attrs, choices)

def render(self, name, value, attrs=None, choices=()):
output = list(super(ApplicationConfigSelect, self).render(name, value, attrs, choices))
output = list(super(ApplicationConfigSelect, self).render(name, value, attrs))
output.append('<script>\n')
output.append('var apphooks_configuration = {\n')
for application, cms_app in self.app_configs.items():
Expand Down
14 changes: 12 additions & 2 deletions cms/plugin_rendering.py
Expand Up @@ -2,7 +2,7 @@
from collections import deque

from classytags.utils import flatten_context
from django.template import Template, Context
from django.template import Context
from django.template.loader import get_template
from django.utils.functional import cached_property
from django.utils.safestring import mark_safe
Expand Down Expand Up @@ -83,10 +83,13 @@ def placeholder_cache_is_enabled(self):
return not self.user_is_on_edit_mode()

def get_cached_template(self, template):
if isinstance(template, Template):
# we check if template quacks like a Template, as generic Template and engine-specific Template
# does not share a common ancestor
if hasattr(template, 'render'):
return template

if not template in self._cached_templates:
# this always return a enging-specific template object
self._cached_templates[template] = get_template(template)
return self._cached_templates[template]

Expand Down Expand Up @@ -289,8 +292,15 @@ def render_plugin(self, instance, context, placeholder=None, editable=False):
if not instance or not plugin.render_plugin:
return ''

# we'd better pass a flat dict to template.render
# as plugin.render can return pretty much any kind of context / dictionary
# we'd better flatten it and force to a Context object
# flattening the context means that template must be an engine-specific template object
# which is guaranteed by get_cached_template if the template returned by
# plugin._get_render_template is either a string or an engine-specific template object
context = PluginContext(context, instance, placeholder)
context = plugin.render(context, instance, placeholder.slot)
context = flatten_context(context)

template = plugin._get_render_template(context, instance, placeholder)
template = self.get_cached_template(template)
Expand Down
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.9 on 2016-08-16 12:16
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('bunch_of_plugins', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='testplugin1',
name='cmsplugin_ptr',
field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='bunch_of_plugins_testplugin1', serialize=False, to='cms.CMSPlugin'),
),
migrations.AlterField(
model_name='testplugin2',
name='cmsplugin_ptr',
field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='bunch_of_plugins_testplugin2', serialize=False, to='cms.CMSPlugin'),
),
]
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.9 on 2016-08-16 12:16
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('cms', '0016_auto_20160608_1535'),
('extensionapp', '0002_auto_20150607_2207'),
]

operations = [
migrations.CreateModel(
name='MultiTablePageExtensionParent',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('extension_parent_field', models.CharField(blank=True, default=b'', max_length=255)),
],
),
migrations.CreateModel(
name='MultiTableTitleExtensionParent',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('extension_title_parent_field', models.CharField(blank=True, default=b'', max_length=255)),
],
),
migrations.CreateModel(
name='MultiTablePageExtension',
fields=[
('multitablepageextensionparent_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='extensionapp.MultiTablePageExtensionParent')),
('multitable_extra', models.CharField(blank=True, default=b'', max_length=255)),
('extended_object', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, to='cms.Page')),
('public_extension', models.OneToOneField(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='draft_extension', to='extensionapp.MultiTablePageExtension')),
],
options={
'abstract': False,
},
bases=('extensionapp.multitablepageextensionparent', models.Model),
),
migrations.CreateModel(
name='MultiTableTitleExtension',
fields=[
('multitabletitleextensionparent_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='extensionapp.MultiTableTitleExtensionParent')),
('multitable_extra_title', models.CharField(blank=True, default=b'', max_length=255)),
('extended_object', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, to='cms.Title')),
('public_extension', models.OneToOneField(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='draft_extension', to='extensionapp.MultiTableTitleExtension')),
],
options={
'abstract': False,
},
bases=('extensionapp.multitabletitleextensionparent', models.Model),
),
]
Expand Up @@ -7,7 +7,7 @@
class Migration(migrations.Migration):

dependencies = [
('cms', '0015_auto_20160409_0838'),
('cms', '0016_auto_20160608_1535'),
('mti_pluginapp', '0002_auto_20150112_2250'),
]

Expand All @@ -22,7 +22,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='TestPluginGammaModel',
fields=[
('cmsplugin_ptr', models.OneToOneField(parent_link=True, related_name=b'mti_pluginapp_testplugingammamodel', auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')),
('cmsplugin_ptr', models.OneToOneField(parent_link=True, related_name='mti_pluginapp_testplugingammamodel', auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')),
('abs', models.CharField(default=b'test plugin abs', max_length=32, verbose_name=b'abs')),
('gamma', models.CharField(default=b'test plugin gamma', max_length=32, verbose_name=b'gamma')),
],
Expand Down Expand Up @@ -57,17 +57,20 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='LessMixedPlugin',
fields=[
('nonpluginmodel_ptr', models.OneToOneField(parent_link=True, auto_created=True, to='mti_pluginapp.NonPluginModel')),
('cmsplugin_ptr', models.OneToOneField(parent_link=True, related_name='mti_pluginapp_lessmixedplugin', auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')),
('less_mixed', models.CharField(default=b'test plugin mixed', max_length=32, verbose_name=b'mixed')),
],
options={
'abstract': False,
},
bases=('mti_pluginapp.nonpluginmodel', 'cms.cmsplugin'),
bases=('cms.cmsplugin', 'mti_pluginapp.nonpluginmodel'),
),
migrations.CreateModel(
name='MixedPlugin',
fields=[
('cmsplugin_ptr', models.OneToOneField(parent_link=True, auto_created=True, to='cms.CMSPlugin')),
('nonpluginmodel_ptr', models.OneToOneField(parent_link=True, auto_created=True, to='mti_pluginapp.NonPluginModel')),
('cmsplugin_ptr', models.OneToOneField(parent_link=True, related_name='mti_pluginapp_mixedplugin', auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')),
('abs', models.CharField(default=b'test plugin abs', max_length=32, verbose_name=b'abs')),
('mixed', models.CharField(default=b'test plugin mixed', max_length=32, verbose_name=b'mixed')),
],
Expand Down
2 changes: 1 addition & 1 deletion cms/test_utils/project/mti_pluginapp/models.py
Expand Up @@ -87,7 +87,7 @@ class MixedPlugin(AbstractPluginParent, NonPluginModel):
mixed = models.CharField('mixed', blank=False, default='test plugin mixed', max_length=32)


class LessMixedPlugin(NonPluginModel, CMSPlugin):
class LessMixedPlugin(CMSPlugin, NonPluginModel):
"""
Plugin which inherits from two concrete models, one of which is CMSPlugin
"""
Expand Down
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.9 on 2016-08-16 12:16
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('placeholderapp', '0005_example1_decimal_field'),
]

operations = [
migrations.AlterModelOptions(
name='multilingualexample1translation',
options={'default_permissions': (), 'managed': True},
),
]
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.9 on 2016-08-16 12:16
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('manytomany_rel', '0002_auto_20151101_0919'),
]

operations = [
migrations.AlterField(
model_name='articlepluginmodel',
name='cmsplugin_ptr',
field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='manytomany_rel_articlepluginmodel', serialize=False, to='cms.CMSPlugin'),
),
migrations.AlterField(
model_name='pluginmodelwithfkfrommodel',
name='cmsplugin_ptr',
field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='manytomany_rel_pluginmodelwithfkfrommodel', serialize=False, to='cms.CMSPlugin'),
),
migrations.AlterField(
model_name='pluginmodelwithm2mtomodel',
name='cmsplugin_ptr',
field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='manytomany_rel_pluginmodelwithm2mtomodel', serialize=False, to='cms.CMSPlugin'),
),
]
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.9 on 2016-08-16 12:16
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('meta', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='testpluginmodel',
name='cmsplugin_ptr',
field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='meta_testpluginmodel', serialize=False, to='cms.CMSPlugin'),
),
migrations.AlterField(
model_name='testpluginmodel2',
name='cmsplugin_ptr',
field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='meta_testpluginmodel2', serialize=False, to='cms.CMSPlugin'),
),
migrations.AlterField(
model_name='testpluginmodel4',
name='cmsplugin_ptr',
field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='meta_testpluginmodel4', serialize=False, to='cms.CMSPlugin'),
),
]

0 comments on commit d42a8a9

Please sign in to comment.