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
c26eb6aa
Commit
c26eb6aa
authored
May 03, 2016
by
Cervinko Cera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add exclude tags to advanced search
parent
80c3c19c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
12 deletions
+31
-12
search_form.html
cps/templates/search_form.html
+17
-5
web.py
cps/web.py
+14
-7
No files found.
cps/templates/search_form.html
View file @
c26eb6aa
...
@@ -10,12 +10,22 @@
...
@@ -10,12 +10,22 @@
<label
for=
"bookAuthor"
>
Author
</label>
<label
for=
"bookAuthor"
>
Author
</label>
<input
type=
"text"
class=
"form-control typeahead"
name=
"author_name"
id=
"bookAuthor"
value=
""
autocomplete=
"off"
>
<input
type=
"text"
class=
"form-control typeahead"
name=
"author_name"
id=
"bookAuthor"
value=
""
autocomplete=
"off"
>
</div>
</div>
<label
for=
"Tags"
>
Select
Tags
</label>
<label
for=
"Tags"
>
Include
Tags
</label>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<div
class=
"btn-toolbar btn-toolbar-lg"
data-toggle=
"buttons"
>
<div
class=
"btn-toolbar btn-toolbar-lg"
data-toggle=
"buttons"
>
{% for tag in tags %}
{% for tag in tags %}
<label
id=
"tag_{{tag.id}}"
class=
"btn btn-primary tag_click"
>
<label
id=
"tag_{{tag.id}}"
class=
"btn btn-primary tags_click"
>
<input
type=
"checkbox"
autocomplete=
"off"
name=
"tag"
value=
"{{tag.id}}"
>
{{tag.name}}
</input>
<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>
</label>
{% endfor %}
{% endfor %}
</div>
</div>
...
@@ -32,9 +42,11 @@
...
@@ -32,9 +42,11 @@
$
(
'form'
).
on
(
'change input typeahead:selected'
,
function
()
{
$
(
'form'
).
on
(
'change input typeahead:selected'
,
function
()
{
form
=
$
(
'form'
).
serialize
();
form
=
$
(
'form'
).
serialize
();
$
.
getJSON
(
"{{ url_for('get_matching_tags') }}"
,
form
,
function
(
data
)
{
$
.
getJSON
(
"{{ url_for('get_matching_tags') }}"
,
form
,
function
(
data
)
{
$
(
'.tag_click'
).
each
(
function
()
{
$
(
'.tag
s
_click'
).
each
(
function
()
{
if
(
$
.
inArray
(
parseInt
(
$
(
this
).
children
(
'input'
).
first
().
val
(),
10
),
data
.
tags
)
==
-
1
)
{
if
(
$
.
inArray
(
parseInt
(
$
(
this
).
children
(
'input'
).
first
().
val
(),
10
),
data
.
tags
)
==
-
1
)
{
$
(
this
).
addClass
(
'disabled'
);
if
(
!
(
$
(
this
).
hasClass
(
'active'
)))
{
$
(
this
).
addClass
(
'disabled'
);
}
}
}
else
{
else
{
$
(
this
).
removeClass
(
'disabled'
);
$
(
this
).
removeClass
(
'disabled'
);
...
...
cps/web.py
View file @
c26eb6aa
...
@@ -327,11 +327,15 @@ def get_matching_tags():
...
@@ -327,11 +327,15 @@ def get_matching_tags():
q
=
db
.
session
.
query
(
db
.
Books
)
q
=
db
.
session
.
query
(
db
.
Books
)
author_input
=
request
.
args
.
get
(
'author_name'
)
author_input
=
request
.
args
.
get
(
'author_name'
)
title_input
=
request
.
args
.
get
(
'book_title'
)
title_input
=
request
.
args
.
get
(
'book_title'
)
tag_inputs
=
request
.
args
.
getlist
(
'tag'
)
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
+
"
%
"
))
q
=
q
.
filter
(
db
.
Books
.
authors
.
any
(
db
.
Authors
.
name
.
like
(
"
%
"
+
author_input
+
"
%
"
)),
db
.
Books
.
title
.
like
(
"
%
"
+
title_input
+
"
%
"
))
if
len
(
tag_inputs
)
>
0
:
if
len
(
include_
tag_inputs
)
>
0
:
for
tag
in
tag_inputs
:
for
tag
in
include_
tag_inputs
:
q
=
q
.
filter
(
db
.
Books
.
tags
.
any
(
db
.
Tags
.
id
==
tag
))
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
book
in
q
:
for
tag
in
book
.
tags
:
for
tag
in
book
.
tags
:
if
tag
.
id
not
in
tag_dict
[
'tags'
]:
if
tag
.
id
not
in
tag_dict
[
'tags'
]:
...
@@ -447,19 +451,22 @@ def search():
...
@@ -447,19 +451,22 @@ def search():
def
advanced_search
():
def
advanced_search
():
if
request
.
method
==
'GET'
:
if
request
.
method
==
'GET'
:
q
=
db
.
session
.
query
(
db
.
Books
)
q
=
db
.
session
.
query
(
db
.
Books
)
tag_inputs
=
request
.
args
.
getlist
(
'tag'
)
include_tag_inputs
=
request
.
args
.
getlist
(
'include_tag'
)
exclude_tag_inputs
=
request
.
args
.
getlist
(
'exclude_tag'
)
author_name
=
request
.
args
.
get
(
"author_name"
)
author_name
=
request
.
args
.
get
(
"author_name"
)
book_title
=
request
.
args
.
get
(
"book_title"
)
book_title
=
request
.
args
.
get
(
"book_title"
)
if
tag_inputs
or
author_name
or
book_title
:
if
include_tag_inputs
or
exclude_
tag_inputs
or
author_name
or
book_title
:
searchterm
=
[]
searchterm
=
[]
searchterm
.
extend
((
author_name
,
book_title
))
searchterm
.
extend
((
author_name
,
book_title
))
tag_names
=
db
.
session
.
query
(
db
.
Tags
)
.
filter
(
db
.
Tags
.
id
.
in_
(
tag_inputs
))
.
all
()
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
.
extend
(
tag
.
name
for
tag
in
tag_names
)
searchterm
=
" + "
.
join
(
filter
(
None
,
searchterm
))
searchterm
=
" + "
.
join
(
filter
(
None
,
searchterm
))
q
=
q
.
filter
(
db
.
Books
.
authors
.
any
(
db
.
Authors
.
name
.
like
(
"
%
"
+
author_name
+
"
%
"
)),
db
.
Books
.
title
.
like
(
"
%
"
+
book_title
+
"
%
"
))
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
)
random
=
db
.
session
.
query
(
db
.
Books
)
.
order_by
(
func
.
random
())
.
limit
(
config
.
RANDOM_BOOKS
)
for
tag
in
tag_inputs
:
for
tag
in
include_
tag_inputs
:
q
=
q
.
filter
(
db
.
Books
.
tags
.
any
(
db
.
Tags
.
id
==
tag
))
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
()
q
=
q
.
all
()
return
render_template
(
'search.html'
,
searchterm
=
searchterm
,
entries
=
q
)
return
render_template
(
'search.html'
,
searchterm
=
searchterm
,
entries
=
q
)
tags
=
db
.
session
.
query
(
db
.
Tags
)
.
order_by
(
db
.
Tags
.
name
)
.
all
()
tags
=
db
.
session
.
query
(
db
.
Tags
)
.
order_by
(
db
.
Tags
.
name
)
.
all
()
...
...
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