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
0
Merge Requests
0
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
钟尚武
sun
Commits
88ee02ef
Commit
88ee02ef
authored
Apr 11, 2019
by
haowang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix code
parent
3057fc89
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
7 deletions
+13
-7
tools.py
api/tools.py
+13
-7
No files found.
api/tools.py
View file @
88ee02ef
...
...
@@ -10,22 +10,28 @@ class VirtualVote(APIView):
xls_file
=
request
.
FILES
.
get
(
'file'
)
if
not
xls_file
:
return
u'文件上传出错'
return
{
'message'
:
u'上传失败,请重新上传'
,
'code'
:
500
}
wb
=
load_workbook
(
xls_file
)
data
=
wb
.
get_sheet_by_name
(
wb
.
get_sheet_names
()[
0
])
row_data
=
[
item
.
value
for
row
in
data
.
rows
for
item
in
row
if
item
.
value
]
columns
=
[
item
for
item
in
data
.
columns
]
column_data
=
columns
[
0
]
column_data
=
[
item
.
value
for
item
in
column_data
]
if
'用户id'
not
in
column_data
:
return
{
'message'
:
u'文件数据格式错误,请确保内容中有”用户id“标题'
,
'code'
:
500
}
user_ids
=
[]
for
item
in
row
_data
:
for
item
in
column
_data
:
try
:
user_id
=
int
(
item
)
user_ids
.
append
(
user_id
)
except
:
continue
if
not
user_ids
:
return
u'上传文件失败'
return
{
'message'
:
u'上传失败,文件第一列不存在user_id数据'
,
'code'
:
500
}
self
.
rpc
[
'venus/sun/tools/virtual_vote'
](
user_ids
=
user_ids
)
.
unwrap
()
return
u'Ok'
return
{
'message'
:
u'上传成功'
,
'code'
:
200
}
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