Commit 99ecf7f9 authored by 王浩's avatar 王浩

Merge branch 'haow/dev' into 'dev'

Haow/dev

See merge request !259
parents 62537f65 6522610b
......@@ -19,21 +19,34 @@ class BrandListView(APIView):
is_online=is_online, has_icon=has_icon, classify_id=classify_id).unwrap()
brand_ids = [obj.get('id') for obj in data]
brands_grade = self.rpc['neptune/commodity/brand/grade'](ids=brand_ids).unwrap()
grade_dict = {str(obj.get('brand_id')): obj.get('grade') for obj in brands_grade}
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'](ids=category_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_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 []
obj['grade'] = 0
obj['classify_info'] = []
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'] = grade_dict.get(str(brand_id)) if grade_dict.get(str(brand_id)) else 0
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 +67,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