Skip to content

Commit

Permalink
Merge branch 'feature/fix-migrations-387' into develop, close #387
Browse files Browse the repository at this point in the history
  • Loading branch information
Fantomas42 committed Jan 5, 2015
2 parents 679ce6a + 896117c commit 7f16698
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
3 changes: 2 additions & 1 deletion zinnia/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import mptt.fields
import tagging.fields

import zinnia.models_bases.entry
from zinnia.migrations import user_model_label


Expand Down Expand Up @@ -58,7 +59,7 @@ class Migration(migrations.Migration):
('pingback_count', models.IntegerField(default=0, verbose_name='pingback count')),
('trackback_count', models.IntegerField(default=0, verbose_name='trackback count')),
('excerpt', models.TextField(help_text='Used for search and SEO.', verbose_name='excerpt', blank=True)),
('image', models.ImageField(help_text='Used for illustration.', upload_to='uploads/zinnia', verbose_name='image', blank=True)),
('image', models.ImageField(help_text='Used for illustration.', upload_to=zinnia.models_bases.entry.image_upload_to_dispatcher, verbose_name='image', blank=True)),
('featured', models.BooleanField(default=False, verbose_name='featured')),
('tags', tagging.fields.TagField(max_length=255, verbose_name='tags', blank=True)),
('login_required', models.BooleanField(default=False, help_text='Only authenticated users can view the entry.', verbose_name='login required')),
Expand Down
16 changes: 9 additions & 7 deletions zinnia/models_bases/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,15 @@ class Meta:
abstract = True


def image_upload_to_dispatcher(entry, filename):
"""
Dispatch function to allow overriding of ``image_upload_to`` method.
Outside the model for fixing an issue with Django's migrations on Python 2.
"""
return entry.image_upload_to(filename)


class ImageEntry(models.Model):
"""
Abstract model class to add an image to the entries.
Expand All @@ -380,13 +389,6 @@ def image_upload_to(self, filename):
now.strftime('%d'),
'%s%s' % (slugify(filename), extension))

def image_upload_to_dispatcher(self, filename):
"""
Dispatch method to allow overriding of ``image_upload_to``.
Do not override this method directly.
"""
return self.image_upload_to(filename)

image = models.ImageField(
_('image'), blank=True,
upload_to=image_upload_to_dispatcher,
Expand Down
14 changes: 6 additions & 8 deletions zinnia/tests/test_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,22 +317,20 @@ def test_tags_list(self):
self.assertEqual(self.entry.tags_list, ['tag-1', 'tag-2'])

def test_image_upload_to_dispatcher(self):
entry = Entry()
path = entry.image_upload_to_dispatcher('image.gif')
path = entry.image_upload_to_dispatcher(self.entry, 'image.gif')
self.assertTrue(path.endswith('image.gif'))

class EntryCustomImageUploadTo(Entry):
def image_upload_to(self, filename):
return 'custom.png'

entry = EntryCustomImageUploadTo()
custom_entry = EntryCustomImageUploadTo()
self.assertEqual(
entry.image_upload_to_dispatcher('image.gif'),
entry.image_upload_to_dispatcher(custom_entry, 'image.gif'),
'custom.png')

def test_image_upload_to(self):
entry = Entry()
path = entry.image_upload_to('Desktop wallpaper.jpeg')
path = self.entry.image_upload_to('Desktop wallpaper.jpeg')
path_split = path.split('/')
self.assertEqual(path_split[-1], 'desktop-wallpaper.jpeg')
for i in range(1, 4):
Expand Down Expand Up @@ -413,8 +411,8 @@ def check_get_absolute_url(self, creation_date, url_expected):
'content': 'My content',
'slug': 'my-entry',
'creation_date': creation_date}
entry = Entry.objects.create(**params)
self.assertTrue(url_expected in entry.get_absolute_url())
e = Entry.objects.create(**params)
self.assertTrue(url_expected in e.get_absolute_url())

@override_settings(USE_TZ=False)
def test_get_absolute_url_no_timezone(self):
Expand Down

0 comments on commit 7f16698

Please sign in to comment.