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
3db682cd
Commit
3db682cd
authored
Aug 04, 2018
by
Ozzie Isaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge remote-tracking branch 'del_books/delete-book-formats'
# Conflicts: # cps/helper.py Implemented delete on gdrive
parent
f81fbaf5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
57 deletions
+84
-57
helper.py
cps/helper.py
+28
-18
book_edit.html
cps/templates/book_edit.html
+9
-0
web.py
cps/web.py
+47
-39
No files found.
cps/helper.py
View file @
3db682cd
...
@@ -243,24 +243,27 @@ def get_sorted_author(value):
...
@@ -243,24 +243,27 @@ def get_sorted_author(value):
value2
=
value
value2
=
value
return
value2
return
value2
# Deletes a book fro the local filestorage, returns True if deleting is successfull, otherwise false
# Deletes a book fro the local filestorage, returns True if deleting is successfull, otherwise false
def
delete_book_file
(
book
,
calibrepath
):
def
delete_book_file
(
book
,
calibrepath
,
book_format
=
None
):
# check that path is 2 elements deep, check that target path has no subfolders
# check that path is 2 elements deep, check that target path has no subfolders
if
book
.
path
.
count
(
'/'
)
==
1
:
if
book
.
path
.
count
(
'/'
)
==
1
:
path
=
os
.
path
.
join
(
calibrepath
,
book
.
path
)
path
=
os
.
path
.
join
(
calibrepath
,
book
.
path
)
if
os
.
path
.
isdir
(
path
):
if
book_format
:
if
len
(
next
(
os
.
walk
(
path
))[
1
]):
for
file
in
os
.
listdir
(
path
):
web
.
app
.
logger
.
error
(
if
file
.
upper
()
.
endswith
(
"."
+
book_format
):
"Deleting book "
+
str
(
book
.
id
)
+
" failed, path has subfolders: "
+
book
.
path
)
os
.
remove
(
os
.
path
.
join
(
path
,
file
))
return
False
shutil
.
rmtree
(
path
,
ignore_errors
=
True
)
return
True
else
:
else
:
web
.
app
.
logger
.
error
(
"Deleting book "
+
str
(
book
.
id
)
+
" failed, book path not valid: "
+
book
.
path
)
if
os
.
path
.
isdir
(
path
):
return
False
if
len
(
next
(
os
.
walk
(
path
))[
1
]):
else
:
web
.
app
.
logger
.
error
(
web
.
app
.
logger
.
error
(
"Deleting book "
+
str
(
book
.
id
)
+
" failed, book path value: "
+
book
.
path
)
"Deleting book "
+
str
(
book
.
id
)
+
" failed, path has subfolders: "
+
book
.
path
)
return
False
return
False
shutil
.
rmtree
(
path
,
ignore_errors
=
True
)
return
True
else
:
web
.
app
.
logger
.
error
(
"Deleting book "
+
str
(
book
.
id
)
+
" failed, book path not valid: "
+
book
.
path
)
return
False
def
update_dir_stucture_file
(
book_id
,
calibrepath
):
def
update_dir_stucture_file
(
book_id
,
calibrepath
):
...
@@ -333,9 +336,16 @@ def update_dir_structure_gdrive(book_id):
...
@@ -333,9 +336,16 @@ def update_dir_structure_gdrive(book_id):
return
error
return
error
def
delete_book_gdrive
(
book
):
def
delete_book_gdrive
(
book
,
book_format
):
error
=
False
error
=
False
gFile
=
gd
.
getFileFromEbooksFolder
(
os
.
path
.
dirname
(
book
.
path
),
book
.
path
.
split
(
'/'
)[
1
])
if
book_format
:
name
=
''
for
entry
in
book
.
data
:
if
entry
.
format
.
upper
()
==
book_format
:
name
=
entry
.
name
+
'.'
+
book_format
gFile
=
gd
.
getFileFromEbooksFolder
(
book
.
path
,
name
)
else
:
gFile
=
gd
.
getFileFromEbooksFolder
(
os
.
path
.
dirname
(
book
.
path
),
book
.
path
.
split
(
'/'
)[
1
])
if
gFile
:
if
gFile
:
gd
.
deleteDatabaseEntry
(
gFile
[
'id'
])
gd
.
deleteDatabaseEntry
(
gFile
[
'id'
])
gFile
.
Trash
()
gFile
.
Trash
()
...
@@ -351,11 +361,11 @@ def update_dir_stucture(book_id, calibrepath):
...
@@ -351,11 +361,11 @@ def update_dir_stucture(book_id, calibrepath):
else
:
else
:
return
update_dir_stucture_file
(
book_id
,
calibrepath
)
return
update_dir_stucture_file
(
book_id
,
calibrepath
)
def
delete_book
(
book
,
calibrepath
):
def
delete_book
(
book
,
calibrepath
,
book_format
):
if
ub
.
config
.
config_use_google_drive
:
if
ub
.
config
.
config_use_google_drive
:
return
delete_book_gdrive
(
book
)
return
delete_book_gdrive
(
book
,
book_format
)
else
:
else
:
return
delete_book_file
(
book
,
calibrepath
)
return
delete_book_file
(
book
,
calibrepath
,
book_format
)
def
get_book_cover
(
cover_path
):
def
get_book_cover
(
cover_path
):
if
ub
.
config
.
config_use_google_drive
:
if
ub
.
config
.
config_use_google_drive
:
...
...
cps/templates/book_edit.html
View file @
3db682cd
...
@@ -15,6 +15,15 @@
...
@@ -15,6 +15,15 @@
<div
class=
"text-center"
>
<div
class=
"text-center"
>
<button
type=
"button"
class=
"btn btn-danger"
id=
"delete"
data-toggle=
"modal"
data-target=
"#deleteModal"
>
{{_("Delete Book")}}
</button>
<button
type=
"button"
class=
"btn btn-danger"
id=
"delete"
data-toggle=
"modal"
data-target=
"#deleteModal"
>
{{_("Delete Book")}}
</button>
</div>
</div>
{% if book.data|length > 1 %}
<div
class=
"text-center more-stuff"
><h4>
{{_('Delete formats:')}}
</h4>
{% for file in book.data %}
<div
class=
"form-group"
>
<a
href=
"{{ url_for('delete_book', book_id=book.id, book_format=file.format) }}"
class=
"btn btn-danger"
type=
"button"
>
{{_('Delete')}} - {{file.format}}
</a>
</div>
{% endfor %}
</div>
{% endif %}
{% endif %}
{% endif %}
</div>
</div>
<div
class=
"col-sm-9 col-xs-12"
>
<div
class=
"col-sm-9 col-xs-12"
>
...
...
cps/web.py
View file @
3db682cd
...
@@ -1480,55 +1480,63 @@ def stats():
...
@@ -1480,55 +1480,63 @@ def stats():
categorycounter
=
categorys
,
seriecounter
=
series
,
title
=
_
(
u"Statistics"
),
page
=
"stat"
)
categorycounter
=
categorys
,
seriecounter
=
series
,
title
=
_
(
u"Statistics"
),
page
=
"stat"
)
@
app
.
route
(
"/delete/<int:book_id>/"
)
@
app
.
route
(
"/delete/<int:book_id>/"
,
defaults
=
{
'book_format'
:
""
})
@
app
.
route
(
"/delete/<int:book_id>/<string:book_format>/"
)
@
login_required
@
login_required
def
delete_book
(
book_id
):
def
delete_book
(
book_id
,
book_format
):
if
current_user
.
role_delete_books
():
if
current_user
.
role_delete_books
():
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
if
book
:
if
book
:
# delete book from Shelfs, Downloads, Read list
helper
.
delete_book
(
book
,
config
.
config_calibre_dir
,
book_format
=
book_format
.
upper
())
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
book_id
==
book_id
)
.
delete
()
if
not
book_format
:
ub
.
session
.
query
(
ub
.
ReadBook
)
.
filter
(
ub
.
ReadBook
.
book_id
==
book_id
)
.
delete
()
# delete book from Shelfs, Downloads, Read list
# ToDo check Downloads.book right
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
book_id
==
book_id
)
.
delete
()
ub
.
delete_download
(
book_id
)
ub
.
session
.
query
(
ub
.
ReadBook
)
.
filter
(
ub
.
ReadBook
.
book_id
==
book_id
)
.
delete
()
# ub.session.query(ub.Downloads).filter(ub.Downloads.book_id == book_id).delete()
# ToDo check Downloads.book right
ub
.
session
.
commit
()
ub
.
delete_download
(
book_id
)
# ub.session.query(ub.Downloads).filter(ub.Downloads.book_id == book_id).delete()
ub
.
session
.
commit
()
helper
.
delete_book
(
book
,
config
.
config_calibre_dir
)
# check if only this book links to:
# check if only this book links to:
# author, language, series, tags, custom columns
# author, language, series, tags, custom columns
modify_database_object
([
u''
],
book
.
authors
,
db
.
Authors
,
db
.
session
,
'author'
)
modify_database_object
([
u''
],
book
.
authors
,
db
.
Authors
,
db
.
session
,
'author'
)
modify_database_object
([
u''
],
book
.
tags
,
db
.
Tags
,
db
.
session
,
'tags'
)
modify_database_object
([
u''
],
book
.
tags
,
db
.
Tags
,
db
.
session
,
'tags'
)
modify_database_object
([
u''
],
book
.
series
,
db
.
Series
,
db
.
session
,
'series'
)
modify_database_object
([
u''
],
book
.
series
,
db
.
Series
,
db
.
session
,
'series'
)
modify_database_object
([
u''
],
book
.
languages
,
db
.
Languages
,
db
.
session
,
'languages'
)
modify_database_object
([
u''
],
book
.
languages
,
db
.
Languages
,
db
.
session
,
'languages'
)
modify_database_object
([
u''
],
book
.
publishers
,
db
.
Publishers
,
db
.
session
,
'series'
)
modify_database_object
([
u''
],
book
.
publishers
,
db
.
Publishers
,
db
.
session
,
'series'
)
cc
=
db
.
session
.
query
(
db
.
Custom_Columns
)
.
filter
(
db
.
Custom_Columns
.
datatype
.
notin_
(
db
.
cc_exceptions
))
.
all
()
cc
=
db
.
session
.
query
(
db
.
Custom_Columns
)
.
filter
(
db
.
Custom_Columns
.
datatype
.
notin_
(
db
.
cc_exceptions
))
.
all
()
for
c
in
cc
:
for
c
in
cc
:
cc_string
=
"custom_column_"
+
str
(
c
.
id
)
cc_string
=
"custom_column_"
+
str
(
c
.
id
)
if
not
c
.
is_multiple
:
if
not
c
.
is_multiple
:
if
len
(
getattr
(
book
,
cc_string
))
>
0
:
if
len
(
getattr
(
book
,
cc_string
))
>
0
:
if
c
.
datatype
==
'bool'
or
c
.
datatype
==
'integer'
:
if
c
.
datatype
==
'bool'
or
c
.
datatype
==
'integer'
:
del_cc
=
getattr
(
book
,
cc_string
)[
0
]
del_cc
=
getattr
(
book
,
cc_string
)[
0
]
getattr
(
book
,
cc_string
)
.
remove
(
del_cc
)
getattr
(
book
,
cc_string
)
.
remove
(
del_cc
)
db
.
session
.
delete
(
del_cc
)
elif
c
.
datatype
==
'rating'
:
del_cc
=
getattr
(
book
,
cc_string
)[
0
]
getattr
(
book
,
cc_string
)
.
remove
(
del_cc
)
if
len
(
del_cc
.
books
)
==
0
:
db
.
session
.
delete
(
del_cc
)
db
.
session
.
delete
(
del_cc
)
else
:
elif
c
.
datatype
==
'rating'
:
del_cc
=
getattr
(
book
,
cc_string
)[
0
]
del_cc
=
getattr
(
book
,
cc_string
)[
0
]
getattr
(
book
,
cc_string
)
.
remove
(
del_cc
)
getattr
(
book
,
cc_string
)
.
remove
(
del_cc
)
db
.
session
.
delete
(
del_cc
)
if
len
(
del_cc
.
books
)
==
0
:
else
:
db
.
session
.
delete
(
del_cc
)
modify_database_object
([
u''
],
getattr
(
book
,
cc_string
),
db
.
cc_classes
[
c
.
id
],
db
.
session
,
'custom'
)
else
:
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
delete
()
del_cc
=
getattr
(
book
,
cc_string
)[
0
]
getattr
(
book
,
cc_string
)
.
remove
(
del_cc
)
db
.
session
.
delete
(
del_cc
)
else
:
modify_database_object
([
u''
],
getattr
(
book
,
cc_string
),
db
.
cc_classes
[
c
.
id
],
db
.
session
,
'custom'
)
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
delete
()
else
:
db
.
session
.
query
(
db
.
Data
)
.
filter
(
db
.
Data
.
book
==
book
.
id
)
.
filter
(
db
.
Data
.
format
==
book_format
)
.
delete
()
db
.
session
.
commit
()
db
.
session
.
commit
()
else
:
else
:
# book not found
ß
# book not found
app
.
logger
.
info
(
'Book with id "'
+
str
(
book_id
)
+
'" could not be deleted'
)
app
.
logger
.
info
(
'Book with id "'
+
str
(
book_id
)
+
'" could not be deleted'
)
return
redirect
(
url_for
(
'index'
))
if
book_format
:
return
redirect
(
url_for
(
'edit_book'
,
book_id
=
book_id
))
else
:
return
redirect
(
url_for
(
'index'
))
@
app
.
route
(
"/gdrive/authenticate"
)
@
app
.
route
(
"/gdrive/authenticate"
)
...
...
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