From fffc2a633ef3ae1cf8050eecb9dd6dadc9aed9b5 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sun, 22 May 2016 12:11:16 +0200 Subject: [PATCH] Fix support for new filer ThumbnailOption --- .../migrations/0017_thumbnail_move.py | 35 +++++++++++++++++++ djangocms_blog/models.py | 15 +++++--- ..._full__chg_field_post_date_published__c.py | 24 ++++++++----- ...g_field_post_main_image_full__chg_field.py | 21 ++++++++--- tests/base.py | 8 +---- 5 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 djangocms_blog/migrations/0017_thumbnail_move.py diff --git a/djangocms_blog/migrations/0017_thumbnail_move.py b/djangocms_blog/migrations/0017_thumbnail_move.py new file mode 100644 index 0000000..1b1cb47 --- /dev/null +++ b/djangocms_blog/migrations/0017_thumbnail_move.py @@ -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), + ), + ] diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index 2de6307..6751aca 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -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 diff --git a/djangocms_blog/south_migrations/0017_auto__chg_field_post_main_image_full__chg_field_post_date_published__c.py b/djangocms_blog/south_migrations/0017_auto__chg_field_post_main_image_full__chg_field_post_date_published__c.py index 0527af0..ff9f339 100644 --- a/djangocms_blog/south_migrations/0017_auto__chg_field_post_main_image_full__chg_field_post_date_published__c.py +++ b/djangocms_blog/south_migrations/0017_auto__chg_field_post_main_image_full__chg_field_post_date_published__c.py @@ -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': { @@ -228,4 +234,4 @@ class Migration(SchemaMigration): } } - complete_apps = ['djangocms_blog'] \ No newline at end of file + complete_apps = ['djangocms_blog'] diff --git a/djangocms_blog/south_migrations/0019_auto__chg_field_post_author__chg_field_post_main_image_full__chg_field.py b/djangocms_blog/south_migrations/0019_auto__chg_field_post_author__chg_field_post_main_image_full__chg_field.py index b74748c..a2bea06 100644 --- a/djangocms_blog/south_migrations/0019_auto__chg_field_post_author__chg_field_post_main_image_full__chg_field.py +++ b/djangocms_blog/south_migrations/0019_auto__chg_field_post_author__chg_field_post_main_image_full__chg_field.py @@ -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': { @@ -229,4 +240,4 @@ class Migration(SchemaMigration): } } - complete_apps = ['djangocms_blog'] \ No newline at end of file + complete_apps = ['djangocms_blog'] diff --git a/tests/base.py b/tests/base.py index c28987e..6fee09c 100644 --- a/tests/base.py +++ b/tests/base.py @@ -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()