Commit 1ca74883 authored by haowang's avatar haowang

fix code

parent 36080ab6
......@@ -21,19 +21,29 @@ class BrandListView(APIView):
product_count = self.rpc['neptune/commodity/brand/product_count'](ids=brand_ids).unwrap()
category_ids = self.rpc['neptune/commodity/brand/brands_category_ids'](ids=brand_ids).unwrap()
category_infos = self.rpc['neptune/commodity/category/infos'](brand_ids=brand_ids).unwrap()
category_dict = {}
for obj in category_infos:
obj_id = obj.get('brand_id')
if category_dict.get(str(obj_id)):
category_dict.get(str(obj_id)).append(obj)
else:
category_dict[str(obj_id)] = [obj]
classify_infos = self.rpc['neptune/commodity/classify/infos'](brand_ids=brand_ids).unwrap()
classify_dict = {str(obj.get('brand_id')): obj for obj in classify_infos}
category_infos = self.rpc['neptune/commodity/category/infos'](ids=category_ids).unwrap()
category_dict = {str(obj.get('id')): obj for obj in category_infos} if category_infos else {}
for obj in data:
brand_id = obj.get('id')
obj['product_num'] = product_count.get(str(brand_id)) or 0
obj['category_infos'] = [{'id': id_, 'cn_name': category_dict.get(str(id_)).get('cn_name')}
for id_ in category_ids.get(str(brand_id))] if category_dict.get(str(id_)) else []
category_info_list = category_dict.get(str(brand_id))
obj['category_infos'] = [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')} for obj in category_info_list] if category_info_list else []
obj['grade'] = 0
obj['classify_info'] = []
classify_info = classify_dict.get(str(brand_id))
obj['classify_info'] = [{'id': classify_info.get('id'), 'cn_name': classify_info.get('cn_name')}] if classify_info else []
obj.pop('platform')
......@@ -54,7 +64,7 @@ class BrandInfoView(APIView):
id_ = request.GET.get('id')
data = self.rpc['neptune/commodity/brand/info'](id_=id_).unwrap()
classify_infos = self.rpc['neptune/commodity/classify/infos'](brand_id=id_).unwrap()
classify_infos = self.rpc['neptune/commodity/classify/infos'](brand_ids=[id_]).unwrap()
data['classify_infos'] = [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')} for obj in classify_infos] if classify_infos else []
category_ids = self.rpc['neptune/commodity/brand/category_ids'](id_=id_).unwrap()
category_infos = self.rpc['neptune/commodity/category/infos'](ids=category_ids).unwrap()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment