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

some improvements for migrations and for ZINNIA_MARKDOWN_EXTENSIONS #401

Closed
wants to merge 6 commits into from
Closed
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
20 changes: 20 additions & 0 deletions demo/models_bases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-

"""
A simple example of using ZINNIA_IMAGE_FIELD to set Entry.image as ForeignKey to other model
"""

from django.conf import settings
from django.db.models import SET_NULL
from django.utils.translation import ugettext_lazy as _

if 'filer' in settings.INSTALLED_APPS:
from filer.fields.image import FilerImageField
ZINNIA_IMAGE_FIELD = FilerImageField(
blank=True,
null=True,
related_name='entry_illustration',
help_text=_('Used for illustration.'),
db_column='image',
on_delete=SET_NULL,
default=None,)
21 changes: 20 additions & 1 deletion demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,27 @@
'django_xmlrpc',
'mptt',
'tagging',
'zinnia'
'zinnia',
# 'filer',
)

from zinnia.xmlrpc import ZINNIA_XMLRPC_METHODS
XMLRPC_METHODS = ZINNIA_XMLRPC_METHODS

if 'filer' in INSTALLED_APPS:
ZINNIA_IMAGE_FIELD = 'demo.models_bases.ZINNIA_IMAGE_FIELD'
INSTALLED_APPS += (
'polymorphic',
'easy_thumbnails',
)
THUMBNAIL_HIGH_RESOLUTION = True
THUMBNAIL_PROCESSORS = (
'easy_thumbnails.processors.colorspace',
'easy_thumbnails.processors.autocrop',
#'easy_thumbnails.processors.scale_and_crop',
'filer.thumbnail_processors.scale_and_crop_with_subject_location',
'easy_thumbnails.processors.filters',
)

## Otherwise, if you want, you can safely disable an image filed
# ZINNIA_IMAGE_FIELD = False
3 changes: 2 additions & 1 deletion zinnia/admin/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class EntryAdmin(admin.ModelAdmin):
'fields': (('title', 'status'), 'lead', 'content',)}),
(_('Illustration'), {
'fields': ('image', 'image_caption'),
'classes': ('collapse', 'collapse-closed')}),
'classes': ('collapse', 'collapse-closed')}) if settings.IMAGE_FIELD else (
None, {'fields': (), 'classes': ()}),
(_('Publication'), {
'fields': (('start_publication', 'end_publication'),
'creation_date', 'sites'),
Expand Down
4 changes: 3 additions & 1 deletion zinnia/admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from zinnia.admin.widgets import TagAutoComplete
from zinnia.admin.widgets import MPTTFilteredSelectMultiple
from zinnia.admin.fields import MPTTModelMultipleChoiceField
from zinnia import settings


class CategoryAdminForm(forms.ModelForm):
Expand Down Expand Up @@ -77,5 +78,6 @@ class Meta:
'tags': TagAutoComplete,
'lead': MiniTextarea,
'excerpt': MiniTextarea,
'image_caption': MiniTextarea,
}
if settings.IMAGE_FIELD:
widgets.update(image_caption=MiniTextarea)
4 changes: 2 additions & 2 deletions zinnia/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def item_enclosure_url(self, item):
"""
Return an image for enclosure.
"""
if item.image:
if hasattr(item, 'image') and item.image:
url = item.image.url
else:
img = BeautifulSoup(item.html_content).find('img')
Expand All @@ -140,7 +140,7 @@ def item_enclosure_length(self, item):
if the enclosure is present on the FS,
otherwise returns an hardcoded value.
"""
if item.image:
if hasattr(item, 'image') and item.image:
try:
return str(item.image.size)
except (os.error, NotImplementedError):
Expand Down
1 change: 0 additions & 1 deletion zinnia/markups.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def markdown(value, extensions=MARKDOWN_EXTENSIONS):
RuntimeWarning)
return value

extensions = [e for e in extensions.split(',') if e]
return markdown.markdown(force_text(value),
extensions, safe_mode=False)

Expand Down
Loading