Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Repurposed sfmoma oembed workaround for fluent bug into icekit for AC…
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Minton committed Dec 6, 2016
1 parent 5d010a9 commit 64bf75e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 24 additions & 1 deletion icekit/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
from django.conf import settings
from django.core.management.color import no_style
from django.db import connection
from django.db.models.signals import post_migrate
from django.db.models.signals import post_migrate, pre_save
from django.utils.module_loading import autodiscover_modules
from fluent_contents.plugins.oembeditem.models import OEmbedItem


def update_site(sender, **kwargs):
Expand Down Expand Up @@ -58,3 +59,25 @@ def ready(self):

# Import plugins from installed apps.
autodiscover_modules('plugins')


def handle_soundcloud_malformed_widths_for_oembeds(sender, instance, **kwargs):
"""
A signal receiver that prevents soundcloud from triggering ValueErrors
when we save an OEmbedItem.
Soundcloud returns "100%", instead of an integer for an OEmbed's width property.
This is against the OEmbed spec, but actually makes sense in the context of
responsive design. Unfortunately, the OEmbedItems can only store integers in
the `width` field, so this becomes a 500 throwing issue.
The issue is tracked https://github.com/edoburu/django-fluent-contents/issues/65
"""
if instance.width == '100%':
instance.width = -100


class OEmbedAppConfig(AppConfig):
name = 'fluent_contents.plugins.oembeditem'

def ready(self):
from fluent_contents.plugins.oembeditem.models import OEmbedItem
pre_save.connect(handle_soundcloud_malformed_widths_for_oembeds, sender=OEmbedItem)
2 changes: 1 addition & 1 deletion icekit/project/settings/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@
'icekit.plugins.links',
'icekit.plugins.map',
'icekit.plugins.map_with_text',
'icekit.plugins.oembed_with_caption',
'icekit.apps.OEmbedAppConfig',
'icekit.plugins.page_anchor',
'icekit.plugins.page_anchor_list',
'icekit.plugins.quote',
Expand Down

0 comments on commit 64bf75e

Please sign in to comment.