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
0a65c050
Commit
0a65c050
authored
May 07, 2021
by
cbartondock
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/janeczku/calibre-web
parents
12c32640
541c8c4b
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
24 deletions
+83
-24
admin.py
cps/admin.py
+31
-5
db.py
cps/db.py
+21
-10
details.js
cps/static/js/details.js
+15
-1
web.py
cps/web.py
+16
-8
No files found.
cps/admin.py
View file @
0a65c050
...
...
@@ -473,6 +473,21 @@ def update_table_settings():
return
"Invalid request"
,
400
return
""
def
check_valid_read_column
(
column
):
if
column
!=
"0"
:
if
not
calibre_db
.
session
.
query
(
db
.
Custom_Columns
)
.
filter
(
db
.
Custom_Columns
.
id
==
column
)
\
.
filter
(
and_
(
db
.
Custom_Columns
.
datatype
==
'bool'
,
db
.
Custom_Columns
.
mark_for_delete
==
0
))
.
all
():
return
False
return
True
def
check_valid_restricted_column
(
column
):
if
column
!=
"0"
:
if
not
calibre_db
.
session
.
query
(
db
.
Custom_Columns
)
.
filter
(
db
.
Custom_Columns
.
id
==
column
)
\
.
filter
(
and_
(
db
.
Custom_Columns
.
datatype
==
'text'
,
db
.
Custom_Columns
.
mark_for_delete
==
0
))
.
all
():
return
False
return
True
@
admi
.
route
(
"/admin/viewconfig"
,
methods
=
[
"POST"
])
@
login_required
...
...
@@ -488,12 +503,23 @@ def update_view_configuration():
if
_config_string
(
"config_title_regex"
):
calibre_db
.
update_title_sort
(
config
)
if
not
check_valid_read_column
(
to_save
.
get
(
"config_read_column"
,
"0"
)):
flash
(
_
(
u"Invalid Read Column"
),
category
=
"error"
)
log
.
debug
(
"Invalid Read column"
)
return
view_configuration
()
_config_int
(
"config_read_column"
)
if
not
check_valid_restricted_column
(
to_save
.
get
(
"config_restricted_column"
,
"0"
)):
flash
(
_
(
u"Invalid Restricted Column"
),
category
=
"error"
)
log
.
debug
(
"Invalid Restricted Column"
)
return
view_configuration
()
_config_int
(
"config_restricted_column"
)
_config_int
(
"config_theme"
)
_config_int
(
"config_random_books"
)
_config_int
(
"config_books_per_page"
)
_config_int
(
"config_authors_max"
)
_config_int
(
"config_restricted_column"
)
config
.
config_default_role
=
constants
.
selected_roles
(
to_save
)
config
.
config_default_role
&=
~
constants
.
ROLE_ANONYMOUS
...
...
@@ -723,10 +749,10 @@ def add_restriction(res_type, user_id):
usr
=
current_user
if
'submit_allow'
in
element
:
usr
.
allowed_tags
=
restriction_addition
(
element
,
usr
.
list_allowed_tags
)
ub
.
session_commit
(
"Changed allowed tags of user {} to {}"
.
format
(
usr
.
name
,
usr
.
list_allowed_tags
))
ub
.
session_commit
(
"Changed allowed tags of user {} to {}"
.
format
(
usr
.
name
,
usr
.
list_allowed_tags
()
))
elif
'submit_deny'
in
element
:
usr
.
denied_tags
=
restriction_addition
(
element
,
usr
.
list_denied_tags
)
ub
.
session_commit
(
"Changed denied tags of user {} to {}"
.
format
(
usr
.
name
,
usr
.
list_denied_tags
))
ub
.
session_commit
(
"Changed denied tags of user {} to {}"
.
format
(
usr
.
name
,
usr
.
list_denied_tags
()
))
if
res_type
==
3
:
# CustomC per user
if
isinstance
(
user_id
,
int
):
usr
=
ub
.
session
.
query
(
ub
.
User
)
.
filter
(
ub
.
User
.
id
==
int
(
user_id
))
.
first
()
...
...
@@ -735,11 +761,11 @@ def add_restriction(res_type, user_id):
if
'submit_allow'
in
element
:
usr
.
allowed_column_value
=
restriction_addition
(
element
,
usr
.
list_allowed_column_values
)
ub
.
session_commit
(
"Changed allowed columns of user {} to {}"
.
format
(
usr
.
name
,
usr
.
list_allowed_column_values
))
usr
.
list_allowed_column_values
()
))
elif
'submit_deny'
in
element
:
usr
.
denied_column_value
=
restriction_addition
(
element
,
usr
.
list_denied_column_values
)
ub
.
session_commit
(
"Changed denied columns of user {} to {}"
.
format
(
usr
.
name
,
usr
.
list_denied_column_values
))
usr
.
list_denied_column_values
()
))
return
""
...
...
cps/db.py
View file @
0a65c050
...
...
@@ -44,6 +44,7 @@ from flask_login import current_user
from
babel
import
Locale
as
LC
from
babel.core
import
UnknownLocaleError
from
flask_babel
import
gettext
as
_
from
flask
import
flash
from
.
import
logger
,
ub
,
isoLanguages
from
.pagination
import
Pagination
...
...
@@ -606,6 +607,7 @@ class CalibreDB():
neg_content_tags_filter
=
false
()
if
negtags_list
==
[
''
]
else
Books
.
tags
.
any
(
Tags
.
name
.
in_
(
negtags_list
))
pos_content_tags_filter
=
true
()
if
postags_list
==
[
''
]
else
Books
.
tags
.
any
(
Tags
.
name
.
in_
(
postags_list
))
if
self
.
config
.
config_restricted_column
:
try
:
pos_cc_list
=
current_user
.
allowed_column_value
.
split
(
','
)
pos_content_cc_filter
=
true
()
if
pos_cc_list
==
[
''
]
else
\
getattr
(
Books
,
'custom_column_'
+
str
(
self
.
config
.
config_restricted_column
))
.
\
...
...
@@ -614,6 +616,15 @@ class CalibreDB():
neg_content_cc_filter
=
false
()
if
neg_cc_list
==
[
''
]
else
\
getattr
(
Books
,
'custom_column_'
+
str
(
self
.
config
.
config_restricted_column
))
.
\
any
(
cc_classes
[
self
.
config
.
config_restricted_column
]
.
value
.
in_
(
neg_cc_list
))
except
(
KeyError
,
AttributeError
):
pos_content_cc_filter
=
false
()
neg_content_cc_filter
=
true
()
log
.
error
(
u"Custom Column No.
%
d is not existing in calibre database"
,
self
.
config
.
config_restricted_column
)
flash
(
_
(
"Custom Column No.
%(column)
d is not existing in calibre database"
,
column
=
self
.
config
.
config_restricted_column
),
category
=
"error"
)
else
:
pos_content_cc_filter
=
true
()
neg_content_cc_filter
=
false
()
...
...
cps/static/js/details.js
View file @
0a65c050
...
...
@@ -22,7 +22,21 @@ $(function() {
});
$
(
"#have_read_cb"
).
on
(
"change"
,
function
()
{
$
(
this
).
closest
(
"form"
).
submit
();
$
.
post
({
url
:
this
.
closest
(
"form"
).
action
,
error
:
function
(
response
)
{
var
data
=
[{
type
:
"danger"
,
message
:
response
.
responseText
}]
$
(
"#flash_success"
).
remove
();
$
(
"#flash_danger"
).
remove
();
if
(
!
jQuery
.
isEmptyObject
(
data
))
{
data
.
forEach
(
function
(
item
)
{
$
(
".navbar"
).
after
(
'<div class="row-fluid text-center" style="margin-top: -20px;">'
+
'<div id="flash_'
+
item
.
type
+
'" class="alert alert-'
+
item
.
type
+
'">'
+
item
.
message
+
'</div>'
+
'</div>'
);
});
}
}
});
});
$
(
function
()
{
...
...
cps/web.py
View file @
0a65c050
...
...
@@ -184,11 +184,12 @@ def toggle_read(book_id):
calibre_db
.
session
.
add
(
new_cc
)
calibre_db
.
session
.
commit
()
except
(
KeyError
,
AttributeError
):
log
.
error
(
u"Custom Column No.
%
d is not exisiting in calibre database"
,
config
.
config_read_column
)
log
.
error
(
u"Custom Column No.
%
d is not existing in calibre database"
,
config
.
config_read_column
)
return
"Custom Column No.{} is not existing in calibre database"
.
format
(
config
.
config_read_column
),
400
except
(
OperationalError
,
InvalidRequestError
)
as
e
:
calibre_db
.
session
.
rollback
()
log
.
error
(
u"Read status could not set:
%
e"
,
e
)
return
"Read status could not set: {}"
.
format
(
e
),
400
return
""
@
web
.
route
(
"/ajax/togglearchived/<int:book_id>"
,
methods
=
[
'POST'
])
...
...
@@ -1117,12 +1118,19 @@ def adv_search_ratings(q, rating_high, rating_low):
def
adv_search_read_status
(
q
,
read_status
):
if
read_status
:
if
config
.
config_read_column
:
try
:
if
read_status
==
"True"
:
q
=
q
.
join
(
db
.
cc_classes
[
config
.
config_read_column
],
isouter
=
True
)
\
.
filter
(
db
.
cc_classes
[
config
.
config_read_column
]
.
value
==
True
)
else
:
q
=
q
.
join
(
db
.
cc_classes
[
config
.
config_read_column
],
isouter
=
True
)
\
.
filter
(
coalesce
(
db
.
cc_classes
[
config
.
config_read_column
]
.
value
,
False
)
!=
True
)
except
(
KeyError
,
AttributeError
):
log
.
error
(
u"Custom Column No.
%
d is not existing in calibre database"
,
config
.
config_read_column
)
flash
(
_
(
"Custom Column No.
%(column)
d is not existing in calibre database"
,
column
=
config
.
config_read_column
),
category
=
"error"
)
return
q
else
:
if
read_status
==
"True"
:
q
=
q
.
join
(
ub
.
ReadBook
,
db
.
Books
.
id
==
ub
.
ReadBook
.
book_id
,
isouter
=
True
)
\
...
...
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