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
78fbdc84
Commit
78fbdc84
authored
Feb 13, 2019
by
张永
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/create_image_zy' into 'test'
fix See merge request
!58
parents
ca3ec3cb
dab15d0c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
26 deletions
+34
-26
user.py
api/user.py
+34
-26
No files found.
api/user.py
View file @
78fbdc84
...
@@ -5,7 +5,8 @@
...
@@ -5,7 +5,8 @@
import
json
import
json
from
django.conf
import
settings
from
django.conf
import
settings
from
gm_upload
import
upload
,
IMG_TYPE
,
upload_with_short
from
gm_types.ascle
import
ERROR
from
gm_upload
import
IMG_TYPE
,
upload_with_short
from
utils.base
import
APIView
from
utils.base
import
APIView
from
django.contrib.auth.hashers
import
make_password
from
django.contrib.auth.hashers
import
make_password
...
@@ -106,49 +107,56 @@ class UserImage(APIView):
...
@@ -106,49 +107,56 @@ class UserImage(APIView):
if
not
all
([
image_id
,
image_url
,
user_id
]):
if
not
all
([
image_id
,
image_url
,
user_id
]):
error_logger
.
error
(
u'参数不完整'
)
error_logger
.
error
(
u'参数不完整'
)
return
return
self
.
write_fail
(
code
=
ERROR
.
ARG_MISS
,
message
=
'参数不完整'
)
err
,
data
=
self
.
rpc
[
'saber/face/detect'
](
url
=
image_url
)
.
unwrap
()
if
err
:
resp
=
self
.
rpc
[
'venus/sun/user/check_image'
](
error_logger
.
error
(
u'获取人脸失败'
)
user_id
=
user_id
,
image_id
=
image_id
)
.
unwrap
()
faces
=
[
if
resp
:
{
return
self
.
write_success
(
data
=
''
,
message
=
'操作成功'
)
try
:
data
=
self
.
rpc
[
'saber/face/detect'
](
url
=
image_url
)
.
unwrap
()
except
Exception
as
e
:
error_logger
.
error
(
u'分析人脸失败:
%
s'
,
e
)
return
self
.
write_fail
(
code
=-
1
,
message
=
'分析人脸失败'
)
faces
=
[{
"point"
:
[
"point"
:
[
item
[
"rect"
][
"left"
],
item
[
"rect"
][
"left"
],
item
[
"rect"
][
"top"
],
item
[
"rect"
][
"top"
],
item
[
"rect"
][
"right"
]
-
item
[
"rect"
][
"left"
],
item
[
"rect"
][
"right"
]
-
item
[
"rect"
][
"left"
],
item
[
"rect"
][
"bottom"
]
-
item
[
"rect"
][
"top"
],
item
[
"rect"
][
"bottom"
]
-
item
[
"rect"
][
"top"
]]}
for
item
in
data
.
get
(
"faces"
,
[])]
]
if
faces
:
}
for
item
in
data
.
get
(
"faces"
,
[])
]
try
:
point
=
faces
[
0
]
.
get
(
'point'
,
[])
point
=
faces
[
0
]
.
get
(
'point'
,
[])
else
:
return
self
.
write_fail
(
code
=-
1
,
message
=
'获取人脸失败'
)
file_path
=
download_img_func
(
image_url
,
user_id
,
suffix
=
"png"
)
file_path
=
download_img_func
(
image_url
,
user_id
,
suffix
=
"png"
)
images
=
tailor_image
(
file_path
,
point
)
images
=
tailor_image
(
file_path
,
[
point
]
)
header_pic_path
=
images
[
0
]
header_pic_path
=
images
[
0
]
with
open
(
header_pic_path
,
'rb'
)
as
f
:
with
open
(
header_pic_path
,
'rb'
)
as
f
:
image_url
=
upload_with_short
(
f
,
img_type
=
IMG_TYPE
.
USEREXTRA
)[
0
]
image_url
=
upload_with_short
(
f
,
img_type
=
IMG_TYPE
.
USEREXTRA
)[
0
]
except
IndexError
:
try
:
error_logger
.
error
(
u'获取人脸失败'
)
return
except
:
error_logger
.
error
(
u'上传失败'
)
return
result
=
self
.
rpc
[
'venus/sun/user/create_update_image'
](
result
=
self
.
rpc
[
'venus/sun/user/create_update_image'
](
url
=
image_url
,
user_id
=
user_id
)
.
unwrap
()
image_url
=
image_url
,
user_id
=
user_id
,
image_id
=
image_id
)
.
unwrap
()
return
{
except
Exception
as
e
:
'message'
:
'创建成功'
if
result
else
'创建失败'
raise
e
}
return
self
.
write_fail
(
code
=-
1
if
result
else
0
,
message
=
"成功"
if
result
else
"失败"
)
def
get
(
self
,
request
):
def
get
(
self
,
request
):
user_id
=
request
.
GET
.
get
(
'user_id'
)
user_id
=
request
.
GET
.
get
(
'user_id'
)
offset
=
int
(
request
.
GET
.
get
(
'page'
,
1
))
offset
=
int
(
request
.
GET
.
get
(
'page'
,
1
))
count
=
int
(
request
.
GET
.
get
(
'limit'
,
10
))
count
=
int
(
request
.
GET
.
get
(
'limit'
,
10
))
if
not
user_id
:
error_logger
.
error
(
u'参数不完整'
)
return
self
.
write_fail
(
code
=
ERROR
.
ARG_MISS
,
message
=
'参数不完整'
)
try
:
try
:
data
=
self
.
rpc
[
'venus/sun/user/user_image_list'
](
data
=
self
.
rpc
[
'venus/sun/user/user_image_list'
](
user_id
=
user_id
,
offset
=
(
offset
-
1
)
*
count
,
limit
=
count
)
.
unwrap
()
user_id
=
user_id
,
offset
=
(
offset
-
1
)
*
count
,
limit
=
count
)
.
unwrap
()
except
Exception
as
e
:
except
Exception
as
e
:
error_logger
.
error
(
u'获取
%
s用户头像失败
%
s'
%
(
id
,
e
))
error_logger
.
error
(
u'获取
%
s用户头像失败
%
s'
%
(
user_
id
,
e
))
raise
raise
return
data
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