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
db70e475
Commit
db70e475
authored
May 22, 2016
by
Jan B
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #18 from cervinko/feature-advanced-search
add advanced search
parents
1e2a6f2f
c26eb6aa
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
119 additions
and
4 deletions
+119
-4
style.css
cps/static/css/style.css
+6
-0
layout.html
cps/templates/layout.html
+2
-1
search_form.html
cps/templates/search_form.html
+61
-0
web.py
cps/web.py
+50
-3
No files found.
cps/static/css/style.css
View file @
db70e475
...
...
@@ -31,3 +31,9 @@ span.glyphicon.glyphicon-tags {padding-right: 5px;color: #999;vertical-align: te
.btn-file
{
position
:
relative
;
overflow
:
hidden
;}
.btn-file
input
[
type
=
file
]
{
position
:
absolute
;
top
:
0
;
right
:
0
;
min-width
:
100%
;
min-height
:
100%
;
font-size
:
100px
;
text-align
:
right
;
filter
:
alpha
(
opacity
=
0
);
opacity
:
0
;
outline
:
none
;
background
:
white
;
cursor
:
inherit
;
display
:
block
;}
.btn-toolbar
.btn
{
margin-bottom
:
5px
;
}
.btn-primary
:hover
,
.btn-primary
:focus
,
.btn-primary
:active
,
.btn-primary.active
,
.open
.dropdown-toggle.btn-primary
{
background-color
:
#1C5484
;
}
.btn-primary.disabled
,
.btn-primary
[
disabled
],
fieldset
[
disabled
]
.btn-primary
,
.btn-primary.disabled
:hover
,
.btn-primary
[
disabled
]
:hover
,
fieldset
[
disabled
]
.btn-primary
:hover
,
.btn-primary.disabled
:focus
,
.btn-primary
[
disabled
]
:focus
,
fieldset
[
disabled
]
.btn-primary
:focus
,
.btn-primary.disabled
:active
,
.btn-primary
[
disabled
]
:active
,
fieldset
[
disabled
]
.btn-primary
:active
,
.btn-primary.disabled.active
,
.btn-primary
[
disabled
]
.active
,
fieldset
[
disabled
]
.btn-primary.active
{
background-color
:
#89B9E2
;
}
.btn-toolbar
>
.btn
+
.btn
,
.btn-toolbar
>
.btn-group
+
.btn
,
.btn-toolbar
>
.btn
+
.btn-group
,
.btn-toolbar
>
.btn-group
+
.btn-group
{
margin-left
:
0px
;
}
cps/templates/layout.html
View file @
db70e475
...
...
@@ -57,9 +57,10 @@
<div
class=
"form-group"
>
<input
type=
"text"
class=
"form-control"
name=
"query"
placeholder=
"Search"
>
</div>
<button
type=
"submit"
class=
"btn btn-default"
>
Submit
</button>
<button
type=
"submit"
class=
"btn btn-default"
>
Go!
</button>
</form>
</li>
<li><a
href=
"{{url_for('advanced_search')}}"
><span
class=
"glyphicon glyphicon-search"
></span>
Advanced Search
</a></li>
</ul>
<ul
class=
"nav navbar-nav navbar-right"
id=
"main-nav"
>
{% if g.user.is_authenticated() %}
...
...
cps/templates/search_form.html
0 → 100644
View file @
db70e475
{% extends "layout.html" %}
{% block body %}
<div
class=
"col-sm-8"
>
<form
role=
"form"
action=
"{{ url_for('advanced_search') }}"
method=
"GET"
>
<div
class=
"form-group"
>
<label
for=
"book_title"
>
Book Title
</label>
<input
type=
"text"
class=
"form-control"
name=
"book_title"
id=
"book_title"
value=
""
>
</div>
<div
class=
"form-group"
>
<label
for=
"bookAuthor"
>
Author
</label>
<input
type=
"text"
class=
"form-control typeahead"
name=
"author_name"
id=
"bookAuthor"
value=
""
autocomplete=
"off"
>
</div>
<label
for=
"Tags"
>
Include Tags
</label>
<div
class=
"form-group"
>
<div
class=
"btn-toolbar btn-toolbar-lg"
data-toggle=
"buttons"
>
{% for tag in tags %}
<label
id=
"tag_{{tag.id}}"
class=
"btn btn-primary tags_click"
>
<input
type=
"checkbox"
autocomplete=
"off"
name=
"include_tag"
value=
"{{tag.id}}"
>
{{tag.name}}
</input>
</label>
{% endfor %}
</div>
</div>
<label
for=
"Tags"
>
Exclude Tags
</label>
<div
class=
"form-group"
>
<div
class=
"btn-toolbar btn-toolbar-lg"
data-toggle=
"buttons"
>
{% for tag in tags %}
<label
id=
"tag_{{tag.id}}"
class=
"btn btn-danger tags_click"
>
<input
type=
"checkbox"
autocomplete=
"off"
name=
"exclude_tag"
value=
"{{tag.id}}"
>
{{tag.name}}
</input>
</label>
{% endfor %}
</div>
</div>
<button
type=
"submit"
class=
"btn btn-default"
>
Submit
</button>
</form>
</div>
{% endblock %}
{% block js %}
<script
src=
"{{ url_for('static', filename='js/typeahead.bundle.js') }}"
></script>
<script
src=
"{{ url_for('static', filename='js/edit_books.js') }}"
></script>
<script>
$
(
'form'
).
on
(
'change input typeahead:selected'
,
function
()
{
form
=
$
(
'form'
).
serialize
();
$
.
getJSON
(
"{{ url_for('get_matching_tags') }}"
,
form
,
function
(
data
)
{
$
(
'.tags_click'
).
each
(
function
()
{
if
(
$
.
inArray
(
parseInt
(
$
(
this
).
children
(
'input'
).
first
().
val
(),
10
),
data
.
tags
)
==
-
1
)
{
if
(
!
(
$
(
this
).
hasClass
(
'active'
)))
{
$
(
this
).
addClass
(
'disabled'
);
}
}
else
{
$
(
this
).
removeClass
(
'disabled'
);
}
});
});
});
</script>
{% endblock %}
{% block header %}
<link
href=
"{{ url_for('static', filename='css/typeahead.css') }}"
rel=
"stylesheet"
media=
"screen"
>
{% endblock %}
cps/web.py
View file @
db70e475
...
...
@@ -318,6 +318,30 @@ def get_series_json():
entries
=
db
.
session
.
execute
(
"select name from series where name like '
%
"
+
query
+
"
%
'"
)
json_dumps
=
json
.
dumps
([
dict
(
r
)
for
r
in
entries
])
return
json_dumps
@
app
.
route
(
"/get_matching_tags"
,
methods
=
[
'GET'
,
'POST'
])
@
login_required_if_no_ano
def
get_matching_tags
():
tag_dict
=
{
'tags'
:
[]}
if
request
.
method
==
"GET"
:
q
=
db
.
session
.
query
(
db
.
Books
)
author_input
=
request
.
args
.
get
(
'author_name'
)
title_input
=
request
.
args
.
get
(
'book_title'
)
include_tag_inputs
=
request
.
args
.
getlist
(
'include_tag'
)
exclude_tag_inputs
=
request
.
args
.
getlist
(
'exclude_tag'
)
q
=
q
.
filter
(
db
.
Books
.
authors
.
any
(
db
.
Authors
.
name
.
like
(
"
%
"
+
author_input
+
"
%
"
)),
db
.
Books
.
title
.
like
(
"
%
"
+
title_input
+
"
%
"
))
if
len
(
include_tag_inputs
)
>
0
:
for
tag
in
include_tag_inputs
:
q
=
q
.
filter
(
db
.
Books
.
tags
.
any
(
db
.
Tags
.
id
==
tag
))
if
len
(
exclude_tag_inputs
)
>
0
:
for
tag
in
exclude_tag_inputs
:
q
=
q
.
filter
(
not_
(
db
.
Books
.
tags
.
any
(
db
.
Tags
.
id
==
tag
)))
for
book
in
q
:
for
tag
in
book
.
tags
:
if
tag
.
id
not
in
tag_dict
[
'tags'
]:
tag_dict
[
'tags'
]
.
append
(
tag
.
id
)
json_dumps
=
json
.
dumps
(
tag_dict
)
return
json_dumps
@
app
.
route
(
"/"
,
defaults
=
{
'page'
:
1
})
@
app
.
route
(
'/page/<int:page>'
)
...
...
@@ -421,6 +445,32 @@ def search():
return
render_template
(
'search.html'
,
searchterm
=
term
,
entries
=
entries
)
else
:
return
render_template
(
'search.html'
,
searchterm
=
""
)
@
app
.
route
(
"/advanced_search"
,
methods
=
[
"GET"
])
@
login_required_if_no_ano
def
advanced_search
():
if
request
.
method
==
'GET'
:
q
=
db
.
session
.
query
(
db
.
Books
)
include_tag_inputs
=
request
.
args
.
getlist
(
'include_tag'
)
exclude_tag_inputs
=
request
.
args
.
getlist
(
'exclude_tag'
)
author_name
=
request
.
args
.
get
(
"author_name"
)
book_title
=
request
.
args
.
get
(
"book_title"
)
if
include_tag_inputs
or
exclude_tag_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
))
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
)))
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
)
@
app
.
route
(
"/author"
)
@
login_required_if_no_ano
...
...
@@ -920,7 +970,6 @@ def edit_book(book_id):
if
len
(
book
.
ratings
)
>
0
:
old_rating
=
book
.
ratings
[
0
]
.
rating
ratingx2
=
int
(
float
(
to_save
[
"rating"
])
*
2
)
print
ratingx2
if
ratingx2
!=
old_rating
:
is_rating
=
db
.
session
.
query
(
db
.
Ratings
)
.
filter
(
db
.
Ratings
.
rating
==
ratingx2
)
.
first
()
if
is_rating
:
...
...
@@ -945,7 +994,6 @@ def edit_book(book_id):
if
to_save
[
cc_string
]
.
strip
():
if
c
.
datatype
==
'rating'
:
to_save
[
cc_string
]
=
str
(
int
(
float
(
to_save
[
cc_string
])
*
2
))
print
to_save
[
cc_string
]
if
to_save
[
cc_string
]
.
strip
()
!=
cc_db_value
:
if
cc_db_value
!=
None
:
#remove old cc_val
...
...
@@ -1008,7 +1056,6 @@ def edit_book(book_id):
new_tag
=
db
.
session
.
query
(
db
.
cc_classes
[
c
.
id
])
.
filter
(
db
.
cc_classes
[
c
.
id
]
.
value
==
add_tag
)
.
first
()
# if no tag is found add it
if
new_tag
==
None
:
print
add_tag
new_tag
=
db
.
cc_classes
[
c
.
id
](
value
=
add_tag
)
db
.
session
.
add
(
new_tag
)
new_tag
=
db
.
session
.
query
(
db
.
cc_classes
[
c
.
id
])
.
filter
(
db
.
cc_classes
[
c
.
id
]
.
value
==
add_tag
)
.
first
()
...
...
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