Example #1
0
    def get_content_ratings(self, obj):
        body = (mkt.regions.REGION_TO_RATINGS_BODY().get(
            self.context['request'].REGION.slug, 'generic'))
        prefix = 'has_%s' % body

        # Backwards incompat with old index.
        for i, desc in enumerate(obj.es_data.get('content_descriptors', [])):
            if desc.isupper():
                obj.es_data['content_descriptors'][i] = 'has_' + desc.lower()
        for i, inter in enumerate(obj.es_data.get('interactive_elements', [])):
            if inter.isupper():
                obj.es_data['interactive_elements'][i] = 'has_' + inter.lower()

        return {
            'body':
            body,
            'rating':
            dehydrate_content_rating(
                (obj.es_data.get('content_ratings') or {}).get(body)) or None,
            'descriptors': [
                key for key in obj.es_data.get('content_descriptors', [])
                if prefix in key
            ],
            'descriptors_text': [
                mkt.iarc_mappings.REVERSE_DESCS[key]
                for key in obj.es_data.get('content_descriptors')
                if prefix in key
            ],
            'interactives':
            obj.es_data.get('interactive_elements', []),
            'interactives_text': [
                mkt.iarc_mappings.REVERSE_INTERACTIVES[key]
                for key in obj.es_data.get('interactive_elements')
            ]
        }
Example #2
0
    def get_content_ratings(self, obj):
        body = (mkt.regions.REGION_TO_RATINGS_BODY().get(
            self.context['request'].REGION.slug, 'generic'))
        prefix = 'has_%s' % body

        # Backwards incompat with old index.
        for i, desc in enumerate(obj.es_data.get('content_descriptors', [])):
            if desc.isupper():
                obj.es_data['content_descriptors'][i] = 'has_' + desc.lower()
        for i, inter in enumerate(obj.es_data.get('interactive_elements', [])):
            if inter.isupper():
                obj.es_data['interactive_elements'][i] = 'has_' + inter.lower()

        return {
            'body': body,
            'rating': dehydrate_content_rating(
                (obj.es_data.get('content_ratings') or {})
                .get(body)) or None,
            'descriptors': [key for key in
                            obj.es_data.get('content_descriptors', [])
                            if prefix in key],
            'descriptors_text': [mkt.iarc_mappings.REVERSE_DESCS[key] for key
                                 in obj.es_data.get('content_descriptors')
                                 if prefix in key],
            'interactives': obj.es_data.get('interactive_elements', []),
            'interactives_text': [mkt.iarc_mappings.REVERSE_INTERACTIVES[key]
                                  for key in
                                  obj.es_data.get('interactive_elements')]
        }
Example #3
0
 def get_content_ratings(self, obj):
     body = mkt.regions.REGION_TO_RATINGS_BODY().get(self.context["request"].REGION.slug, "generic")
     return {
         "body": body,
         "rating": dehydrate_content_rating((obj.es_data.get("content_ratings") or {}).get(body)) or None,
         "descriptors": dehydrate_descriptors(obj.es_data.get("content_descriptors", {})).get(body, []),
         "interactives": dehydrate_interactives(obj.es_data.get("interactive_elements", [])),
     }
Example #4
0
 def test_dehydrate_content_rating_old_es(self):
     """Test dehydrate works with old ES mapping."""
     rating = dehydrate_content_rating(
         [json.dumps({'body': u'CLASSIND',
                      'slug': u'0',
                      'description': u'General Audiences',
                      'name': u'0+',
                      'body_slug': u'classind'})])
     eq_(rating, {})
Example #5
0
 def test_dehydrate_content_rating_old_es(self):
     """Test dehydrate works with old ES mapping."""
     rating = dehydrate_content_rating(
         [json.dumps({'body': u'CLASSIND',
                      'slug': u'0',
                      'description': u'General Audiences',
                      'name': u'0+',
                      'body_slug': u'classind'})])
     eq_(rating, {})
Example #6
0
 def get_content_ratings(self, obj):
     body = (mkt.regions.REGION_TO_RATINGS_BODY().get(
         self.context['request'].REGION.slug, 'generic'))
     return {
         'body': body,
         'rating': dehydrate_content_rating(
             (obj.es_data.get('content_ratings') or {})
             .get(body)) or None,
         'descriptors': dehydrate_descriptors(
             obj.es_data.get('content_descriptors', {})
         ).get(body, []),
         'interactives': dehydrate_interactives(
             obj.es_data.get('interactive_elements', [])),
     }
Example #7
0
 def get_content_ratings(self, obj):
     body = (mkt.regions.REGION_TO_RATINGS_BODY().get(
         self.context['request'].REGION.slug, 'generic'))
     return {
         'body': body,
         'rating': dehydrate_content_rating(
             (obj.es_data.get('content_ratings') or {})
             .get(body)) or None,
         'descriptors': dehydrate_descriptors(
             obj.es_data.get('content_descriptors', {})
         ).get(body, []),
         'interactives': dehydrate_interactives(
             obj.es_data.get('interactive_elements', [])),
     }
Example #8
0
    def test_dehydrate_content_rating_old_es(self):
        """Test dehydrate works with old ES mapping."""
        self.create_switch("iarc")

        rating = dehydrate_content_rating(
            [
                json.dumps(
                    {
                        "body": u"CLASSIND",
                        "slug": u"0",
                        "description": u"General Audiences",
                        "name": u"0+",
                        "body_slug": u"classind",
                    }
                )
            ]
        )
        eq_(rating, {})
Example #9
0
    def get_content_ratings(self, obj):
        body = mkt.regions.REGION_TO_RATINGS_BODY().get(self.context["request"].REGION.slug, "generic")
        prefix = "has_%s" % body

        # Backwards incompat with old index.
        for i, desc in enumerate(obj.es_data.get("content_descriptors", [])):
            if desc.isupper():
                obj.es_data["content_descriptors"][i] = "has_" + desc.lower()
        for i, inter in enumerate(obj.es_data.get("interactive_elements", [])):
            if inter.isupper():
                obj.es_data["interactive_elements"][i] = "has_" + inter.lower()

        return {
            "body": body,
            "rating": dehydrate_content_rating((obj.es_data.get("content_ratings") or {}).get(body)) or None,
            "descriptors": [key for key in obj.es_data.get("content_descriptors", []) if prefix in key],
            "descriptors_text": [
                mkt.iarc_mappings.REVERSE_DESCS[key] for key in obj.es_data.get("content_descriptors") if prefix in key
            ],
            "interactives": obj.es_data.get("interactive_elements", []),
            "interactives_text": [
                mkt.iarc_mappings.REVERSE_INTERACTIVES[key] for key in obj.es_data.get("interactive_elements")
            ],
        }