Пример #1
0
    def fake_object(self, data):
        """Create a fake instance of Extension from ES data."""
        obj = Extension(id=data['id'])
        data['created'] = es_to_datetime(data['created'])
        data['last_updated'] = es_to_datetime(data['last_updated'])
        data['modified'] = es_to_datetime(data['modified'])

        # Create a fake ExtensionVersion for latest_public_version.
        if data['latest_public_version']:
            obj.latest_public_version = ExtensionVersion(
                extension=obj,
                id=data['latest_public_version']['id'],
                created=es_to_datetime(
                    data['latest_public_version']['created']),
                size=data['latest_public_version'].get('size', 0),
                status=STATUS_PUBLIC,
                version=data['latest_public_version']['version'],
            )

        # Set basic attributes we'll need on the fake instance using the data
        # from ES.
        self._attach_fields(
            obj, data,
            ('author', 'created', 'default_language', 'icon_hash',
             'last_updated', 'modified', 'slug', 'status', 'version'))

        obj.deleted = data['is_deleted']
        obj.disabled = data['is_disabled']
        obj.uuid = data['guid']

        # Attach translations for all translated attributes.
        # obj.default_language should be set first for this to work.
        self._attach_translations(obj, data, (
            'name',
            'description',
        ))

        # Some methods might need the raw data from ES, put it on obj.
        obj.es_data = data

        return obj