本文整理汇总了Python中mkt.webapps.models.Webapp.get_icon_url方法的典型用法代码示例。如果您正苦于以下问题:Python Webapp.get_icon_url方法的具体用法?Python Webapp.get_icon_url怎么用?Python Webapp.get_icon_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mkt.webapps.models.Webapp
的用法示例。
在下文中一共展示了Webapp.get_icon_url方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RocketbarESAppSerializer
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import get_icon_url [as 别名]
class RocketbarESAppSerializer(serializers.Serializer):
"""Used by Firefox OS's Rocketbar apps viewer."""
name = ESTranslationSerializerField()
@property
def data(self):
if self._data is None:
self._data = [self.to_native(o['payload']) for o in self.object]
return self._data
def to_native(self, obj):
# fake_app is a fake instance because we need to access a couple
# properties and methods on Webapp. It should never hit the database.
self.fake_app = Webapp(
id=obj['id'], icon_type='image/png',
default_locale=obj.get('default_locale', settings.LANGUAGE_CODE),
icon_hash=obj.get('icon_hash'),
modified=es_to_datetime(obj['modified']))
ESTranslationSerializerField.attach_translations(
self.fake_app, obj, 'name')
return {
'name': self.fields['name'].field_to_native(self.fake_app, 'name'),
'icon': self.fake_app.get_icon_url(64),
'slug': obj['slug'],
'manifest_url': obj['manifest_url'],
}
示例2: RocketbarESAppSerializer
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import get_icon_url [as 别名]
class RocketbarESAppSerializer(serializers.Serializer):
"""Used by Firefox OS's Rocketbar apps viewer."""
name = ESTranslationSerializerField()
@property
def data(self):
if self._data is None:
self._data = [self.to_native(o["payload"]) for o in self.object]
return self._data
def to_native(self, obj):
# fake_app is a fake instance because we need to access a couple
# properties and methods on Webapp. It should never hit the database.
self.fake_app = Webapp(
id=obj["id"],
icon_type="image/png",
type=amo.ADDON_WEBAPP,
default_locale=obj.get("default_locale", settings.LANGUAGE_CODE),
icon_hash=obj.get("icon_hash"),
modified=es_to_datetime(obj["modified"]),
)
ESTranslationSerializerField.attach_translations(self.fake_app, obj, "name")
return {
"name": self.fields["name"].field_to_native(self.fake_app, "name"),
"icon": self.fake_app.get_icon_url(64),
"slug": obj["slug"],
"manifest_url": obj["manifest_url"],
}
示例3: to_native
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import get_icon_url [as 别名]
def to_native(self, obj):
# fake_app is a fake instance because we need to access a couple
# properties and methods on Webapp. It should never hit the database.
fake_app = Webapp(id=obj['id'], icon_type='image/png',
modified=datetime.strptime(obj['modified'], '%Y-%m-%dT%H:%M:%S'))
ESTranslationSerializerField.attach_translations(fake_app, obj, 'name')
return {
'name': self.fields['name'].field_to_native(fake_app, 'name'),
'icon' : fake_app.get_icon_url(64),
'slug': obj['slug'],
'manifest_url': obj['manifest_url'],
}
示例4: to_native
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import get_icon_url [as 别名]
def to_native(self, obj):
# fake_app is a fake instance because we need to access a couple
# properties and methods on Webapp. It should never hit the database.
fake_app = Webapp(
id=obj["id"],
icon_type="image/png",
type=amo.ADDON_WEBAPP,
default_locale=obj.get("default_locale", settings.LANGUAGE_CODE),
icon_hash=obj.get("icon_hash"),
modified=datetime.strptime(obj["modified"], "%Y-%m-%dT%H:%M:%S"),
)
ESTranslationSerializerField.attach_translations(fake_app, obj, "name")
return {
"name": self.fields["name"].field_to_native(fake_app, "name"),
"icon": fake_app.get_icon_url(64),
"slug": obj["slug"],
"manifest_url": obj["manifest_url"],
}
示例5: es_app_to_dict
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import get_icon_url [as 别名]
def es_app_to_dict(obj, profile=None, request=None):
"""
Return app data as dict for API where `app` is the elasticsearch result.
"""
# Circular import.
from mkt.developers.models import AddonPaymentAccount
from mkt.webapps.models import Installed, Webapp
translation_fields = ('banner_message', 'description', 'homepage', 'name',
'release_notes', 'support_email', 'support_url')
lang = None
if request and request.method == 'GET' and 'lang' in request.GET:
lang = request.GET.get('lang', '').lower()
region_slug = None
region_id = None
if request and request.method == 'GET' and 'region' in request.GET:
region_slug = request.GET.get('region', '').lower()
if region_slug not in REGIONS_DICT:
region_slug = get_region()
region_id = REGIONS_DICT[region_slug].id
src = obj._source
is_packaged = src.get('app_type') != amo.ADDON_WEBAPP_HOSTED
# The following doesn't perform a database query, but gives us useful
# methods like `get_detail_url` and `get_icon_url`. If you use `app` make
# sure the calls don't query the database.
app = Webapp(id=obj._id, app_slug=obj.app_slug, is_packaged=is_packaged,
type=amo.ADDON_WEBAPP, icon_type='image/png',
modified=getattr(obj, 'modified', None))
attrs = ('created', 'current_version', 'default_locale', 'is_offline',
'manifest_url', 'reviewed', 'ratings', 'status',
'weekly_downloads')
data = dict((a, getattr(obj, a, None)) for a in attrs)
# Flatten the localized fields from {'lang': ..., 'string': ...}
# to {lang: string}.
for field in translation_fields:
src_field = '%s_translations' % field
value_field = src.get(src_field)
src[src_field] = dict((v.get('lang', ''), v.get('string', ''))
for v in value_field) if value_field else {}
data[field] = get_translations(src, src_field, obj.default_locale,
lang)
# Generate urls for previews and icons before the data.update() call below
# adds them to the result.
previews = getattr(obj, 'previews', [])
for preview in previews:
if 'image_url' and 'thumbnail_url' in preview:
# Old-style index, the full URL is already present, nothing to do.
# TODO: remove this check once we have re-indexed everything.
continue
else:
# New-style index, we need to build the URLs from the data we have.
p = Preview(id=preview.pop('id'), modified=preview.pop('modified'),
filetype=preview['filetype'])
preview['image_url'] = p.image_url
preview['thumbnail_url'] = p.thumbnail_url
icons = getattr(obj, 'icons', [])
for icon in icons:
if 'url' in icon:
# Old-style index, the full URL is already present, nothing to do.
# TODO: remove this check once we have re-indexed everything.
continue
else:
# New-style index, we need to build the URLs from the data we have.
icon['url'] = app.get_icon_url(icon['size'])
data.update({
'absolute_url': absolutify(app.get_detail_url()),
'app_type': 'packaged' if is_packaged else 'hosted',
'author': src.get('author', ''),
'banner_regions': src.get('banner_regions', []),
'categories': [c for c in obj.category],
'content_ratings': filter_content_ratings_by_region({
'ratings': dehydrate_content_ratings(
getattr(obj, 'content_ratings', {})),
'descriptors': dehydrate_descriptors(
getattr(obj, 'content_descriptors', {})),
'interactive_elements': dehydrate_interactives(
getattr(obj, 'interactive_elements', [])),
'regions': mkt.regions.REGION_TO_RATINGS_BODY()
}, region=region_slug),
'device_types': [DEVICE_TYPES[d].api_name for d in src.get('device')],
'icons': dict((i['size'], i['url']) for i in src.get('icons')),
'id': long(obj._id),
'is_packaged': is_packaged,
'payment_required': False,
'premium_type': amo.ADDON_PREMIUM_API[src.get('premium_type')],
'previews': previews,
'privacy_policy': reverse('app-privacy-policy-detail',
kwargs={'pk': obj._id}),
'public_stats': obj.has_public_stats,
'supported_locales': src.get('supported_locales', ''),
'slug': obj.app_slug,
'versions': dict((v.get('version'), v.get('resource_uri')) for v in
src.get('versions')),
})
#.........这里部分代码省略.........