本文整理汇总了Python中mkt.feed.indexers.FeedItemIndexer类的典型用法代码示例。如果您正苦于以下问题:Python FeedItemIndexer类的具体用法?Python FeedItemIndexer怎么用?Python FeedItemIndexer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FeedItemIndexer类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get
def get(self, request, *args, **kwargs):
q = request.GET.get('q')
# Make search.
queries = [
query.Q('match', slug=self._phrase(q)), # Slug.
query.Q('match', type=self._phrase(q)), # Type.
query.Q('match', search_names=self._phrase(q)), # Name.
query.Q('prefix', carrier=q), # Shelf carrier.
query.Q('term', region=q) # Shelf region.
]
sq = query.Bool(should=queries)
# Search.
res = {'apps': [], 'brands': [], 'collections': [], 'shelves': []}
es = Search(using=FeedItemIndexer.get_es(),
index=self.get_feed_element_index())
feed_elements = es.query(sq).execute().hits
if not feed_elements:
return response.Response(res, status=status.HTTP_404_NOT_FOUND)
# Deserialize.
ctx = {'app_map': self.get_apps(request,
self.get_app_ids_all(feed_elements)),
'request': request}
for feed_element in feed_elements:
item_type = feed_element.item_type
serializer = self.SERIALIZERS[item_type]
data = serializer(feed_element, context=ctx).data
res[self.PLURAL_TYPES[item_type]].append(data)
# Return.
return response.Response(res, status=status.HTTP_200_OK)
开发者ID:atiqueahmedziad,项目名称:zamboni,代码行数:33,代码来源:views.py
示例2: get
def get(self, request, item_type, slug, **kwargs):
item_type = self.ITEM_TYPES[item_type]
# Hit ES.
sq = self.get_feed_element_filter(
Search(using=FeedItemIndexer.get_es(),
index=self.INDICES[item_type]),
item_type, slug)
try:
feed_element = sq.execute().hits[0]
except IndexError:
return response.Response(status=status.HTTP_404_NOT_FOUND)
# Deserialize.
data = self.SERIALIZERS[item_type](feed_element, context={
'app_map': self.mget_apps(self.get_app_ids(feed_element)),
'request': request
}).data
# Filter data. If None of the apps are compatible, only run the
# public apps filter.
data = (self.filter_apps_feed_element(request, dict(data)) or
self._filter(amo.STATUS_PUBLIC, 'status', feed_element))
return response.Response(data, status=status.HTTP_200_OK)
开发者ID:MorrisJobke,项目名称:zamboni,代码行数:25,代码来源:views.py
示例3: get
def get(self, request, item_type, slug, **kwargs):
item_type = self.ITEM_TYPES[item_type]
# Hit ES.
sq = self.get_feed_element_filter(
Search(using=FeedItemIndexer.get_es(),
index=self.INDICES[item_type]),
item_type, slug)
try:
feed_element = sq.execute().hits[0]
except IndexError:
return response.Response(status=status.HTTP_404_NOT_FOUND)
# Deserialize.
data = self.SERIALIZERS[item_type](feed_element, context={
'app_map': self.get_apps(request, self.get_app_ids(feed_element)),
'request': request
}).data
# Limit if necessary.
limit = request.GET.get('limit')
if limit and limit.isdigit() and 'apps' in data:
data['apps'] = data['apps'][:int(limit)]
return response.Response(data, status=status.HTTP_200_OK)
开发者ID:JaredKerim-Mozilla,项目名称:zamboni,代码行数:25,代码来源:views.py
示例4: _get
def _get(self, request, rest_of_world=False, original_region=None,
*args, **kwargs):
es = FeedItemIndexer.get_es()
# Parse region.
if rest_of_world:
region = mkt.regions.RESTOFWORLD.id
else:
region = request.REGION.id
# Parse carrier.
carrier = None
q = request.QUERY_PARAMS
if q.get('carrier') and q['carrier'] in mkt.carriers.CARRIER_MAP:
carrier = mkt.carriers.CARRIER_MAP[q['carrier']].id
# Fetch FeedItems.
sq = self.get_es_feed_query(FeedItemIndexer.search(using=es),
region=region, carrier=carrier,
original_region=original_region)
# The paginator triggers the ES request.
with statsd.timer('mkt.feed.view.feed_query'):
feed_items = self.paginate_queryset(sq)
feed_ok = self._check_empty_feed(feed_items, rest_of_world)
if feed_ok != 1:
return self._handle_empty_feed(feed_ok, region, request, args,
kwargs)
# Build the meta object.
meta = mkt.api.paginator.CustomPaginationSerializer(
feed_items, context={'request': request}).data['meta']
# Set up serializer context.
feed_element_map = {
feed.FEED_TYPE_APP: {},
feed.FEED_TYPE_BRAND: {},
feed.FEED_TYPE_COLL: {},
feed.FEED_TYPE_SHELF: {},
}
# Fetch feed elements to attach to FeedItems later.
apps = []
sq = self.get_es_feed_element_query(
Search(using=es, index=self.get_feed_element_index()), feed_items)
with statsd.timer('mkt.feed.view.feed_element_query'):
feed_elements = sq.execute().hits
for feed_elm in feed_elements:
# Store the feed elements to attach to FeedItems later.
feed_element_map[feed_elm['item_type']][feed_elm['id']] = feed_elm
# Store the apps to retrieve later.
apps += self.get_app_ids(feed_elm)
# Remove dupes from apps list.
apps = list(set(apps))
# Fetch apps to attach to feed elements later.
app_map = self.get_apps(request, apps)
# Super serialize.
with statsd.timer('mkt.feed.view.serialize'):
feed_items = FeedItemESSerializer(feed_items, many=True, context={
'app_map': app_map,
'feed_element_map': feed_element_map,
'request': request
}).data
# Filter excluded apps. If there are feed items that have all their
# apps excluded, they will be removed from the feed.
feed_items = self.filter_feed_items(request, feed_items)
feed_ok = self._check_empty_feed(feed_items, rest_of_world)
if feed_ok != 1:
if not rest_of_world:
log.warning('Feed empty for region {0}. Requerying feed with '
'region=RESTOFWORLD'.format(region))
return self._handle_empty_feed(feed_ok, region, request, args,
kwargs)
return response.Response({'meta': meta, 'objects': feed_items},
status=status.HTTP_200_OK)
开发者ID:atiqueahmedziad,项目名称:zamboni,代码行数:78,代码来源:views.py
示例5: _get
def _get(self, request, rest_of_world=False, original_region=None, *args, **kwargs):
es = FeedItemIndexer.get_es()
# Parse region.
if rest_of_world:
region = mkt.regions.RESTOFWORLD.id
else:
region = request.REGION.id
# Parse carrier.
carrier = None
q = request.query_params
if q.get("carrier") and q["carrier"] in mkt.carriers.CARRIER_MAP:
carrier = mkt.carriers.CARRIER_MAP[q["carrier"]].id
# Fetch FeedItems.
sq = self.get_es_feed_query(
FeedItemIndexer.search(using=es), region=region, carrier=carrier, original_region=original_region
)
# The paginator triggers the ES request.
with statsd.timer("mkt.feed.view.feed_query"):
feed_items = self.paginate_queryset(sq)
feed_ok = self._check_empty_feed(feed_items, rest_of_world)
if feed_ok != 1:
return self._handle_empty_feed(feed_ok, region, request, args, kwargs)
# Build the meta object.
meta = self.paginator.get_paginated_response(feed_items).data["meta"]
# Set up serializer context.
feed_element_map = {
feed.FEED_TYPE_APP: {},
feed.FEED_TYPE_BRAND: {},
feed.FEED_TYPE_COLL: {},
feed.FEED_TYPE_SHELF: {},
}
# Fetch feed elements to attach to FeedItems later.
apps = []
sq = self.get_es_feed_element_query(Search(using=es, index=self.get_feed_element_index()), feed_items)
with statsd.timer("mkt.feed.view.feed_element_query"):
feed_elements = sq.execute().hits
for feed_elm in feed_elements:
# Store the feed elements to attach to FeedItems later.
feed_element_map[feed_elm["item_type"]][feed_elm["id"]] = feed_elm
# Store the apps to retrieve later.
apps += self.get_app_ids(feed_elm)
# Remove dupes from apps list.
apps = list(set(apps))
# Fetch apps to attach to feed elements later.
app_map = self.get_apps(request, apps)
# Super serialize.
with statsd.timer("mkt.feed.view.serialize"):
feed_items = FeedItemESSerializer(
feed_items,
many=True,
context={"app_map": app_map, "feed_element_map": feed_element_map, "request": request},
).data
# Filter excluded apps. If there are feed items that have all their
# apps excluded, they will be removed from the feed.
feed_items = self.filter_feed_items(request, feed_items)
feed_ok = self._check_empty_feed(feed_items, rest_of_world)
if feed_ok != 1:
if not rest_of_world:
log.warning("Feed empty for region {0}. Requerying feed with " "region=RESTOFWORLD".format(region))
return self._handle_empty_feed(feed_ok, region, request, args, kwargs)
with statsd.timer("mkt.feed.view.feed_website_query"):
websites = self.get_featured_websites()
return response.Response({"meta": meta, "objects": feed_items, "websites": websites}, status=status.HTTP_200_OK)
开发者ID:waseem18,项目名称:zamboni,代码行数:74,代码来源:views.py
示例6: _get
def _get(self, request, *args, **kwargs):
es = FeedItemIndexer.get_es()
# Parse carrier and region.
q = request.QUERY_PARAMS
region = request.REGION.id
carrier = None
if q.get('carrier') and q['carrier'] in mkt.carriers.CARRIER_MAP:
carrier = mkt.carriers.CARRIER_MAP[q['carrier']].id
# Fetch FeedItems.
sq = self.get_es_feed_query(FeedItemIndexer.search(using=es),
region=region, carrier=carrier)
feed_items = self.paginate_queryset(sq)
# No items returned; try to fall back to RoW.
if not feed_items:
world_sq = self.get_es_feed_query(FeedItemIndexer.search(using=es))
world_feed_items = self.paginate_queryset(world_sq)
# No RoW feed items, either. Let's 404.
if not world_feed_items:
world_meta = mkt.api.paginator.CustomPaginationSerializer(
world_feed_items,
context={'request': request}).data['meta']
return response.Response({'meta': world_meta, 'objects': []},
status=status.HTTP_404_NOT_FOUND)
# Return RoW items.
else:
feed_items = world_feed_items
# Build the meta object.
meta = mkt.api.paginator.CustomPaginationSerializer(
feed_items, context={'request': request}).data['meta']
# Set up serializer context.
feed_element_map = {
feed.FEED_TYPE_APP: {},
feed.FEED_TYPE_BRAND: {},
feed.FEED_TYPE_COLL: {},
feed.FEED_TYPE_SHELF: {},
}
# Fetch feed elements to attach to FeedItems later.
apps = []
sq = self.get_es_feed_element_query(
Search(using=es, index=self.get_feed_element_index()), feed_items)
for feed_elm in sq.execute().hits:
# Store the feed elements to attach to FeedItems later.
feed_element_map[feed_elm['item_type']][feed_elm['id']] = feed_elm
# Store the apps to retrieve later.
apps += self.get_app_ids(feed_elm)
# Fetch apps to attach to feed elements later (with mget).
app_map = self.mget_apps(apps)
# Super serialize.
feed_items = FeedItemESSerializer(feed_items, many=True, context={
'app_map': app_map,
'feed_element_map': feed_element_map,
'request': request
}).data
# Filter excluded apps. If there are feed items that have all their
# apps excluded, they will be removed from the feed.
feed_items = self.filter_apps_feed_items(request, feed_items)
# Slice AFTER filtering so that filtering works correctly.
self.limit_apps_feed_items(feed_items)
# TODO (chuck): paginate after filtering/slicing.
return response.Response({'meta': meta, 'objects': feed_items},
status=status.HTTP_200_OK)
开发者ID:MorrisJobke,项目名称:zamboni,代码行数:75,代码来源:views.py
注:本文中的mkt.feed.indexers.FeedItemIndexer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论