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
c18d5786
Commit
c18d5786
authored
Jun 12, 2020
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved validation check
parent
f26ccfe1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
82 additions
and
36 deletions
+82
-36
db.py
cps/db.py
+1
-1
editbooks.py
cps/editbooks.py
+26
-5
table.js
cps/static/js/table.js
+41
-4
book_table.html
cps/templates/book_table.html
+9
-26
web.py
cps/web.py
+5
-0
No files found.
cps/db.py
View file @
c18d5786
...
...
@@ -294,7 +294,7 @@ class Data(Base):
class
Books
(
Base
):
__tablename__
=
'books'
DEFAULT_PUBDATE
=
"0101-01-01 00:00:00+00:00"
DEFAULT_PUBDATE
=
datetime
(
101
,
1
,
1
,
0
,
0
,
0
,
0
)
# ("0101-01-01 00:00:00+00:00")
id
=
Column
(
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
title
=
Column
(
String
(
collation
=
'NOCASE'
),
nullable
=
False
,
default
=
'Unknown'
)
...
...
cps/editbooks.py
View file @
c18d5786
...
...
@@ -911,20 +911,41 @@ def edit_list_book(param):
book
.
author_sort
=
vals
[
'value'
]
elif
param
==
'title'
:
book
.
title
=
vals
[
'value'
]
helper
.
update_dir_stucture
(
book
.
id
,
config
.
config_calibre_dir
)
elif
param
==
'sort'
:
book
.
sort
=
vals
[
'value'
]
# ToDo: edit books
elif
param
==
'authors'
:
edit_book_languages
(
vals
[
'value'
],
book
)
input_authors
=
vals
[
'value'
]
.
split
(
'&'
)
input_authors
=
list
(
map
(
lambda
it
:
it
.
strip
()
.
replace
(
','
,
'|'
),
input_authors
))
modify_database_object
(
input_authors
,
book
.
authors
,
db
.
Authors
,
calibre_db
.
session
,
'author'
)
sort_authors_list
=
list
()
for
inp
in
input_authors
:
stored_author
=
calibre_db
.
session
.
query
(
db
.
Authors
)
.
filter
(
db
.
Authors
.
name
==
inp
)
.
first
()
if
not
stored_author
:
stored_author
=
helper
.
get_sorted_author
(
inp
)
else
:
stored_author
=
stored_author
.
sort
sort_authors_list
.
append
(
helper
.
get_sorted_author
(
stored_author
))
sort_authors
=
' & '
.
join
(
sort_authors_list
)
if
book
.
author_sort
!=
sort_authors
:
book
.
author_sort
=
sort_authors
helper
.
update_dir_stucture
(
book
.
id
,
config
.
config_calibre_dir
,
input_authors
[
0
])
book
.
last_modified
=
datetime
.
utcnow
()
calibre_db
.
session
.
commit
()
return
""
@
editbook
.
route
(
"/ajax/sort_value"
)
@
editbook
.
route
(
"/ajax/sort_value
/<field>/<int:bookid>
"
)
@
login_required
def
get_sorted_entry
():
pass
def
get_sorted_entry
(
field
,
bookid
):
if
field
==
'title'
or
field
==
'authors'
:
book
=
calibre_db
.
get_filtered_book
(
bookid
)
if
book
:
if
field
==
'title'
:
return
json
.
dumps
({
'sort'
:
book
.
sort
})
elif
field
==
'authors'
:
return
json
.
dumps
({
'author_sort'
:
book
.
author_sort
})
return
''
@
editbook
.
route
(
"/ajax/deletebooks"
)
@
login_required
...
...
cps/static/js/table.js
View file @
c18d5786
...
...
@@ -76,12 +76,14 @@ $(function() {
}
column
.
push
(
element
);
});
$
(
"#books-table"
).
bootstrapTable
({
sidePagination
:
"server"
,
pagination
:
true
,
paginationDetailHAlign
:
" hidden"
,
paginationHAlign
:
"left"
,
idField
:
"id"
,
uniqueId
:
"id"
,
search
:
true
,
showColumns
:
true
,
searchAlign
:
"left"
,
...
...
@@ -94,8 +96,47 @@ $(function() {
formatNoMatches
:
function
()
{
return
""
;
},
onEditableSave
:
function
(
field
,
row
,
oldvalue
,
$el
)
{
if
(
field
===
'title'
||
field
===
'authors'
)
{
$
.
ajax
({
method
:
"get"
,
dataType
:
"json"
,
url
:
window
.
location
.
pathname
+
"/../../ajax/sort_value/"
+
field
+
'/'
+
row
.
id
,
success
:
function
success
(
data
)
{
var
key
=
Object
.
keys
(
data
)[
0
]
$
(
"#books-table"
).
bootstrapTable
(
'updateCellByUniqueId'
,
{
id
:
row
.
id
,
field
:
key
,
value
:
data
[
key
]
})
console
.
log
(
data
);
}
});
}
},
onColumnSwitch
:
function
(
field
,
checked
)
{
var
visible
=
$
(
"#books-table"
).
bootstrapTable
(
'getVisibleColumns'
);
var
hidden
=
$
(
"#books-table"
).
bootstrapTable
(
'getHiddenColumns'
);
$
.
ajax
({
method
:
"post"
,
contentType
:
"application/json; charset=utf-8"
,
dataType
:
"json"
,
url
:
window
.
location
.
pathname
+
"/../../ajax/table_settings"
,
data
:
JSON
.
stringify
({
"Merge_books"
:
selections
}),
success
:
function
success
()
{
// ToDo:
}
});
}
});
// to save current setting
// coresponding event: onColumnSwitch
//$table.bootstrapTable('getVisibleColumns')
//$table.bootstrapTable('getHiddenColumns').
$
(
"#domain_allow_submit"
).
click
(
function
(
event
)
{
event
.
preventDefault
();
$
(
"#domain_add_allow"
).
ajaxForm
();
...
...
@@ -194,10 +235,6 @@ $(function() {
<div id="flash_success" class="alert alert-success">{{ message[1] }}</div>
</div>*/
// to save current setting
// coresponding event: onColumnSwitch
//$table.bootstrapTable('getVisibleColumns')
//$table.bootstrapTable('getHiddenColumns').
$
(
"#restrictModal"
).
on
(
"hidden.bs.modal"
,
function
()
{
// Destroy table and remove hooks for buttons
...
...
cps/templates/book_table.html
View file @
c18d5786
...
...
@@ -17,27 +17,10 @@
{% endblock %}
{% block body %}
<h2
class=
"{{page}}"
>
{{_(title)}}
</h2>
<!--table id="table1"></table-->
<!--a href="{{url_for('editbook.merge_list_book')}}" class="btn btn-default disabled" id="merge_book" role="button" aria-disabled="true">{{_('Merge selected books')}}
data-side-pagination="server"
data-pagination="true"
data-pagination-detail-h-align=" hidden"
data-pagination-h-align="left"
id="books-table"
data-id-field="id"
data-editable-mode="inline"
data-show-columns="true"
data-search="true"
data-search-align="left"
data-show-search-button="false"
data-search-on-enter-key="true"
data-checkbox-header="false"
data-maintain-meta-data="true"
data-response-handler="responseHandler"
data-editable-emptytext="<span class='glyphicon glyphicon-plus'></span>"
</a-->
<div
class=
"btn btn-default disabled"
id=
"merge_books"
aria-disabled=
"true"
>
{{_('Merge selected books')}}
</div>
<div
class=
"btn btn-default"
id=
"delete_selection"
aria-disabled=
"false"
>
{{_('Remove Selections')}}
</div>
<div
class=
"btn btn-default"
id=
"autoupdate_titlesort"
aria-disabled=
"false"
>
{{_('Update Title Sort automatically')}}
</div>
<div
class=
"btn btn-default"
id=
"autoupdate_autorsort"
aria-disabled=
"false"
>
{{_('Update Author Sort automatically')}}
</div>
<table
id=
"books-table"
class=
"table table-no-bordered table-striped"
data-url=
"{{url_for('web.list_books')}}"
>
<thead>
...
...
@@ -47,14 +30,14 @@
{% endif %}
<th
data-field=
"id"
id=
"id"
data-visible=
"false"
data-switchable=
"false"
></th>
{{ text_table_row('title', _('Enter Title'),_('Title'), true) }}
{{ text_table_row('sort', _('Enter Title
sort'),_('
Sort'), false) }}
{{ text_table_row('author_sort', _('Enter Author
sort'),_('Authors
Sort'), false) }}
{{ text_table_row('authors', _('Enter Authors'),_('Authors'),
fals
e) }}
{{ text_table_row('tags', _('Enter
Tags'),_('Tag
s'), false) }}
{{ text_table_row('sort', _('Enter Title
Sort'),_('Title
Sort'), false) }}
{{ text_table_row('author_sort', _('Enter Author
Sort'),_('Author
Sort'), false) }}
{{ text_table_row('authors', _('Enter Authors'),_('Authors'),
tru
e) }}
{{ text_table_row('tags', _('Enter
Categories'),_('Categorie
s'), false) }}
{{ text_table_row('series', _('Enter Series'),_('Series'), false) }}
<th
data-field=
"series_index"
id=
"series_index"
data-
sortable=
"true"
{%
if
g
.
user
.
role_edit
() %}
data-editable-type=
"number"
data-editable-placeholder=
"1"
data-editable-step=
"0.01"
data-editable-min=
"0"
data-editable-url=
"{{ url_for('editbook.edit_list_book', param='series_index')}}"
data-editable
=
"true"
data-editable-title=
"{{_('Enter title')}}"
{%
endif
%}
>
{{_('Series Index')}}
</th>
<th
data-field=
"series_index"
id=
"series_index"
data-
edit-validate=
"{{ _('This Field is Required') }}"
data-sortable=
"true"
{%
if
g
.
user
.
role_edit
() %}
data-editable-type=
"number"
data-editable-placeholder=
"1"
data-editable-step=
"0.01"
data-editable-min=
"0"
data-editable-url=
"{{ url_for('editbook.edit_list_book', param='series_index')}}"
data-edit
=
"true"
data-editable-title=
"{{_('Enter title')}}"
{%
endif
%}
>
{{_('Series Index')}}
</th>
{{ text_table_row('languages', _('Enter Languages'),_('Languages'), false) }}
<th
data-field=
"pubdate"
data-type=
"date"
data-viewformat=
"dd.mm.yyyy"
id=
"pubdate"
data-sortable=
"true"
>
_('Publishing Date')
</th>
<th
data-field=
"pubdate"
data-type=
"date"
data-viewformat=
"dd.mm.yyyy"
id=
"pubdate"
data-sortable=
"true"
>
{{_('Publishing Date')}}
</th>
{{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false) }}
{% if g.user.role_edit() %}
<th
data-align=
"right"
data-formatter=
"EbookActions"
data-switchable=
"false"
></th>
...
...
cps/web.py
View file @
c18d5786
...
...
@@ -865,6 +865,11 @@ def list_books():
response
.
headers
[
"Content-Type"
]
=
"application/json; charset=utf-8"
return
response
@
web
.
route
(
"/ajax/table_settings"
)
@
login_required
def
update_table_settings
():
# ToDo: Save table settings
pass
@
web
.
route
(
"/author"
)
@
login_required_if_no_ano
...
...
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