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
e29f17ac
Commit
e29f17ac
authored
Apr 24, 2020
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'kobo/shelves' into Develop
# Conflicts: # cps/kobo.py # cps/shelf.py
parents
95ca1e6a
742ec2b3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
18 additions
and
15 deletions
+18
-15
constants.py
cps/constants.py
+1
-1
editbooks.py
cps/editbooks.py
+1
-1
kobo.py
cps/kobo.py
+6
-9
server.py
cps/server.py
+1
-1
shelf.py
cps/shelf.py
+7
-1
book_edit.html
cps/templates/book_edit.html
+2
-2
No files found.
cps/constants.py
View file @
e29f17ac
...
@@ -82,7 +82,7 @@ SIDEBAR_RATING = 1 << 13
...
@@ -82,7 +82,7 @@ SIDEBAR_RATING = 1 << 13
SIDEBAR_FORMAT
=
1
<<
14
SIDEBAR_FORMAT
=
1
<<
14
SIDEBAR_ARCHIVED
=
1
<<
15
SIDEBAR_ARCHIVED
=
1
<<
15
ADMIN_USER_ROLES
=
sum
(
r
for
r
in
ALL_ROLES
.
values
())
&
~
ROLE_
EDIT_SHELFS
&
~
ROLE_
ANONYMOUS
ADMIN_USER_ROLES
=
sum
(
r
for
r
in
ALL_ROLES
.
values
())
&
~
ROLE_ANONYMOUS
ADMIN_USER_SIDEBAR
=
(
SIDEBAR_ARCHIVED
<<
1
)
-
1
ADMIN_USER_SIDEBAR
=
(
SIDEBAR_ARCHIVED
<<
1
)
-
1
UPDATE_STABLE
=
0
<<
0
UPDATE_STABLE
=
0
<<
0
...
...
cps/editbooks.py
View file @
e29f17ac
...
@@ -181,7 +181,7 @@ def delete_book(book_id, book_format):
...
@@ -181,7 +181,7 @@ def delete_book(book_id, book_format):
# delete book from Shelfs, Downloads, Read list
# delete book from Shelfs, Downloads, Read list
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
book_id
==
book_id
)
.
delete
()
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
book_id
==
book_id
)
.
delete
()
ub
.
session
.
query
(
ub
.
ReadBook
)
.
filter
(
ub
.
ReadBook
.
book_id
==
book_id
)
.
delete
()
ub
.
session
.
query
(
ub
.
ReadBook
)
.
filter
(
ub
.
ReadBook
.
book_id
==
book_id
)
.
delete
()
ub
.
session
.
query
(
ub
.
ArchivedBook
)
.
filter
(
ub
.
Rea
dBook
.
book_id
==
book_id
)
.
delete
()
ub
.
session
.
query
(
ub
.
ArchivedBook
)
.
filter
(
ub
.
Archive
dBook
.
book_id
==
book_id
)
.
delete
()
ub
.
delete_download
(
book_id
)
ub
.
delete_download
(
book_id
)
ub
.
session
.
commit
()
ub
.
session
.
commit
()
...
...
cps/kobo.py
View file @
e29f17ac
...
@@ -407,10 +407,8 @@ def HandleTagCreate():
...
@@ -407,10 +407,8 @@ def HandleTagCreate():
log
.
debug
(
"Received malformed v1/library/tags request."
)
log
.
debug
(
"Received malformed v1/library/tags request."
)
abort
(
400
,
description
=
"Malformed tags POST request. Data is missing 'Name' or 'Items' field"
)
abort
(
400
,
description
=
"Malformed tags POST request. Data is missing 'Name' or 'Items' field"
)
# ToDO: Names are not unique ! -> filter only private shelfs
shelf
=
ub
.
session
.
query
(
ub
.
Shelf
)
.
filter
(
ub
.
Shelf
.
name
==
name
,
ub
.
Shelf
.
user_id
==
shelf
=
ub
.
session
.
query
(
ub
.
Shelf
)
.
filter
(
and_
(
ub
.
Shelf
.
name
)
==
name
,
ub
.
Shelf
.
user_id
==
current_user
.
id
)
.
one_or_none
()
current_user
.
id
)
.
one_or_none
()
# ToDO: shouldn't it ) at the end
if
shelf
and
not
shelf_lib
.
check_shelf_edit_permissions
(
shelf
):
if
shelf
and
not
shelf_lib
.
check_shelf_edit_permissions
(
shelf
):
abort
(
401
,
description
=
"User is unauthaurized to edit shelf."
)
abort
(
401
,
description
=
"User is unauthaurized to edit shelf."
)
...
@@ -428,7 +426,7 @@ def HandleTagCreate():
...
@@ -428,7 +426,7 @@ def HandleTagCreate():
@
kobo
.
route
(
"/v1/library/tags/<tag_id>"
,
methods
=
[
"DELETE"
,
"PUT"
])
@
kobo
.
route
(
"/v1/library/tags/<tag_id>"
,
methods
=
[
"DELETE"
,
"PUT"
])
def
HandleTagUpdate
(
tag_id
):
def
HandleTagUpdate
(
tag_id
):
shelf
=
ub
.
session
.
query
(
ub
.
Shelf
)
.
filter
(
and_
(
ub
.
Shelf
.
uuid
)
==
tag_id
,
shelf
=
ub
.
session
.
query
(
ub
.
Shelf
)
.
filter
(
ub
.
Shelf
.
uuid
==
tag_id
,
ub
.
Shelf
.
user_id
==
current_user
.
id
)
.
one_or_none
()
ub
.
Shelf
.
user_id
==
current_user
.
id
)
.
one_or_none
()
if
not
shelf
:
if
not
shelf
:
log
.
debug
(
"Received Kobo tag update request on a collection unknown to CalibreWeb"
)
log
.
debug
(
"Received Kobo tag update request on a collection unknown to CalibreWeb"
)
...
@@ -489,7 +487,7 @@ def HandleTagAddItem(tag_id):
...
@@ -489,7 +487,7 @@ def HandleTagAddItem(tag_id):
log
.
debug
(
"Received malformed v1/library/tags/<tag_id>/items/delete request."
)
log
.
debug
(
"Received malformed v1/library/tags/<tag_id>/items/delete request."
)
abort
(
400
,
description
=
"Malformed tags POST request. Data is missing 'Items' field"
)
abort
(
400
,
description
=
"Malformed tags POST request. Data is missing 'Items' field"
)
shelf
=
ub
.
session
.
query
(
ub
.
Shelf
)
.
filter
(
and_
(
ub
.
Shelf
.
uuid
)
==
tag_id
,
shelf
=
ub
.
session
.
query
(
ub
.
Shelf
)
.
filter
(
ub
.
Shelf
.
uuid
==
tag_id
,
ub
.
Shelf
.
user_id
==
current_user
.
id
)
.
one_or_none
()
ub
.
Shelf
.
user_id
==
current_user
.
id
)
.
one_or_none
()
if
not
shelf
:
if
not
shelf
:
log
.
debug
(
"Received Kobo request on a collection unknown to CalibreWeb"
)
log
.
debug
(
"Received Kobo request on a collection unknown to CalibreWeb"
)
...
@@ -500,7 +498,7 @@ def HandleTagAddItem(tag_id):
...
@@ -500,7 +498,7 @@ def HandleTagAddItem(tag_id):
items_unknown_to_calibre
=
add_items_to_shelf
(
items
,
shelf
)
items_unknown_to_calibre
=
add_items_to_shelf
(
items
,
shelf
)
if
items_unknown_to_calibre
:
if
items_unknown_to_calibre
:
log
.
debug
(
"Received request to add an unknown book to a collec
i
tion. Silently ignoring item."
)
log
.
debug
(
"Received request to add an unknown book to a collection. Silently ignoring item."
)
ub
.
session
.
merge
(
shelf
)
ub
.
session
.
merge
(
shelf
)
ub
.
session
.
commit
()
ub
.
session
.
commit
()
...
@@ -605,8 +603,7 @@ def create_kobo_tag(shelf):
...
@@ -605,8 +603,7 @@ def create_kobo_tag(shelf):
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_shelf
.
book_id
)
.
one_or_none
()
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_shelf
.
book_id
)
.
one_or_none
()
if
not
book
:
if
not
book
:
log
.
info
(
u"Book (id:
%
s) in BookShelf (id:
%
s) not found in book database"
,
book_shelf
.
book_id
,
shelf
.
id
)
log
.
info
(
u"Book (id:
%
s) in BookShelf (id:
%
s) not found in book database"
,
book_shelf
.
book_id
,
shelf
.
id
)
# ToDo shouldn't it continue?
continue
return
None
tag
[
"Items"
]
.
append
(
tag
[
"Items"
]
.
append
(
{
{
"RevisionId"
:
book
.
uuid
,
"RevisionId"
:
book
.
uuid
,
...
...
cps/server.py
View file @
e29f17ac
...
@@ -24,7 +24,7 @@ import signal
...
@@ -24,7 +24,7 @@ import signal
import
socket
import
socket
try
:
try
:
from
gevent.pywsgi
import
WSGIServer
from
gevent.pyw
t
sgi
import
WSGIServer
from
gevent.pool
import
Pool
from
gevent.pool
import
Pool
from
gevent
import
__version__
as
_version
from
gevent
import
__version__
as
_version
VERSION
=
'Gevent '
+
_version
VERSION
=
'Gevent '
+
_version
...
...
cps/shelf.py
View file @
e29f17ac
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
division
,
print_function
,
unicode_literals
from
__future__
import
division
,
print_function
,
unicode_literals
from
datetime
import
datetime
from
flask
import
Blueprint
,
request
,
flash
,
redirect
,
url_for
from
flask
import
Blueprint
,
request
,
flash
,
redirect
,
url_for
from
flask_babel
import
gettext
as
_
from
flask_babel
import
gettext
as
_
...
@@ -90,6 +91,7 @@ def add_to_shelf(shelf_id, book_id):
...
@@ -90,6 +91,7 @@ def add_to_shelf(shelf_id, book_id):
maxOrder
=
maxOrder
[
0
]
maxOrder
=
maxOrder
[
0
]
shelf
.
books
.
append
(
ub
.
BookShelf
(
shelf
=
shelf
.
id
,
book_id
=
book_id
,
order
=
maxOrder
+
1
))
shelf
.
books
.
append
(
ub
.
BookShelf
(
shelf
=
shelf
.
id
,
book_id
=
book_id
,
order
=
maxOrder
+
1
))
shelf
.
last_modified
=
datetime
.
utcnow
()
ub
.
session
.
merge
(
shelf
)
ub
.
session
.
merge
(
shelf
)
ub
.
session
.
commit
()
ub
.
session
.
commit
()
if
not
xhr
:
if
not
xhr
:
...
@@ -141,6 +143,7 @@ def search_to_shelf(shelf_id):
...
@@ -141,6 +143,7 @@ def search_to_shelf(shelf_id):
for
book
in
books_for_shelf
:
for
book
in
books_for_shelf
:
maxOrder
=
maxOrder
+
1
maxOrder
=
maxOrder
+
1
shelf
.
books
.
append
(
ub
.
BookShelf
(
shelf
=
shelf
.
id
,
book_id
=
book
,
order
=
maxOrder
))
shelf
.
books
.
append
(
ub
.
BookShelf
(
shelf
=
shelf
.
id
,
book_id
=
book
,
order
=
maxOrder
))
shelf
.
last_modified
=
datetime
.
utcnow
()
ub
.
session
.
merge
(
shelf
)
ub
.
session
.
merge
(
shelf
)
ub
.
session
.
commit
()
ub
.
session
.
commit
()
flash
(
_
(
u"Books have been added to shelf:
%(sname)
s"
,
sname
=
shelf
.
name
),
category
=
"success"
)
flash
(
_
(
u"Books have been added to shelf:
%(sname)
s"
,
sname
=
shelf
.
name
),
category
=
"success"
)
...
@@ -179,6 +182,7 @@ def remove_from_shelf(shelf_id, book_id):
...
@@ -179,6 +182,7 @@ def remove_from_shelf(shelf_id, book_id):
return
"Book already removed from shelf"
,
410
return
"Book already removed from shelf"
,
410
ub
.
session
.
delete
(
book_shelf
)
ub
.
session
.
delete
(
book_shelf
)
shelf
.
last_modified
=
datetime
.
utcnow
()
ub
.
session
.
commit
()
ub
.
session
.
commit
()
if
not
xhr
:
if
not
xhr
:
...
@@ -269,6 +273,7 @@ def edit_shelf(shelf_id):
...
@@ -269,6 +273,7 @@ def edit_shelf(shelf_id):
if
is_shelf_name_unique
:
if
is_shelf_name_unique
:
shelf
.
name
=
to_save
[
"title"
]
shelf
.
name
=
to_save
[
"title"
]
shelf
.
last_modified
=
datetime
.
utcnow
()
if
"is_public"
in
to_save
:
if
"is_public"
in
to_save
:
shelf
.
is_public
=
1
shelf
.
is_public
=
1
else
:
else
:
...
@@ -289,7 +294,7 @@ def delete_shelf_helper(cur_shelf):
...
@@ -289,7 +294,7 @@ def delete_shelf_helper(cur_shelf):
shelf_id
=
cur_shelf
.
id
shelf_id
=
cur_shelf
.
id
ub
.
session
.
delete
(
cur_shelf
)
ub
.
session
.
delete
(
cur_shelf
)
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
shelf
==
shelf_id
)
.
delete
()
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
shelf
==
shelf_id
)
.
delete
()
ub
.
session
.
add
(
ub
.
ShelfArchive
(
uuid
=
cur_shelf
.
uuid
,
user_id
=
cur_shelf
.
u
u
id
))
ub
.
session
.
add
(
ub
.
ShelfArchive
(
uuid
=
cur_shelf
.
uuid
,
user_id
=
cur_shelf
.
u
ser_
id
))
ub
.
session
.
commit
()
ub
.
session
.
commit
()
log
.
info
(
"successfully deleted
%
s"
,
cur_shelf
)
log
.
info
(
"successfully deleted
%
s"
,
cur_shelf
)
...
@@ -342,6 +347,7 @@ def order_shelf(shelf_id):
...
@@ -342,6 +347,7 @@ def order_shelf(shelf_id):
for
book
in
books_in_shelf
:
for
book
in
books_in_shelf
:
setattr
(
book
,
'order'
,
to_save
[
str
(
book
.
book_id
)])
setattr
(
book
,
'order'
,
to_save
[
str
(
book
.
book_id
)])
counter
+=
1
counter
+=
1
# if order diffrent from before -> shelf.last_modified = datetime.utcnow()
ub
.
session
.
commit
()
ub
.
session
.
commit
()
shelf
=
ub
.
session
.
query
(
ub
.
Shelf
)
.
filter
(
ub
.
Shelf
.
id
==
shelf_id
)
.
first
()
shelf
=
ub
.
session
.
query
(
ub
.
Shelf
)
.
filter
(
ub
.
Shelf
.
id
==
shelf_id
)
.
first
()
...
...
cps/templates/book_edit.html
View file @
e29f17ac
...
@@ -213,7 +213,7 @@
...
@@ -213,7 +213,7 @@
</div>
</div>
<div
class=
"modal-footer"
>
<div
class=
"modal-footer"
>
<a
href=
"{{ url_for('editbook.delete_book', book_id=book.id) }}"
class=
"btn btn-danger"
>
{{_('Delete')}}
</a>
<a
href=
"{{ url_for('editbook.delete_book', book_id=book.id) }}"
id=
"delete_confirm"
class=
"btn btn-danger"
>
{{_('Delete')}}
</a>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
{{_('Cancel')}}
</button>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
{{_('Cancel')}}
</button>
</div>
</div>
</div>
</div>
...
@@ -313,7 +313,7 @@
...
@@ -313,7 +313,7 @@
});
});
function
removeIdentifierLine
(
el
)
{
function
removeIdentifierLine
(
el
)
{
$
(
el
).
parent
().
parent
().
remove
();
$
(
el
).
parent
().
parent
().
remove
();
}
}
</script>
</script>
<script
src=
"{{ url_for('static', filename='js/libs/typeahead.bundle.js') }}"
></script>
<script
src=
"{{ url_for('static', filename='js/libs/typeahead.bundle.js') }}"
></script>
...
...
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