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
f9c3e751
Commit
f9c3e751
authored
Jul 24, 2021
by
Ozzie Isaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes for handling shelf requests without title
parent
c7b057ec
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
18 deletions
+18
-18
shelf.py
cps/shelf.py
+18
-18
No files found.
cps/shelf.py
View file @
f9c3e751
...
@@ -72,7 +72,7 @@ def add_to_shelf(shelf_id, book_id):
...
@@ -72,7 +72,7 @@ def add_to_shelf(shelf_id, book_id):
if
not
check_shelf_edit_permissions
(
shelf
):
if
not
check_shelf_edit_permissions
(
shelf
):
if
not
xhr
:
if
not
xhr
:
flash
(
_
(
u"Sorry you are not allowed to add a book to th
e the
shelf"
),
category
=
"error"
)
flash
(
_
(
u"Sorry you are not allowed to add a book to th
at
shelf"
),
category
=
"error"
)
return
redirect
(
url_for
(
'web.index'
))
return
redirect
(
url_for
(
'web.index'
))
return
"Sorry you are not allowed to add a book to the that shelf"
,
403
return
"Sorry you are not allowed to add a book to the that shelf"
,
403
...
@@ -227,7 +227,7 @@ def remove_from_shelf(shelf_id, book_id):
...
@@ -227,7 +227,7 @@ def remove_from_shelf(shelf_id, book_id):
@
login_required
@
login_required
def
create_shelf
():
def
create_shelf
():
shelf
=
ub
.
Shelf
()
shelf
=
ub
.
Shelf
()
return
create_edit_shelf
(
shelf
,
title
=
_
(
u"Create a Shelf"
),
page
=
"shelfcreate"
)
return
create_edit_shelf
(
shelf
,
page_
title
=
_
(
u"Create a Shelf"
),
page
=
"shelfcreate"
)
@
shelf
.
route
(
"/shelf/edit/<int:shelf_id>"
,
methods
=
[
"GET"
,
"POST"
])
@
shelf
.
route
(
"/shelf/edit/<int:shelf_id>"
,
methods
=
[
"GET"
,
"POST"
])
...
@@ -237,11 +237,11 @@ def edit_shelf(shelf_id):
...
@@ -237,11 +237,11 @@ def edit_shelf(shelf_id):
if
not
check_shelf_edit_permissions
(
shelf
):
if
not
check_shelf_edit_permissions
(
shelf
):
flash
(
_
(
u"Sorry you are not allowed to edit this shelf"
),
category
=
"error"
)
flash
(
_
(
u"Sorry you are not allowed to edit this shelf"
),
category
=
"error"
)
return
redirect
(
url_for
(
'web.index'
))
return
redirect
(
url_for
(
'web.index'
))
return
create_edit_shelf
(
shelf
,
title
=
_
(
u"Edit a shelf"
),
page
=
"shelfedit"
,
shelf_id
=
shelf_id
)
return
create_edit_shelf
(
shelf
,
page_
title
=
_
(
u"Edit a shelf"
),
page
=
"shelfedit"
,
shelf_id
=
shelf_id
)
# if shelf ID is set, we are editing a shelf
# if shelf ID is set, we are editing a shelf
def
create_edit_shelf
(
shelf
,
title
,
page
,
shelf_id
=
False
):
def
create_edit_shelf
(
shelf
,
page_
title
,
page
,
shelf_id
=
False
):
sync_only_selected_shelves
=
current_user
.
kobo_only_shelves_sync
sync_only_selected_shelves
=
current_user
.
kobo_only_shelves_sync
# calibre_db.session.query(ub.Shelf).filter(ub.Shelf.user_id == current_user.id).filter(ub.Shelf.kobo_sync).count()
# calibre_db.session.query(ub.Shelf).filter(ub.Shelf.user_id == current_user.id).filter(ub.Shelf.kobo_sync).count()
if
request
.
method
==
"POST"
:
if
request
.
method
==
"POST"
:
...
@@ -249,20 +249,20 @@ def create_edit_shelf(shelf, title, page, shelf_id=False):
...
@@ -249,20 +249,20 @@ def create_edit_shelf(shelf, title, page, shelf_id=False):
shelf
.
is_public
=
1
if
to_save
.
get
(
"is_public"
)
else
0
shelf
.
is_public
=
1
if
to_save
.
get
(
"is_public"
)
else
0
if
config
.
config_kobo_sync
:
if
config
.
config_kobo_sync
:
shelf
.
kobo_sync
=
True
if
to_save
.
get
(
"kobo_sync"
)
else
False
shelf
.
kobo_sync
=
True
if
to_save
.
get
(
"kobo_sync"
)
else
False
shelf_title
=
to_save
.
get
(
"title"
,
""
)
if
check_shelf_is_unique
(
shelf
,
to_sav
e
,
shelf_id
):
if
check_shelf_is_unique
(
shelf
,
shelf_titl
e
,
shelf_id
):
shelf
.
name
=
to_save
.
get
(
"title"
,
""
)
shelf
.
name
=
shelf_title
if
not
shelf_id
:
if
not
shelf_id
:
shelf
.
user_id
=
int
(
current_user
.
id
)
shelf
.
user_id
=
int
(
current_user
.
id
)
ub
.
session
.
add
(
shelf
)
ub
.
session
.
add
(
shelf
)
shelf_action
=
"created"
shelf_action
=
"created"
flash_text
=
_
(
u"Shelf
%(title)
s created"
,
title
=
to_save
.
get
(
"title"
,
""
)
)
flash_text
=
_
(
u"Shelf
%(title)
s created"
,
title
=
shelf_title
)
else
:
else
:
shelf_action
=
"changed"
shelf_action
=
"changed"
flash_text
=
_
(
u"Shelf
%(title)
s changed"
,
title
=
to_save
.
get
(
"title"
,
""
)
)
flash_text
=
_
(
u"Shelf
%(title)
s changed"
,
title
=
shelf_title
)
try
:
try
:
ub
.
session
.
commit
()
ub
.
session
.
commit
()
log
.
info
(
u"Shelf {} {}"
.
format
(
to_save
.
get
(
"title"
,
""
)
,
shelf_action
))
log
.
info
(
u"Shelf {} {}"
.
format
(
shelf_title
,
shelf_action
))
flash
(
flash_text
,
category
=
"success"
)
flash
(
flash_text
,
category
=
"success"
)
return
redirect
(
url_for
(
'shelf.show_shelf'
,
shelf_id
=
shelf
.
id
))
return
redirect
(
url_for
(
'shelf.show_shelf'
,
shelf_id
=
shelf
.
id
))
except
(
OperationalError
,
InvalidRequestError
)
as
ex
:
except
(
OperationalError
,
InvalidRequestError
)
as
ex
:
...
@@ -276,37 +276,37 @@ def create_edit_shelf(shelf, title, page, shelf_id=False):
...
@@ -276,37 +276,37 @@ def create_edit_shelf(shelf, title, page, shelf_id=False):
flash
(
_
(
u"There was an error"
),
category
=
"error"
)
flash
(
_
(
u"There was an error"
),
category
=
"error"
)
return
render_title_template
(
'shelf_edit.html'
,
return
render_title_template
(
'shelf_edit.html'
,
shelf
=
shelf
,
shelf
=
shelf
,
title
=
title
,
title
=
page_
title
,
page
=
page
,
page
=
page
,
kobo_sync_enabled
=
config
.
config_kobo_sync
,
kobo_sync_enabled
=
config
.
config_kobo_sync
,
sync_only_selected_shelves
=
sync_only_selected_shelves
)
sync_only_selected_shelves
=
sync_only_selected_shelves
)
def
check_shelf_is_unique
(
shelf
,
t
o_sav
e
,
shelf_id
=
False
):
def
check_shelf_is_unique
(
shelf
,
t
itl
e
,
shelf_id
=
False
):
if
shelf_id
:
if
shelf_id
:
ident
=
ub
.
Shelf
.
id
!=
shelf_id
ident
=
ub
.
Shelf
.
id
!=
shelf_id
else
:
else
:
ident
=
true
()
ident
=
true
()
if
shelf
.
is_public
==
1
:
if
shelf
.
is_public
==
1
:
is_shelf_name_unique
=
ub
.
session
.
query
(
ub
.
Shelf
)
\
is_shelf_name_unique
=
ub
.
session
.
query
(
ub
.
Shelf
)
\
.
filter
((
ub
.
Shelf
.
name
==
t
o_save
[
"title"
]
)
&
(
ub
.
Shelf
.
is_public
==
1
))
\
.
filter
((
ub
.
Shelf
.
name
==
t
itle
)
&
(
ub
.
Shelf
.
is_public
==
1
))
\
.
filter
(
ident
)
\
.
filter
(
ident
)
\
.
first
()
is
None
.
first
()
is
None
if
not
is_shelf_name_unique
:
if
not
is_shelf_name_unique
:
log
.
error
(
"A public shelf with the name '{}' already exists."
.
format
(
t
o_save
[
"title"
]
))
log
.
error
(
"A public shelf with the name '{}' already exists."
.
format
(
t
itle
))
flash
(
_
(
u"A public shelf with the name '
%(title)
s' already exists."
,
title
=
t
o_save
[
"title"
]
),
flash
(
_
(
u"A public shelf with the name '
%(title)
s' already exists."
,
title
=
t
itle
),
category
=
"error"
)
category
=
"error"
)
else
:
else
:
is_shelf_name_unique
=
ub
.
session
.
query
(
ub
.
Shelf
)
\
is_shelf_name_unique
=
ub
.
session
.
query
(
ub
.
Shelf
)
\
.
filter
((
ub
.
Shelf
.
name
==
t
o_save
.
get
(
"title"
,
""
)
)
&
(
ub
.
Shelf
.
is_public
==
0
)
&
.
filter
((
ub
.
Shelf
.
name
==
t
itle
)
&
(
ub
.
Shelf
.
is_public
==
0
)
&
(
ub
.
Shelf
.
user_id
==
int
(
current_user
.
id
)))
\
(
ub
.
Shelf
.
user_id
==
int
(
current_user
.
id
)))
\
.
filter
(
ident
)
\
.
filter
(
ident
)
\
.
first
()
is
None
.
first
()
is
None
if
not
is_shelf_name_unique
:
if
not
is_shelf_name_unique
:
log
.
error
(
"A private shelf with the name '{}' already exists."
.
format
(
t
o_save
[
"title"
]
))
log
.
error
(
"A private shelf with the name '{}' already exists."
.
format
(
t
itle
))
flash
(
_
(
u"A private shelf with the name '
%(title)
s' already exists."
,
title
=
t
o_save
[
"title"
]
),
flash
(
_
(
u"A private shelf with the name '
%(title)
s' already exists."
,
title
=
t
itle
),
category
=
"error"
)
category
=
"error"
)
return
is_shelf_name_unique
return
is_shelf_name_unique
...
...
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