Commit 8aa1f996 authored by haowang's avatar haowang

fix code

parent 34c2c5f9
......@@ -30,7 +30,7 @@ class BrandListView(APIView):
for obj in data:
brand_id = obj.get('id')
obj['product_num'] = product_count.get(str(brand_id)) or 0
obj['category_names'] = [{'id': id_, 'cn_name': category_dict.get(str(id_)).get('cn_name')}
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.pop('platform')
......@@ -53,7 +53,10 @@ class BrandInfoView(APIView):
data = self.rpc['neptune/commodity/brand/info'](id_=id_).unwrap()
classify_infos = self.rpc['neptune/commodity/classify/infos'](brand_id=id_).unwrap()
data['classify_names'] = [obj.get('cn_name') for obj in classify_infos]
data['classify_infos'] = [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')} for obj in classify_infos]
category_ids = self.rpc['neptune/commodity/brand/category_ids'](id_=id_).unwrap()
category_infos = self.rpc['neptune/commodity/category/infos'](ids=category_ids).unwrap()
data['category_infos'] = [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')} for obj in category_infos]
return data
......
......@@ -17,7 +17,7 @@ class ProductListView(APIView):
if not category_infos:
return ret
for obj in category_infos:
product_id = obj.get('project_id')
product_id = obj.get('product_id')
if ret.get(str(product_id)):
ret[str(product_id)] = ret.get(str(product_id)).append(obj)
else:
......@@ -30,7 +30,7 @@ class ProductListView(APIView):
if not effect_infos:
return ret
for obj in effect_infos:
product_id = obj.get('project_id')
product_id = obj.get('product_id')
if ret.get(str(product_id)):
ret[str(product_id)] = ret.get(str(product_id)).append(obj)
else:
......@@ -43,7 +43,7 @@ class ProductListView(APIView):
if not classify_infos:
return ret
for obj in classify_infos:
product_id = obj.get('project_id')
product_id = obj.get('product_id')
if ret.get(str(product_id)):
ret[str(product_id)] = ret.get(str(product_id)).append(obj)
else:
......@@ -79,15 +79,18 @@ class ProductListView(APIView):
category_product_dict = self.get_category_infos(product_ids)
effect_product_dict = self.get_effect_infos(product_ids)
classify_product_dict = self.get_classify_infos(product_ids)
print(category_product_dict, effect_product_dict, classify_product_dict)
for obj in data:
product_id = obj.get('id')
obj['brand_name'] = brand_product_dict.get(str(product_id)).get('cn_name') if brand_product_dict.get(str(product_id)) else ''
obj['category_names'] = [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')}
obj['brand_info'] = {
'id': brand_product_dict.get(str(product_id)).get('id'),
'cn_name': brand_product_dict.get(str(product_id)).get('cn_name')} if brand_product_dict.get(str(product_id)) else ''
obj['category_infos'] = [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')}
for obj in category_product_dict.get(str(product_id))] if category_product_dict.get(str(product_id)) else []
obj['effect_names'] = [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')}
obj['effect_infos'] = [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')}
for obj in effect_product_dict.get(str(product_id))] if effect_product_dict.get(str(product_id)) else []
obj['classify_names'] = [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')}
obj['classify_infos'] = [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')}
for obj in classify_product_dict.get(str(product_id))] if classify_product_dict.get(str(product_id)) else []
obj.pop('norms')
......@@ -107,13 +110,13 @@ class ProductListView(APIView):
class ProductInfoView(APIView):
def get_category_names(self, product_id):
def get_category_infos(self, product_id):
category_infos = self.rpc['neptune/commodity/category/infos'](product_id=product_id).unwrap()
if not category_infos:
return []
return [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')} for obj in category_infos]
def get_effect_names(self, product_id):
def get_effect_infos(self, product_id):
effect_infos = self.rpc['neptune/commodity/effect/infos'](product_id=product_id).unwrap()
if not effect_infos:
return []
......@@ -128,11 +131,11 @@ class ProductInfoView(APIView):
data.pop('platform')
brand_info = self.rpc['neptune/commodity/brand/infos'](product_id=id_).unwrap()
data['brand_name'] = brand_info[0].get('cn_name') if brand_info else ''
data['brand_info'] = {'id': brand_info[0].get('id'), 'cn_name': brand_info[0].get('cn_name')} if brand_info else {}
classify_infos = self.rpc['neptune/commodity/classify/infos'](product_ids=[id_]).unwrap()
data['classify_names'] = [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')} for obj in classify_infos]
data['category_names'] = self.get_category_names(id_)
data['effect_names'] = self.get_effect_names(id_)
data['classify_infos'] = [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')} for obj in classify_infos]
data['category_infos'] = self.get_category_infos(id_)
data['effect_infos'] = self.get_effect_infos(id_)
return data
......
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