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
016c7b4b
Commit
016c7b4b
authored
Sep 30, 2018
by
Virgil Grigoras
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to store and edit publishers
parent
2b9ab96f
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
8 deletions
+46
-8
db.py
cps/db.py
+1
-1
edit_books.js
cps/static/js/edit_books.js
+25
-0
book_edit.html
cps/templates/book_edit.html
+1
-1
web.py
cps/web.py
+19
-6
No files found.
cps/db.py
View file @
016c7b4b
...
@@ -211,7 +211,7 @@ class Publishers(Base):
...
@@ -211,7 +211,7 @@ class Publishers(Base):
name
=
Column
(
String
)
name
=
Column
(
String
)
sort
=
Column
(
String
)
sort
=
Column
(
String
)
def
__init__
(
self
,
name
,
sort
):
def
__init__
(
self
,
name
,
sort
=
"ASC"
):
self
.
name
=
name
self
.
name
=
name
self
.
sort
=
sort
self
.
sort
=
sort
...
...
cps/static/js/edit_books.js
View file @
016c7b4b
...
@@ -142,6 +142,17 @@ var languages = new Bloodhound({
...
@@ -142,6 +142,17 @@ var languages = new Bloodhound({
}
}
});
});
var
publishers
=
new
Bloodhound
({
name
:
"publisher"
,
datumTokenizer
:
function
datumTokenizer
(
datum
)
{
return
[
datum
.
name
];
},
queryTokenizer
:
Bloodhound
.
tokenizers
.
whitespace
,
remote
:
{
url
:
getPath
()
+
"/get_publishers_json?q=%QUERY"
}
});
function
sourceSplit
(
query
,
cb
,
split
,
source
)
{
function
sourceSplit
(
query
,
cb
,
split
,
source
)
{
var
bhAdapter
=
source
.
ttAdapter
();
var
bhAdapter
=
source
.
ttAdapter
();
...
@@ -224,6 +235,20 @@ promiseLanguages.done(function() {
...
@@ -224,6 +235,20 @@ promiseLanguages.done(function() {
);
);
});
});
var
promisePublishers
=
publishers
.
initialize
();
promisePublishers
.
done
(
function
()
{
$
(
"#publisher"
).
typeahead
(
{
highlight
:
true
,
minLength
:
0
,
hint
:
true
},
{
name
:
"publishers"
,
displayKey
:
"name"
,
source
:
publishers
.
ttAdapter
()
}
);
});
$
(
"#search"
).
on
(
"change input.typeahead:selected"
,
function
()
{
$
(
"#search"
).
on
(
"change input.typeahead:selected"
,
function
()
{
var
form
=
$
(
"form"
).
serialize
();
var
form
=
$
(
"form"
).
serialize
();
$
.
getJSON
(
getPath
()
+
"/get_matching_tags"
,
form
,
function
(
data
)
{
$
.
getJSON
(
getPath
()
+
"/get_matching_tags"
,
form
,
function
(
data
)
{
...
...
cps/templates/book_edit.html
View file @
016c7b4b
...
@@ -101,7 +101,7 @@
...
@@ -101,7 +101,7 @@
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"publisher"
>
{{_('Publisher')}}
</label>
<label
for=
"publisher"
>
{{_('Publisher')}}
</label>
<input
type=
"text"
class=
"form-control typeahead"
name=
"publisher"
id=
"publisher"
value=
"{% if book.publishers|length > 0 %}{{book.publishers[0].name}}{% endif %}"
disabled
>
<input
type=
"text"
class=
"form-control typeahead"
name=
"publisher"
id=
"publisher"
value=
"{% if book.publishers|length > 0 %}{{book.publishers[0].name}}{% endif %}"
>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"languages"
>
{{_('Language')}}
</label>
<label
for=
"languages"
>
{{_('Language')}}
</label>
...
...
cps/web.py
View file @
016c7b4b
...
@@ -532,6 +532,10 @@ def fill_indexpage(page, database, db_filter, order, *join):
...
@@ -532,6 +532,10 @@ def fill_indexpage(page, database, db_filter, order, *join):
# Modifies different Database objects, first check if elements have to be added to database, than check
# Modifies different Database objects, first check if elements have to be added to database, than check
# if elements have to be deleted, because they are no longer used
# if elements have to be deleted, because they are no longer used
def
modify_database_object
(
input_elements
,
db_book_object
,
db_object
,
db_session
,
db_type
):
def
modify_database_object
(
input_elements
,
db_book_object
,
db_object
,
db_session
,
db_type
):
# passing input_elements not as a list may lead to undesired results
if
type
(
input_elements
)
is
not
list
:
raise
TypeError
(
str
(
input_elements
)
+
" should be passed as a list"
)
input_elements
=
[
x
for
x
in
input_elements
if
x
!=
''
]
input_elements
=
[
x
for
x
in
input_elements
if
x
!=
''
]
# we have all input element (authors, series, tags) names now
# we have all input element (authors, series, tags) names now
# 1. search for elements to remove
# 1. search for elements to remove
...
@@ -1031,6 +1035,16 @@ def get_authors_json():
...
@@ -1031,6 +1035,16 @@ def get_authors_json():
return
json_dumps
return
json_dumps
@
app
.
route
(
"/get_publishers_json"
,
methods
=
[
'GET'
,
'POST'
])
@
login_required_if_no_ano
def
get_publishers_json
():
if
request
.
method
==
"GET"
:
query
=
request
.
args
.
get
(
'q'
)
entries
=
db
.
session
.
query
(
db
.
Publishers
)
.
filter
(
db
.
Publishers
.
name
.
ilike
(
"
%
"
+
query
+
"
%
"
))
.
all
()
json_dumps
=
json
.
dumps
([
dict
(
name
=
r
.
name
.
replace
(
'|'
,
','
))
for
r
in
entries
])
return
json_dumps
@
app
.
route
(
"/get_tags_json"
,
methods
=
[
'GET'
,
'POST'
])
@
app
.
route
(
"/get_tags_json"
,
methods
=
[
'GET'
,
'POST'
])
@
login_required_if_no_ano
@
login_required_if_no_ano
def
get_tags_json
():
def
get_tags_json
():
...
@@ -3549,11 +3563,10 @@ def edit_book(book_id):
...
@@ -3549,11 +3563,10 @@ def edit_book(book_id):
book
.
pubdate
=
db
.
Books
.
DEFAULT_PUBDATE
book
.
pubdate
=
db
.
Books
.
DEFAULT_PUBDATE
else
:
else
:
book
.
pubdate
=
db
.
Books
.
DEFAULT_PUBDATE
book
.
pubdate
=
db
.
Books
.
DEFAULT_PUBDATE
'''if len(book.publishers):
if to_save["publisher"] != book.publishers[0].name:
if
to_save
[
"publisher"
]:
modify_database_object(to_save["publisher"], book.publishers, db.Publishers, db.session, 'series')
if
len
(
book
.
publishers
)
==
0
or
(
len
(
book
.
publishers
)
>
0
and
to_save
[
"publisher"
]
!=
book
.
publishers
[
0
]
.
name
):
else:
modify_database_object
([
to_save
[
"publisher"
]],
book
.
publishers
,
db
.
Publishers
,
db
.
session
,
'publisher'
)
modify_database_object(to_save["publisher"], book.publishers, db.Publishers, db.session, 'series')'''
# handle book languages
# handle book languages
input_languages
=
to_save
[
"languages"
]
.
split
(
','
)
input_languages
=
to_save
[
"languages"
]
.
split
(
','
)
...
...
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