Beispiel #1
0
    def extract_document(cls, pk=None, obj=None):
        from mkt.feed.models import FeedShelfMembership

        if obj is None:
            obj = cls.get_model().get(pk=pk)

        attach_trans_dict(cls.get_model(), [obj])

        doc = {
            'id':
            obj.id,
            'apps':
            list(obj.apps().values_list('id', flat=True)),
            'carrier':
            mkt.carriers.CARRIER_CHOICE_DICT[obj.carrier].slug,
            'created':
            obj.created,
            'group_apps': {},  # Map of app IDs to index in group_names below.
            'group_names': [],  # List of ES-serialized group names.
            'image_hash':
            obj.image_hash,
            'image_landing_hash':
            obj.image_landing_hash,
            'item_type':
            feed.FEED_TYPE_SHELF,
            'region':
            mkt.regions.REGIONS_CHOICES_ID_DICT[obj.region].slug,
            'search_names':
            list(set(string for _, string in obj.translations[obj.name_id])),
            'slug':
            obj.slug,
        }

        # Grouped apps. Key off of translation, pointed to app IDs.
        memberships = obj.feedshelfmembership_set.all()
        attach_trans_dict(FeedShelfMembership, memberships)
        for member in memberships:
            if member.group:
                grp_translation = format_translation_es(member, 'group')
                if grp_translation not in doc['group_names']:
                    doc['group_names'].append(grp_translation)

                doc['group_apps'][member.app_id] = (
                    doc['group_names'].index(grp_translation))

        # Handle localized fields.
        for field in ('description', 'name'):
            doc.update(format_translation_es(obj, field))

        return doc
Beispiel #2
0
    def extract_document(cls, pk=None, obj=None):
        """Converts this instance into an Elasticsearch document"""
        if obj is None:
            obj = cls.get_model().objects.get(pk=pk)

        # Attach translations for searching and indexing.
        attach_trans_dict(cls.get_model(), [obj])
        attach_trans_dict(Webapp, [obj.app])

        doc = {
            'id': obj.id,
            'app': obj.app_id,
            'background_color': obj.background_color,
            'created': obj.created,
            'image_hash': obj.image_hash,
            'item_type': feed.FEED_TYPE_APP,
            'preview': {'id': obj.preview.id,
                        'thumbnail_size': obj.preview.thumbnail_size,
                        'thumbnail_url': obj.preview.thumbnail_url}
                       if getattr(obj, 'preview') else None,
            'pullquote_attribution': obj.pullquote_attribution,
            'pullquote_rating': obj.pullquote_rating,
            'search_names': list(
                set(string for _, string
                    in obj.app.translations[obj.app.name_id])),
            'slug': obj.slug,
            'type': obj.type,
        }

        # Handle localized fields.
        for field in ('description', 'pullquote_text'):
            doc.update(format_translation_es(obj, field))

        return doc
Beispiel #3
0
    def extract_document(cls, pk=None, obj=None):
        if obj is None:
            obj = cls.get_model().get(pk=pk)

        attach_trans_dict(cls.get_model(), [obj])

        doc = {
            'id': obj.id,
            'apps': list(obj.apps().values_list('id', flat=True)),
            'carrier': mkt.carriers.CARRIER_CHOICE_DICT[obj.carrier].slug,
            'created': obj.created,
            'image_hash': obj.image_hash,
            'image_landing_hash': obj.image_landing_hash,
            'item_type': feed.FEED_TYPE_SHELF,
            'region': mkt.regions.REGIONS_CHOICES_ID_DICT[obj.region].slug,
            'search_names': list(set(string for _, string
                                     in obj.translations[obj.name_id])),
            'slug': obj.slug,
        }

        # Handle localized fields.
        for field in ('description', 'name'):
            doc.update(format_translation_es(obj, field))

        return doc
Beispiel #4
0
    def extract_document(cls, pk=None, obj=None):
        """Converts this instance into an Elasticsearch document"""
        if obj is None:
            obj = cls.get_model().objects.get(pk=pk)

        # Attach translations for searching and indexing.
        attach_trans_dict(cls.get_model(), [obj])
        attach_trans_dict(Webapp, [obj.app])

        doc = {
            'id': obj.id,
            'app': obj.app_id,
            'background_color': obj.background_color,
            'created': obj.created,
            'image_hash': obj.image_hash,
            'item_type': feed.FEED_TYPE_APP,
            'preview': {'id': obj.preview.id,
                        'thumbnail_size': obj.preview.thumbnail_size,
                        'thumbnail_url': obj.preview.thumbnail_url}
                       if getattr(obj, 'preview') else None,
            'pullquote_attribution': obj.pullquote_attribution,
            'pullquote_rating': obj.pullquote_rating,
            'search_names': list(
                set(string for _, string
                    in obj.app.translations[obj.app.name_id])),
            'slug': obj.slug,
            'type': obj.type,
        }

        # Handle localized fields.
        for field in ('description', 'pullquote_text'):
            doc.update(format_translation_es(obj, field))

        return doc
Beispiel #5
0
    def extract_document(cls, pk=None, obj=None):
        if obj is None:
            obj = cls.get_model().get(pk=pk)

        attach_trans_dict(cls.get_model(), [obj])

        doc = {
            'id': obj.id,
            'apps': list(obj.apps().values_list('id', flat=True)),
            'carrier': mkt.carriers.CARRIER_CHOICE_DICT[obj.carrier].slug,
            'created': obj.created,
            'image_hash': obj.image_hash,
            'image_landing_hash': obj.image_landing_hash,
            'item_type': feed.FEED_TYPE_SHELF,
            'region': mkt.regions.REGIONS_CHOICES_ID_DICT[obj.region].slug,
            'search_names': list(set(string for _, string
                                     in obj.translations[obj.name_id])),
            'slug': obj.slug,
        }

        # Handle localized fields.
        for field in ('description', 'name'):
            doc.update(format_translation_es(obj, field))

        return doc
Beispiel #6
0
    def extract_document(cls, pk=None, obj=None):
        from mkt.feed.models import FeedShelfMembership

        if obj is None:
            obj = cls.get_model().get(pk=pk)

        attach_trans_dict(cls.get_model(), [obj])

        doc = {
            'id': obj.id,
            'apps': list(obj.apps().values_list('id', flat=True)),
            'carrier': mkt.carriers.CARRIER_CHOICE_DICT[obj.carrier].slug,
            'created': obj.created,
            'group_apps': {},  # Map of app IDs to index in group_names below.
            'group_names': [],  # List of ES-serialized group names.
            'image_hash': obj.image_hash,
            'image_landing_hash': obj.image_landing_hash,
            'item_type': feed.FEED_TYPE_SHELF,
            'region': mkt.regions.REGIONS_CHOICES_ID_DICT[obj.region].slug,
            'search_names': list(set(string for _, string
                                     in obj.translations[obj.name_id])),
            'slug': obj.slug,
        }


        # Grouped apps. Key off of translation, pointed to app IDs.
        memberships = obj.feedshelfmembership_set.all()
        attach_trans_dict(FeedShelfMembership, memberships)
        for member in memberships:
            if member.group:
                grp_translation = format_translation_es(member, 'group')
                if grp_translation not in doc['group_names']:
                    doc['group_names'].append(grp_translation)

                doc['group_apps'][member.app_id] = (
                    doc['group_names'].index(grp_translation))

        # Handle localized fields.
        for field in ('description', 'name'):
            doc.update(format_translation_es(obj, field))

        return doc