Fix support for new filer ThumbnailOption

This commit is contained in:
Iacopo Spalletti 2016-05-22 12:11:16 +02:00
parent 758989ad24
commit fffc2a633e
No known key found for this signature in database
GPG key ID: BDCBC2EB289F60C6
5 changed files with 78 additions and 25 deletions

View file

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from djangocms_blog.models import thumbnail_model
class Migration(migrations.Migration):
if 'cmsplugin_filer' not in thumbnail_model:
dependencies = [
('djangocms_blog', '0016_auto_20160502_1741'),
('cmsplugin_filer_image', '0006_auto_20160427_1438')
]
else:
dependencies = [
('djangocms_blog', '0016_auto_20160502_1741'),
]
operations = [
migrations.AlterField(
model_name='post',
name='main_image_full',
field=models.ForeignKey(related_name='djangocms_blog_post_full',
verbose_name='Main image full', blank=True,
to=thumbnail_model, null=True),
),
migrations.AlterField(
model_name='post',
name='main_image_thumbnail',
field=models.ForeignKey(related_name='djangocms_blog_post_thumbnail',
verbose_name='Main image thumbnail', blank=True,
to=thumbnail_model, null=True),
),
]

View file

@ -33,11 +33,18 @@ BLOG_CURRENT_POST_IDENTIFIER = get_setting('CURRENT_POST_IDENTIFIER')
BLOG_CURRENT_NAMESPACE = get_setting('CURRENT_NAMESPACE')
try:
from filer.models import ThumbnailOption # NOQA
thumbnail_model = 'filer.ThumbnailOption'
except ImportError:
from cmsplugin_filer_image.models import ThumbnailOption # NOQA
thumbnail_model = 'cmsplugin_filer_image.ThumbnailOption'
except ImportError:
from filer.models import ThumbnailOption # NOQA
try:
thumbnail_model = '%s.%s' % (
ThumbnailOption._meta.app_label, ThumbnailOption._meta.model_name
)
except AttributeError:
thumbnail_model = '%s.%s' % (
ThumbnailOption._meta.app_label, ThumbnailOption._meta.module_name
)
try:
from knocker.mixins import KnockerModel

View file

@ -3,31 +3,37 @@ from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
from djangocms_blog.models import thumbnail_model
class Migration(SchemaMigration):
def forwards(self, orm):
if 'cmsplugin_filer' not in thumbnail_model:
dependencies = [
('cmsplugin_filer_image', '0014_auto__del_thumbnailoption__chg_field_filerimage_thumbnail_option')
]
# Changing field 'Post.main_image_full'
db.alter_column(u'djangocms_blog_post', 'main_image_full_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['cmsplugin_filer_image.ThumbnailOption']))
def forwards(self, orm):
# Changing field 'Post.date_published'
db.alter_column(u'djangocms_blog_post', 'date_published', self.gf('django.db.models.fields.DateTimeField')(null=True))
# Changing field 'Post.main_image_full'
db.alter_column(u'djangocms_blog_post', 'main_image_full_id', self.gf('django.db.models.fields.related.ForeignKey')(on_delete=models.SET_NULL, null=True, to=orm[thumbnail_model]))
# Changing field 'Post.main_image_thumbnail'
db.alter_column(u'djangocms_blog_post', 'main_image_thumbnail_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['cmsplugin_filer_image.ThumbnailOption']))
db.alter_column(u'djangocms_blog_post', 'main_image_thumbnail_id', self.gf('django.db.models.fields.related.ForeignKey')(on_delete=models.SET_NULL, null=True, to=orm[thumbnail_model]))
def backwards(self, orm):
# Changing field 'Post.main_image_full'
db.alter_column(u'djangocms_blog_post', 'main_image_full_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm[thumbnail_model], null=True, on_delete=models.SET_NULL))
# Changing field 'Post.date_published'
db.alter_column(u'djangocms_blog_post', 'date_published', self.gf('django.db.models.fields.DateTimeField')())
# Changing field 'Post.main_image_full'
db.alter_column(u'djangocms_blog_post', 'main_image_full_id', self.gf('django.db.models.fields.related.ForeignKey')(on_delete=models.SET_NULL, null=True, to=orm[thumbnail_model]))
# Changing field 'Post.main_image_thumbnail'
db.alter_column(u'djangocms_blog_post', 'main_image_thumbnail_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm[thumbnail_model], null=True, on_delete=models.SET_NULL))
db.alter_column(u'djangocms_blog_post', 'main_image_thumbnail_id', self.gf('django.db.models.fields.related.ForeignKey')(on_delete=models.SET_NULL, null=True, to=orm[thumbnail_model]))
models = {
u'auth.group': {

View file

@ -3,20 +3,31 @@ from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
from djangocms_blog.models import thumbnail_model
class Migration(SchemaMigration):
if 'cmsplugin_filer' not in thumbnail_model:
dependencies = [
('djangocms_blog', '0018_auto__chg_field_post_main_image_full__chg_field_post_main_image_thumbn'),
('cmsplugin_filer_image', '0014_auto__del_thumbnailoption__chg_field_filerimage_thumbnail_option')
]
else:
dependencies = [
('djangocms_blog', '0018_auto__chg_field_post_main_image_full__chg_field_post_main_image_thumbn'),
]
def forwards(self, orm):
# Changing field 'Post.author'
db.alter_column('djangocms_blog_post', 'author_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['test_utils.CustomUser']))
# Changing field 'Post.main_image_full'
db.alter_column('djangocms_blog_post', 'main_image_full_id', self.gf('django.db.models.fields.related.ForeignKey')(on_delete=models.SET_NULL, null=True, to=orm['filer.ThumbnailOption']))
db.alter_column('djangocms_blog_post', 'main_image_full_id', self.gf('django.db.models.fields.related.ForeignKey')(on_delete=models.SET_NULL, null=True, to=orm[thumbnail_model]))
# Changing field 'Post.main_image_thumbnail'
db.alter_column('djangocms_blog_post', 'main_image_thumbnail_id', self.gf('django.db.models.fields.related.ForeignKey')(on_delete=models.SET_NULL, null=True, to=orm['filer.ThumbnailOption']))
db.alter_column('djangocms_blog_post', 'main_image_thumbnail_id', self.gf('django.db.models.fields.related.ForeignKey')(on_delete=models.SET_NULL, null=True, to=orm[thumbnail_model]))
def backwards(self, orm):
@ -24,10 +35,10 @@ class Migration(SchemaMigration):
db.alter_column('djangocms_blog_post', 'author_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['auth.User']))
# Changing field 'Post.main_image_full'
db.alter_column('djangocms_blog_post', 'main_image_full_id', self.gf('django.db.models.fields.related.ForeignKey')(on_delete=models.SET_NULL, null=True, to=orm['cmsplugin_filer_image.ThumbnailOption']))
db.alter_column('djangocms_blog_post', 'main_image_full_id', self.gf('django.db.models.fields.related.ForeignKey')(on_delete=models.SET_NULL, null=True, to=orm[thumbnail_model]))
# Changing field 'Post.main_image_thumbnail'
db.alter_column('djangocms_blog_post', 'main_image_thumbnail_id', self.gf('django.db.models.fields.related.ForeignKey')(on_delete=models.SET_NULL, null=True, to=orm['cmsplugin_filer_image.ThumbnailOption']))
db.alter_column('djangocms_blog_post', 'main_image_thumbnail_id', self.gf('django.db.models.fields.related.ForeignKey')(on_delete=models.SET_NULL, null=True, to=orm[thumbnail_model]))
models = {
'auth.group': {

View file

@ -6,7 +6,6 @@ from copy import deepcopy
from django.contrib.auth import get_user_model
from django.contrib.sites.models import Site
from django.core.cache import cache
from django.core.management import call_command
from djangocms_helper.base_test import BaseTestCase
from haystack import connections
@ -14,12 +13,7 @@ from haystack.constants import DEFAULT_ALIAS
from parler.utils.context import smart_override
from djangocms_blog.cms_appconfig import BlogConfig
from djangocms_blog.models import BlogCategory, Post
try:
from filer.models import ThumbnailOption # NOQA
except ImportError:
from cmsplugin_filer_image.models import ThumbnailOption # NOQA
from djangocms_blog.models import BlogCategory, Post, ThumbnailOption
User = get_user_model()