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
2e67bd24
Commit
2e67bd24
authored
Oct 10, 2020
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix add to shelf from search
parent
d70ded09
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
18 deletions
+22
-18
__init__.py
cps/__init__.py
+0
-1
db.py
cps/db.py
+6
-2
shelf.py
cps/shelf.py
+4
-4
ub.py
cps/ub.py
+9
-1
web.py
cps/web.py
+3
-10
No files found.
cps/__init__.py
View file @
2e67bd24
...
...
@@ -73,7 +73,6 @@ ub.init_db(cli.settingspath)
# pylint: disable=no-member
config
=
config_sql
.
load_configuration
(
ub
.
session
)
searched_ids
=
{}
web_server
=
WebServer
()
babel
=
Babel
()
...
...
cps/db.py
View file @
2e67bd24
...
...
@@ -543,7 +543,7 @@ class CalibreDB():
bind
=
cls
.
engine
))
for
inst
in
cls
.
instances
:
inst
.
initSession
()
cls
.
_init
=
True
return
True
...
...
@@ -685,7 +685,11 @@ class CalibreDB():
else
:
offset
=
0
limit_all
=
result_count
return
result
[
offset
:
limit_all
],
result_count
,
pagination
ub
.
store_ids
(
result
)
return
result
[
offset
:
limit_all
],
result_count
,
pagination
,
# Creates for all stored languages a translated speaking name in the array for the UI
def
speaking_language
(
self
,
languages
=
None
):
...
...
cps/shelf.py
View file @
2e67bd24
...
...
@@ -29,7 +29,7 @@ from flask_login import login_required, current_user
from
sqlalchemy.sql.expression
import
func
from
sqlalchemy.exc
import
OperationalError
,
InvalidRequestError
from
.
import
logger
,
ub
,
searched_ids
,
calibre_db
from
.
import
logger
,
ub
,
calibre_db
from
.web
import
login_required_if_no_ano
,
render_title_template
...
...
@@ -124,18 +124,18 @@ def search_to_shelf(shelf_id):
flash
(
_
(
u"You are not allowed to add a book to the the shelf:
%(name)
s"
,
name
=
shelf
.
name
),
category
=
"error"
)
return
redirect
(
url_for
(
'web.index'
))
if
current_user
.
id
in
searched_ids
and
searched_ids
[
current_user
.
id
]:
if
current_user
.
id
in
ub
.
searched_ids
and
ub
.
searched_ids
[
current_user
.
id
]:
books_for_shelf
=
list
()
books_in_shelf
=
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
shelf
==
shelf_id
)
.
all
()
if
books_in_shelf
:
book_ids
=
list
()
for
book_id
in
books_in_shelf
:
book_ids
.
append
(
book_id
.
book_id
)
for
searchid
in
searched_ids
[
current_user
.
id
]:
for
searchid
in
ub
.
searched_ids
[
current_user
.
id
]:
if
searchid
not
in
book_ids
:
books_for_shelf
.
append
(
searchid
)
else
:
books_for_shelf
=
searched_ids
[
current_user
.
id
]
books_for_shelf
=
ub
.
searched_ids
[
current_user
.
id
]
if
not
books_for_shelf
:
log
.
error
(
"Books are already part of
%
s"
,
shelf
)
...
...
cps/ub.py
View file @
2e67bd24
...
...
@@ -28,7 +28,7 @@ from binascii import hexlify
from
flask
import
g
from
flask_babel
import
gettext
as
_
from
flask_login
import
AnonymousUserMixin
from
flask_login
import
AnonymousUserMixin
,
current_user
from
werkzeug.local
import
LocalProxy
try
:
from
flask_dance.consumer.backend.sqla
import
OAuthConsumerMixin
...
...
@@ -54,6 +54,7 @@ from . import constants
session
=
None
app_DB_path
=
None
Base
=
declarative_base
()
searched_ids
=
{}
def
get_sidebar_config
(
kwargs
=
None
):
...
...
@@ -123,6 +124,13 @@ def get_sidebar_config(kwargs=None):
return
sidebar
def
store_ids
(
result
):
ids
=
list
()
for
element
in
result
:
ids
.
append
(
element
.
id
)
searched_ids
[
current_user
.
id
]
=
ids
class
UserBase
:
@
property
...
...
cps/web.py
View file @
2e67bd24
...
...
@@ -54,7 +54,7 @@ from werkzeug.datastructures import Headers
from
werkzeug.security
import
generate_password_hash
,
check_password_hash
from
.
import
constants
,
logger
,
isoLanguages
,
services
from
.
import
searched_ids
,
lm
,
babel
,
db
,
ub
,
config
,
get_locale
,
app
from
.
import
lm
,
babel
,
db
,
ub
,
config
,
get_locale
,
app
from
.
import
calibre_db
from
.gdriveutils
import
getFileFromEbooksFolder
,
do_gdrive_download
from
.helper
import
check_valid_domain
,
render_task_status
,
\
...
...
@@ -956,10 +956,6 @@ def render_prepare_search_form(cc):
def
render_search_results
(
term
,
offset
=
None
,
order
=
None
,
limit
=
None
):
entries
,
result_count
,
pagination
=
calibre_db
.
get_search_results
(
term
,
offset
,
order
,
limit
)
ids
=
list
()
for
element
in
entries
:
ids
.
append
(
element
.
id
)
searched_ids
[
current_user
.
id
]
=
ids
return
render_title_template
(
'search.html'
,
searchterm
=
term
,
pagination
=
pagination
,
...
...
@@ -1239,6 +1235,7 @@ def search():
title
=
_
(
u"Search"
),
page
=
"search"
)
@
web
.
route
(
"/advanced_search"
,
methods
=
[
'POST'
])
@
login_required_if_no_ano
def
advanced_search
():
...
...
@@ -1380,11 +1377,7 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
func
.
lower
(
db
.
cc_classes
[
c
.
id
]
.
value
)
.
ilike
(
"
%
"
+
custom_query
+
"
%
"
)))
q
=
q
.
order_by
(
*
order
)
.
all
()
flask_session
[
'query'
]
=
json
.
dumps
(
term
)
# ToDo: Check saved ids mechanism ?
ids
=
list
()
for
element
in
q
:
ids
.
append
(
element
.
id
)
searched_ids
[
current_user
.
id
]
=
ids
ub
.
store_ids
(
q
)
# entries, result_count, pagination = calibre_db.get_search_results(term, offset, order, limit)
result_count
=
len
(
q
)
if
offset
!=
None
and
limit
!=
None
:
...
...
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