Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
sun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alpha
sun
Commits
8aa1f996
Commit
8aa1f996
authored
Jul 06, 2019
by
haowang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix code
parent
34c2c5f9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
15 deletions
+21
-15
brand.py
api/brand.py
+5
-2
product.py
api/product.py
+16
-13
No files found.
api/brand.py
View file @
8aa1f996
...
...
@@ -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_
name
s'
]
=
[{
'id'
:
id_
,
'cn_name'
:
category_dict
.
get
(
str
(
id_
))
.
get
(
'cn_name'
)}
obj
[
'category_
info
s'
]
=
[{
'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
...
...
api/product.py
View file @
8aa1f996
...
...
@@ -17,7 +17,7 @@ class ProductListView(APIView):
if
not
category_infos
:
return
ret
for
obj
in
category_infos
:
product_id
=
obj
.
get
(
'pro
je
ct_id'
)
product_id
=
obj
.
get
(
'pro
du
ct_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
(
'pro
je
ct_id'
)
product_id
=
obj
.
get
(
'pro
du
ct_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
(
'pro
je
ct_id'
)
product_id
=
obj
.
get
(
'pro
du
ct_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_
name
s'
]
=
[{
'id'
:
obj
.
get
(
'id'
),
'cn_name'
:
obj
.
get
(
'cn_name'
)}
obj
[
'effect_
info
s'
]
=
[{
'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_
name
s'
]
=
[{
'id'
:
obj
.
get
(
'id'
),
'cn_name'
:
obj
.
get
(
'cn_name'
)}
obj
[
'classify_
info
s'
]
=
[{
'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_
name
s
(
self
,
product_id
):
def
get_category_
info
s
(
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_
name
s
(
self
,
product_id
):
def
get_effect_
info
s
(
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_
name
s'
]
=
[{
'id'
:
obj
.
get
(
'id'
),
'cn_name'
:
obj
.
get
(
'cn_name'
)}
for
obj
in
classify_infos
]
data
[
'category_
names'
]
=
self
.
get_category_name
s
(
id_
)
data
[
'effect_
names'
]
=
self
.
get_effect_name
s
(
id_
)
data
[
'classify_
info
s'
]
=
[{
'id'
:
obj
.
get
(
'id'
),
'cn_name'
:
obj
.
get
(
'cn_name'
)}
for
obj
in
classify_infos
]
data
[
'category_
infos'
]
=
self
.
get_category_info
s
(
id_
)
data
[
'effect_
infos'
]
=
self
.
get_effect_info
s
(
id_
)
return
data
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment