diff --git a/bulbs/content/migrations/0013_auto_20160725_1304.py b/bulbs/content/migrations/0013_auto_20160725_1304.py new file mode 100644 index 00000000..c5452d88 --- /dev/null +++ b/bulbs/content/migrations/0013_auto_20160725_1304.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import djbetty.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('content', '0012_auto_20160615_1605'), + ] + + operations = [ + migrations.AddField( + model_name='content', + name='_facebook_description', + field=models.TextField(max_length=1024, null=True, db_column='facebook_description', blank=True), + ), + migrations.AddField( + model_name='content', + name='facebook_image', + field=djbetty.fields.ImageField(default=None, null=True, blank=True), + ), + ] diff --git a/bulbs/content/models.py b/bulbs/content/models.py index 10e3cda1..1659e1ca 100644 --- a/bulbs/content/models.py +++ b/bulbs/content/models.py @@ -221,6 +221,13 @@ class Content(PolymorphicModel, Indexable): template_choice = models.IntegerField(default=0, choices=TEMPLATE_CHOICES) # Facebook Instant Article ID instant_article_id = models.BigIntegerField(blank=True, null=True, default=None) + _facebook_description = models.TextField( + max_length=1024, + blank=True, + null=True, + db_column="facebook_description" + ) + facebook_image = ImageField(null=True, blank=True) # custom ES manager search_objects = ContentManager() @@ -238,6 +245,7 @@ class Mapping: slug = field.String(index="not_analyzed") status = field.String(index="not_analyzed") thumbnail_override = ElasticsearchImageField() + facebook_image = ElasticsearchImageField() def __unicode__(self): """unicode friendly name @@ -288,6 +296,16 @@ def first_image(self): # no non-none images, return None return None + @property + def facebook_description(self): + if self._facebook_description: + return self._facebook_description + return self.description + + @facebook_description.setter + def facebook_description(self, value): + self._facebook_description = value + def get_absolute_url(self): """produces a url to link directly to this instance, given the URL config diff --git a/bulbs/content/serializers.py b/bulbs/content/serializers.py index 5590ac9a..14670067 100644 --- a/bulbs/content/serializers.py +++ b/bulbs/content/serializers.py @@ -241,8 +241,15 @@ class ContentSerializer(serializers.ModelSerializer): thumbnail = ImageFieldSerializer(allow_null=True, read_only=True) first_image = ImageFieldSerializer(allow_null=True, read_only=True) thumbnail_override = ImageFieldSerializer(allow_null=True, required=False) + facebook_image = ImageFieldSerializer(allow_null=True, required=False) absolute_url = serializers.ReadOnlyField(source="get_absolute_url") status = serializers.ReadOnlyField(source="get_status") + facebook_description = serializers.CharField( + source="_facebook_description", + allow_null=True, + required=False + ) + template_type = serializers.SlugRelatedField( slug_field="slug", allow_null=True, diff --git a/bulbs/super_features/serializers.py b/bulbs/super_features/serializers.py index 01d0a768..d63bd4d7 100644 --- a/bulbs/super_features/serializers.py +++ b/bulbs/super_features/serializers.py @@ -41,6 +41,10 @@ class BaseSuperFeatureSerializer(ContentSerializer): class Meta: model = BaseSuperFeature + def to_representation(self, obj): + self.superfeature_type = getattr(obj, 'superfeature_type') + return super(BaseSuperFeatureSerializer, self).to_representation(obj) + class BaseSuperFeaturePartialSerializer(ContentSerializer): diff --git a/tests/api/test_content_api.py b/tests/api/test_content_api.py index 9d1ada68..708151ab 100644 --- a/tests/api/test_content_api.py +++ b/tests/api/test_content_api.py @@ -99,6 +99,8 @@ def test_create_article(self): "description": "Testing out things with an article.", "foo": "Fighters", "feature_type": "Some Super Long String Probably", + "facebook_description": "this is the facebook description", + "facebook_image": {"id": 1}, "authors": [{ "id": author.id, "username": author.username, diff --git a/tests/content/test_content_model.py b/tests/content/test_content_model.py index ceba5443..b86ad3fc 100644 --- a/tests/content/test_content_model.py +++ b/tests/content/test_content_model.py @@ -43,6 +43,21 @@ def test_get_targeting(self): targeting = obj.get_targeting() self.assertEqual(obj.published.isoformat(), targeting.get("dfp_publishdate")) + def test_facebook_description_fallback(self): + obj = TestContentObj.objects.create(**self.default_data) + obj.description = "This is a description" + obj.save() + TestContentObj.search_objects.refresh() + + self.assertEqual(obj.facebook_description, obj.description) + + obj.facebook_description = "This is the facebook description" + obj.save() + TestContentObj.search_objects.refresh() + + self.assertNotEqual(obj.facebook_description, obj.description) + self.assertEqual(obj.facebook_description, "This is the facebook description") + class SerializerTestCase(BaseIndexableTestCase): def test_content_status(self):