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
9d5e9b28
Commit
9d5e9b28
authored
Oct 16, 2021
by
Ozzie Isaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enabled editing of "number" custom_columns in books list
parent
6f1e78b9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
16 deletions
+41
-16
db.py
cps/db.py
+5
-2
editbooks.py
cps/editbooks.py
+19
-7
table.js
cps/static/js/table.js
+4
-0
book_table.html
cps/templates/book_table.html
+11
-0
web.py
cps/web.py
+2
-7
No files found.
cps/db.py
View file @
9d5e9b28
...
...
@@ -395,7 +395,7 @@ class AlchemyEncoder(json.JSONEncoder):
if
isinstance
(
o
.
__class__
,
DeclarativeMeta
):
# an SQLAlchemy class
fields
=
{}
for
field
in
[
x
for
x
in
dir
(
o
)
if
not
x
.
startswith
(
'_'
)
and
x
!=
'metadata'
and
x
!=
"password"
]:
for
field
in
[
x
for
x
in
dir
(
o
)
if
not
x
.
startswith
(
'_'
)
and
x
!=
'metadata'
and
x
!=
"password"
]:
if
field
==
'books'
:
continue
data
=
o
.
__getattribute__
(
field
)
...
...
@@ -404,8 +404,11 @@ class AlchemyEncoder(json.JSONEncoder):
data
=
data
.
replace
(
"'"
,
"
\'
"
)
elif
isinstance
(
data
,
InstrumentedList
):
el
=
list
()
# ele = None
for
ele
in
data
:
if
ele
.
get
:
if
hasattr
(
ele
,
'value'
):
# converter for custom_column values
el
=
[
str
(
ele
.
value
)]
elif
ele
.
get
:
el
.
append
(
ele
.
get
())
else
:
el
.
append
(
json
.
dumps
(
ele
,
cls
=
AlchemyEncoder
))
...
...
cps/editbooks.py
View file @
9d5e9b28
...
...
@@ -573,10 +573,19 @@ def edit_cc_data_string(book, c, to_save, cc_db_value, cc_string):
getattr
(
book
,
cc_string
)
.
append
(
new_cc
)
return
changed
,
to_save
def
edit_single_cc_data
(
book_id
,
book
,
column_id
,
to_save
):
cc
=
(
calibre_db
.
session
.
query
(
db
.
Custom_Columns
)
.
filter
(
db
.
Custom_Columns
.
datatype
.
notin_
(
db
.
cc_exceptions
))
.
filter
(
db
.
Custom_Columns
.
id
==
column_id
)
.
all
())
return
edit_cc_data
(
book_id
,
book
,
to_save
,
cc
)
def
edit_all_cc_data
(
book_id
,
book
,
to_save
):
cc
=
calibre_db
.
session
.
query
(
db
.
Custom_Columns
)
.
filter
(
db
.
Custom_Columns
.
datatype
.
notin_
(
db
.
cc_exceptions
))
.
all
()
return
edit_cc_data
(
book_id
,
book
,
to_save
,
cc
)
def
edit_cc_data
(
book_id
,
book
,
to_save
):
def
edit_cc_data
(
book_id
,
book
,
to_save
,
cc
):
changed
=
False
cc
=
calibre_db
.
session
.
query
(
db
.
Custom_Columns
)
.
filter
(
db
.
Custom_Columns
.
datatype
.
notin_
(
db
.
cc_exceptions
))
.
all
()
for
c
in
cc
:
cc_string
=
"custom_column_"
+
str
(
c
.
id
)
if
not
c
.
is_multiple
:
...
...
@@ -811,7 +820,7 @@ def edit_book(book_id):
# handle book ratings
modif_date
|=
edit_book_ratings
(
to_save
,
book
)
# handle cc data
modif_date
|=
edit_cc_data
(
book_id
,
book
,
to_save
)
modif_date
|=
edit_
all_
cc_data
(
book_id
,
book
,
to_save
)
if
to_save
[
"pubdate"
]:
try
:
...
...
@@ -1131,10 +1140,6 @@ def edit_list_book(param):
lang_names
=
list
()
for
lang
in
book
.
languages
:
lang_names
.
append
(
isoLanguages
.
get_language_name
(
get_locale
(),
lang
.
lang_code
))
#try:
# lang_names.append(LC.parse(lang.lang_code).get_language_name(get_locale()))
#except UnknownLocaleError:
# lang_names.append(_(isoLanguages.get(part3=lang.lang_code).name))
ret
=
Response
(
json
.
dumps
({
'success'
:
True
,
'newValue'
:
', '
.
join
(
lang_names
)}),
mimetype
=
'application/json'
)
elif
param
==
'author_sort'
:
...
...
@@ -1157,6 +1162,13 @@ def edit_list_book(param):
ret
=
Response
(
json
.
dumps
({
'success'
:
True
,
'newValue'
:
' & '
.
join
([
author
.
replace
(
'|'
,
','
)
for
author
in
input_authors
])}),
mimetype
=
'application/json'
)
elif
param
.
startswith
(
"custom_column_"
):
new_val
=
dict
()
new_val
[
param
]
=
vals
[
'value'
]
edit_single_cc_data
(
book
.
id
,
book
,
param
[
14
:],
new_val
)
ret
=
Response
(
json
.
dumps
({
'success'
:
True
,
'newValue'
:
vals
[
'value'
]}),
mimetype
=
'application/json'
)
book
.
last_modified
=
datetime
.
utcnow
()
try
:
calibre_db
.
session
.
commit
()
...
...
cps/static/js/table.js
View file @
9d5e9b28
...
...
@@ -639,6 +639,10 @@ function singlecheckboxFormatter(value, row){
return
'<input type="checkbox" class="chk" data-pk="'
+
row
.
id
+
'" data-name="'
+
this
.
field
+
'" onchange="checkboxChange(this, '
+
row
.
id
+
',
\'
'
+
this
.
name
+
'
\'
, 0)">'
;
}
function
ratingFormatter
(
value
,
row
)
{
return
(
value
/
2
);
}
/* Do some hiding disabling after user list is loaded */
function
loadSuccess
()
{
...
...
cps/templates/book_table.html
View file @
9d5e9b28
...
...
@@ -59,6 +59,17 @@
{{ text_table_row('languages', _('Enter Languages'),_('Languages'), false, true) }}
<!--th data-field="pubdate" data-type="date" data-visible="{{visiblility.get('pubdate')}}" data-viewformat="dd.mm.yyyy" id="pubdate" data-sortable="true">{{_('Publishing Date')}}</th-->
{{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false, true) }}
{% for c in cc %}
{% if c.datatype == "int" %}
<th
data-field=
"custom_column_{{ c.id|string }}"
id=
"custom_column_{{ c.id|string }}"
data-visible=
"{{visiblility.get('custom_column_'+ c.id|string)}}"
data-sortable=
"false"
{%
if
g
.
user
.
role_edit
()
%}
data-editable-type=
"number"
data-editable-placeholder=
"1"
data-editable-step=
"1"
data-editable-url=
"{{ url_for('editbook.edit_list_book', param='custom_column_'+ c.id|string)}}"
data-edit=
"true"
data-editable-title=
"{{_('Enter ') + c.name}}"
{%
endif
%}
>
{{c.name}}
</th>
{% elif c.datatype == "rating" %}
<th
data-field=
"custom_column_{{ c.id|string }}"
id=
"custom_column_{{ c.id|string }}"
data-formatter=
"ratingFormatter"
data-visible=
"{{visiblility.get('custom_column_'+ c.id|string)}}"
data-sortable=
"false"
{%
if
g
.
user
.
role_edit
()
%}
data-editable-type=
"number"
data-editable-placeholder=
"1"
data-editable-step=
"1"
data-editable-min=
"0"
data-editable-max=
"10"
data-editable-url=
"{{ url_for('editbook.edit_list_book', param='custom_column_'+ c.id|string)}}"
data-edit=
"true"
data-editable-title=
"{{_('Enter ') + c.name}}"
{%
endif
%}
>
{{c.name}}
</th>
{% elif c.datatype == "float" %}
<th
data-field=
"custom_column_{{ c.id|string }}"
id=
"custom_column_{{ c.id|string }}"
data-visible=
"{{visiblility.get('custom_column_'+ c.id|string)}}"
data-sortable=
"false"
{%
if
g
.
user
.
role_edit
()
%}
data-editable-type=
"number"
data-editable-placeholder=
"1"
data-editable-step=
"0.01"
data-editable-url=
"{{ url_for('editbook.edit_list_book', param='custom_column_'+ c.id|string)}}"
data-edit=
"true"
data-editable-title=
"{{_('Enter ') + c.name}}"
{%
endif
%}
>
{{c.name}}
</th>
{% else %}
<!--{{ text_table_row('custom_column_' + c.id|string, _('Enter ') + c.name, c.name, false, false) }} -->
{% endif %}
{% endfor %}
{% if g.user.role_delete_books() and g.user.role_edit()%}
<th
data-align=
"right"
data-formatter=
"EbookActions"
data-switchable=
"false"
>
{{_('Delete')}}
</th>
{% endif %}
...
...
cps/web.py
View file @
9d5e9b28
...
...
@@ -765,7 +765,8 @@ def books_list(data, sort_param, book_id, page):
@
login_required
def
books_table
():
visibility
=
current_user
.
view_settings
.
get
(
'table'
,
{})
return
render_title_template
(
'book_table.html'
,
title
=
_
(
u"Books List"
),
page
=
"book_table"
,
cc
=
get_cc_columns
(
filter_config_custom_read
=
True
)
return
render_title_template
(
'book_table.html'
,
title
=
_
(
u"Books List"
),
cc
=
cc
,
page
=
"book_table"
,
visiblility
=
visibility
)
@
web
.
route
(
"/ajax/listbooks"
)
...
...
@@ -822,12 +823,6 @@ def list_books():
for
index
in
range
(
0
,
len
(
entry
.
languages
)):
entry
.
languages
[
index
]
.
language_name
=
isoLanguages
.
get_language_name
(
get_locale
(),
entry
.
languages
[
index
]
.
lang_code
)
#try:
# entry.languages[index].language_name = LC.parse(entry.languages[index].lang_code)\
# .get_language_name(get_locale())
#except UnknownLocaleError:
# entry.languages[index].language_name = _(
# isoLanguages.get(part3=entry.languages[index].lang_code).name)
table_entries
=
{
'totalNotFiltered'
:
total_count
,
'total'
:
filtered_count
,
"rows"
:
entries
}
js_list
=
json
.
dumps
(
table_entries
,
cls
=
db
.
AlchemyEncoder
)
...
...
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