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
c33a329f
Commit
c33a329f
authored
Dec 27, 2016
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add search for series and languages (#56)
Add database migration for shelf ordering (#73)
parent
fac83a10
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
3 deletions
+88
-3
search_form.html
cps/templates/search_form.html
+42
-0
ub.py
cps/ub.py
+7
-0
web.py
cps/web.py
+39
-3
No files found.
cps/templates/search_form.html
View file @
c33a329f
...
...
@@ -30,6 +30,48 @@
{% endfor %}
</div>
</div>
<label
for=
"Series"
>
{{_('Series')}}
</label>
<div
class=
"form-group"
>
<div
class=
"btn-toolbar btn-toolbar-lg"
data-toggle=
"buttons"
>
{% for serie in series %}
<label
id=
"serie_{{serie.id}}"
class=
"btn btn-primary serie_click"
>
<input
type=
"checkbox"
autocomplete=
"off"
name=
"include_serie"
value=
"{{serie.id}}"
>
{{serie.name}}
</input>
</label>
{% endfor %}
</div>
</div>
<label
for=
"Tags"
>
{{_('Exclude Series')}}
</label>
<div
class=
"form-group"
>
<div
class=
"btn-toolbar btn-toolbar-lg"
data-toggle=
"buttons"
>
{% for serie in series %}
<label
id=
"serie_{{serie.id}}"
class=
"btn btn-danger serie_click"
>
<input
type=
"checkbox"
autocomplete=
"off"
name=
"exclude_serie"
value=
"{{serie.id}}"
>
{{serie.name}}
</input>
</label>
{% endfor %}
</div>
</div>
{% if languages %}
<label
for=
"Languages"
>
{{_('Languages')}}
</label>
<div
class=
"form-group"
>
<div
class=
"btn-toolbar btn-toolbar-lg"
data-toggle=
"buttons"
>
{% for language in languages %}
<label
id=
"language_{{language.id}}"
class=
"btn btn-primary serie_click"
>
<input
type=
"checkbox"
autocomplete=
"off"
name=
"include_language"
value=
"{{language.id}}"
>
{{language.name}}
</input>
</label>
{% endfor %}
</div>
</div>
<label
for=
"Languages"
>
{{_('Exclude Languages')}}
</label>
<div
class=
"form-group"
>
<div
class=
"btn-toolbar btn-toolbar-lg"
data-toggle=
"buttons"
>
{% for language in languages %}
<label
id=
"language_{{language.id}}"
class=
"btn btn-danger language_click"
>
<input
type=
"checkbox"
autocomplete=
"off"
name=
"exclude_language"
value=
"{{language.id}}"
>
{{language.name}}
</input>
</label>
{% endfor %}
</div>
</div>
{% endif%}
<button
type=
"submit"
class=
"btn btn-default"
>
{{_('Submit')}}
</button>
</form>
</div>
...
...
cps/ub.py
View file @
c33a329f
...
...
@@ -174,6 +174,13 @@ def migrate_Database():
conn
.
execute
(
"ALTER TABLE user ADD column category_books INTEGER DEFAULT 1"
)
conn
.
execute
(
"ALTER TABLE user ADD column hot_books INTEGER DEFAULT 1"
)
session
.
commit
()
try
:
session
.
query
(
exists
()
.
where
(
BookShelf
.
order
))
.
scalar
()
session
.
commit
()
except
exc
.
OperationalError
:
# Database is not compatible, some rows are missing
conn
=
engine
.
connect
()
conn
.
execute
(
"ALTER TABLE book_shelf_link ADD column order INTEGER DEFAULT 1"
)
session
.
commit
()
def
create_default_config
():
...
...
cps/web.py
View file @
c33a329f
...
...
@@ -969,29 +969,65 @@ def advanced_search():
q
=
db
.
session
.
query
(
db
.
Books
)
include_tag_inputs
=
request
.
args
.
getlist
(
'include_tag'
)
exclude_tag_inputs
=
request
.
args
.
getlist
(
'exclude_tag'
)
include_series_inputs
=
request
.
args
.
getlist
(
'include_serie'
)
exclude_series_inputs
=
request
.
args
.
getlist
(
'exclude_serie'
)
include_languages_inputs
=
request
.
args
.
getlist
(
'include_language'
)
exclude_languages_inputs
=
request
.
args
.
getlist
(
'exclude_language'
)
author_name
=
request
.
args
.
get
(
"author_name"
)
book_title
=
request
.
args
.
get
(
"book_title"
)
if
author_name
:
author_name
=
author_name
.
strip
()
if
book_title
:
book_title
=
book_title
.
strip
()
if
include_tag_inputs
or
exclude_tag_inputs
or
author_name
or
book_title
:
if
include_tag_inputs
or
exclude_tag_inputs
or
include_series_inputs
or
exclude_series_inputs
or
\
include_languages_inputs
or
exclude_languages_inputs
or
author_name
or
book_title
:
searchterm
=
[]
searchterm
.
extend
((
author_name
,
book_title
))
tag_names
=
db
.
session
.
query
(
db
.
Tags
)
.
filter
(
db
.
Tags
.
id
.
in_
(
include_tag_inputs
))
.
all
()
searchterm
.
extend
(
tag
.
name
for
tag
in
tag_names
)
# searchterm = " + ".join(filter(None, searchterm))
serie_names
=
db
.
session
.
query
(
db
.
Series
)
.
filter
(
db
.
Series
.
id
.
in_
(
include_series_inputs
))
.
all
()
searchterm
.
extend
(
serie
.
name
for
serie
in
serie_names
)
language_names
=
db
.
session
.
query
(
db
.
Languages
)
.
filter
(
db
.
Languages
.
id
.
in_
(
include_languages_inputs
))
.
all
()
for
lang
in
language_names
:
try
:
cur_l
=
LC
.
parse
(
lang
.
lang_code
)
lang
.
name
=
cur_l
.
get_language_name
(
get_locale
())
except
:
lang
.
name
=
_
(
isoLanguages
.
get
(
part3
=
lang
.
lang_code
)
.
name
)
searchterm
.
extend
(
language
.
name
for
language
in
language_names
)
searchterm
=
" + "
.
join
(
filter
(
None
,
searchterm
))
q
=
q
.
filter
(
db
.
Books
.
authors
.
any
(
db
.
Authors
.
name
.
like
(
"
%
"
+
author_name
+
"
%
"
)),
db
.
Books
.
title
.
like
(
"
%
"
+
book_title
+
"
%
"
))
# random = db.session.query(db.Books).order_by(func.random()).limit(config.RANDOM_BOOKS)
for
tag
in
include_tag_inputs
:
q
=
q
.
filter
(
db
.
Books
.
tags
.
any
(
db
.
Tags
.
id
==
tag
))
for
tag
in
exclude_tag_inputs
:
q
=
q
.
filter
(
not_
(
db
.
Books
.
tags
.
any
(
db
.
Tags
.
id
==
tag
)))
for
serie
in
include_series_inputs
:
q
=
q
.
filter
(
db
.
Books
.
series
.
any
(
db
.
Series
.
id
==
serie
))
for
serie
in
exclude_series_inputs
:
q
=
q
.
filter
(
not_
(
db
.
Books
.
series
.
any
(
db
.
Series
.
id
==
serie
)))
if
current_user
.
filter_language
()
!=
"all"
:
q
=
q
.
filter
(
db
.
Books
.
languages
.
any
(
db
.
Languages
.
lang_code
==
current_user
.
filter_language
()))
else
:
for
language
in
include_languages_inputs
:
q
=
q
.
filter
(
db
.
Books
.
languages
.
any
(
db
.
Languages
.
id
==
language
))
for
language
in
exclude_languages_inputs
:
q
=
q
.
filter
(
not_
(
db
.
Books
.
series
.
any
(
db
.
Languages
.
id
==
language
)))
q
=
q
.
all
()
return
render_template
(
'search.html'
,
searchterm
=
searchterm
,
entries
=
q
)
tags
=
db
.
session
.
query
(
db
.
Tags
)
.
order_by
(
db
.
Tags
.
name
)
.
all
()
return
render_template
(
'search_form.html'
,
tags
=
tags
)
series
=
db
.
session
.
query
(
db
.
Series
)
.
order_by
(
db
.
Series
.
name
)
.
all
()
if
current_user
.
filter_language
()
==
u"all"
:
languages
=
db
.
session
.
query
(
db
.
Languages
)
.
all
()
for
lang
in
languages
:
try
:
cur_l
=
LC
.
parse
(
lang
.
lang_code
)
lang
.
name
=
cur_l
.
get_language_name
(
get_locale
())
except
:
lang
.
name
=
_
(
isoLanguages
.
get
(
part3
=
lang
.
lang_code
)
.
name
)
else
:
languages
=
None
return
render_template
(
'search_form.html'
,
tags
=
tags
,
languages
=
languages
,
series
=
series
)
@
app
.
route
(
"/cover/<path:cover_path>"
)
...
...
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