Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
Respect My Net
Commits
0ac46074
Commit
0ac46074
authored
Feb 18, 2016
by
Okhin
Browse files
Upgrading the search function
parent
435000e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
bt/search_indexes.py
View file @
0ac46074
...
@@ -7,6 +7,10 @@ class ViolationIndexes(indexes.SearchIndex, indexes.Indexable):
...
@@ -7,6 +7,10 @@ class ViolationIndexes(indexes.SearchIndex, indexes.Indexable):
country
=
indexes
.
CharField
(
model_attr
=
"country"
)
country
=
indexes
.
CharField
(
model_attr
=
"country"
)
contract
=
indexes
.
CharField
(
model_attr
=
"contract_excerpt"
)
contract
=
indexes
.
CharField
(
model_attr
=
"contract_excerpt"
)
type
=
indexes
.
BooleanField
(
model_attr
=
"contractual"
)
type
=
indexes
.
BooleanField
(
model_attr
=
"contractual"
)
operator_name
=
indexes
.
CharField
()
def
get_model
(
self
):
def
get_model
(
self
):
return
Violation
return
Violation
def
prepare_operator_name
(
self
,
obj
):
return
obj
.
operator_ref
.
name
bt/views.py
View file @
0ac46074
...
@@ -267,21 +267,18 @@ class LookupView(JSONMixin, SearchView):
...
@@ -267,21 +267,18 @@ class LookupView(JSONMixin, SearchView):
form_class
=
SearchViolation
form_class
=
SearchViolation
class
ViolationSearchView
(
SearchView
):
class
ViolationSearchView
(
SearchView
):
def
get_queryset
(
self
):
"""Let's strip the queryset form the non needed items."""
queryset
=
super
(
ViolationSearchView
,
self
).
get_queryset
()
return
queryset
.
filter
(
annotationid
=
''
).
exclude
(
state__in
=
[
'closed'
,
'ooscope'
,
'duplicate'
])
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
context
=
super
(
ViolationSearchView
,
self
).
get_context_data
(
*
args
,
**
kwargs
)
context
=
super
(
ViolationSearchView
,
self
).
get_context_data
(
*
args
,
**
kwargs
)
countries
=
[(
k
,
len
(
g
),)
for
k
,
g
in
groupby
(
sorted
([
i
[
'country'
]
for
i
in
self
.
queryset
.
values
(
'country'
)]))]
countries
=
sorted
(
[(
k
,
len
(
list
(
g
)
),)
for
k
,
g
in
groupby
(
sorted
([
i
[
'country'
]
for
i
in
self
.
queryset
.
values
(
'country'
)]))]
)
countryweights
=
json
.
dumps
([{
'iso2'
:
y
,
'w'
:
x
}
for
x
,
y
in
countries
])
countryweights
=
json
.
dumps
([{
'iso2'
:
y
,
'w'
:
x
}
for
x
,
y
in
countries
])
operators
=
sorted
([(
k
,
len
(
list
(
g
)),)
for
k
,
g
in
groupby
(
sorted
([
i
[
'operator_name'
]
for
i
in
self
.
queryset
.
values
(
'operator_name'
)]))])
context
[
'operators'
]
=
operators
context
[
'countries'
]
=
countries
context
[
'countries'
]
=
countries
context
[
'countryweights'
]
=
countryweights
context
[
'countryweights'
]
=
countryweights
context
[
'stats'
]
=
[
context
[
'stats'
]
=
[
(
_
(
'Number of reports in this search'
),
self
.
queryset
.
count
(
)),
(
_
(
'Number of reports in this search'
),
len
(
self
.
queryset
.
all
()
)),
(
_
(
'Countries with some confirmed reports'
),
self
.
queryset
.
values
(
'country'
).
count
(
)),
(
_
(
'Countries with some confirmed reports'
),
len
([
c
for
c
,
v
in
countries
if
v
>
0
]
)),
(
_
(
'Operators with some confirmed reports'
),
self
.
queryset
.
values
(
'operator_ref__name'
).
count
(
)),
(
_
(
'Operators with some confirmed reports'
),
len
([
c
for
c
,
v
in
operators
if
v
>
0
]
)),
]
]
return
context
return
context
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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