Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
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
captainwong
douban-api-proxy
Commits
000b85ff
Commit
000b85ff
authored
May 01, 2020
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes for deleting books(error handling and user feedback)
parent
bb317d54
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
10 deletions
+28
-10
admin.py
cps/admin.py
+0
-2
editbooks.py
cps/editbooks.py
+6
-1
helper.py
cps/helper.py
+22
-7
No files found.
cps/admin.py
View file @
000b85ff
...
...
@@ -933,8 +933,6 @@ def edit_user(user_id):
@
login_required
@
admin_required
def
reset_user_password
(
user_id
):
if
not
config
.
get_mail_server_configured
():
abort
(
404
)
if
current_user
is
not
None
and
current_user
.
is_authenticated
:
ret
,
message
=
reset_password
(
user_id
)
if
ret
==
1
:
...
...
cps/editbooks.py
View file @
000b85ff
...
...
@@ -177,7 +177,10 @@ def delete_book(book_id, book_format):
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
if
book
:
try
:
helper
.
delete_book
(
book
,
config
.
config_calibre_dir
,
book_format
=
book_format
.
upper
())
result
,
error
=
helper
.
delete_book
(
book
,
config
.
config_calibre_dir
,
book_format
=
book_format
.
upper
())
if
not
result
:
flash
(
error
,
category
=
"error"
)
return
redirect
(
url_for
(
'editbook.edit_book'
,
book_id
=
book_id
))
if
not
book_format
:
# delete book from Shelfs, Downloads, Read list
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
book_id
==
book_id
)
.
delete
()
...
...
@@ -233,8 +236,10 @@ def delete_book(book_id, book_format):
# book not found
log
.
error
(
'Book with id "
%
s" could not be deleted: not found'
,
book_id
)
if
book_format
:
flash
(
_
(
'Book Format Successfully Deleted'
),
category
=
"success"
)
return
redirect
(
url_for
(
'editbook.edit_book'
,
book_id
=
book_id
))
else
:
flash
(
_
(
'Book Successfully Deleted'
),
category
=
"success"
)
return
redirect
(
url_for
(
'web.index'
))
...
...
cps/helper.py
View file @
000b85ff
...
...
@@ -296,15 +296,29 @@ def delete_book_file(book, calibrepath, book_format=None):
if
os
.
path
.
isdir
(
path
):
if
len
(
next
(
os
.
walk
(
path
))[
1
]):
log
.
error
(
"Deleting book
%
s failed, path has subfolders:
%
s"
,
book
.
id
,
book
.
path
)
return
False
shutil
.
rmtree
(
path
,
ignore_errors
=
True
)
return
False
,
_
(
"Deleting book
%(id)
s failed, path has subfolders:
%(path)
s"
,
id
=
book
.
id
,
path
=
book
.
path
)
try
:
for
root
,
__
,
files
in
os
.
walk
(
path
):
for
f
in
files
:
os
.
unlink
(
os
.
path
.
join
(
root
,
f
))
shutil
.
rmtree
(
path
)
except
(
IOError
,
OSError
)
as
e
:
log
.
error
(
"Deleting book
%
s failed:
%
s"
,
book
.
id
,
e
)
return
False
,
_
(
"Deleting book
%(id)
s failed:
%(message)
s"
,
id
=
book
.
id
,
message
=
e
)
authorpath
=
os
.
path
.
join
(
calibrepath
,
os
.
path
.
split
(
book
.
path
)[
0
])
if
not
os
.
listdir
(
authorpath
):
shutil
.
rmtree
(
authorpath
,
ignore_errors
=
True
)
return
True
try
:
shutil
.
rmtree
(
authorpath
)
except
(
IOError
,
OSError
)
as
e
:
log
.
error
(
"Deleting authorpath for book
%
s failed:
%
s"
,
book
.
id
,
e
)
return
True
,
None
else
:
log
.
error
(
"Deleting book
%
s failed, book path not valid:
%
s"
,
book
.
id
,
book
.
path
)
return
False
return
False
,
_
(
"Deleting book
%(id)
s failed, book path not valid:
%(path)
s"
,
id
=
book
.
id
,
path
=
book
.
path
)
def
update_dir_structure_file
(
book_id
,
calibrepath
,
first_author
):
...
...
@@ -413,7 +427,7 @@ def update_dir_structure_gdrive(book_id, first_author):
def
delete_book_gdrive
(
book
,
book_format
):
error
=
Fals
e
error
=
Non
e
if
book_format
:
name
=
''
for
entry
in
book
.
data
:
...
...
@@ -427,7 +441,8 @@ def delete_book_gdrive(book, book_format):
gFile
.
Trash
()
else
:
error
=
_
(
u'Book path
%(path)
s not found on Google Drive'
,
path
=
book
.
path
)
# file not found
return
error
return
error
is
None
,
error
def
reset_password
(
user_id
):
...
...
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