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
piks3l
Respect My Net
Commits
f564ffb9
Commit
f564ffb9
authored
Mar 01, 2016
by
Okhin
Browse files
No more old stuff in the result
parent
1c83df44
Changes
5
Show whitespace changes
Inline
Side-by-side
bt/migrations/0001_initial.pyc
View file @
f564ffb9
No preview for this file type
bt/migrations/0002_violation_old.pyc
View file @
f564ffb9
No preview for this file type
bt/migrations/0003_auto_20160301_2032.pyc
View file @
f564ffb9
No preview for this file type
bt/search_indexes.py
View file @
f564ffb9
...
...
@@ -10,6 +10,7 @@ class ViolationIndexes(indexes.SearchIndex, indexes.Indexable):
media
=
indexes
.
CharField
(
model_attr
=
"media"
)
operator_name
=
indexes
.
CharField
()
state
=
indexes
.
NgramField
(
model_attr
=
"state"
)
old
=
indexes
.
BooleanField
(
model_attr
=
"old"
)
def
get_model
(
self
):
return
Violation
...
...
bt/views.py
View file @
f564ffb9
...
...
@@ -192,25 +192,22 @@ class AddForm(FormView):
messages
.
add_message
(
request
,
messages
.
INFO
,
_
(
'Thank you for submitting this report, you will receive a verification email immediately, if not check your spam folder.'
))
return
super
(
AddForm
,
self
).
form_valid
(
form
)
def
get_queryset
(
self
):
return
Violation
.
objects
.
filter
(
activationid
=
''
,
featuredcase__isnull
=
False
).
order_by
(
'id'
).
reverse
()[:
3
]
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
AddForm
,
self
).
get_context_data
(
**
kwargs
)
reports
=
sorted
([(
i
[
'total'
],
i
[
'id'
])
for
i
in
Violation
.
objects
.
values
(
'id'
).
filter
(
activationid
=
''
).
exclude
(
state__in
=
[
'closed'
,
'ooscope'
,
'duplicate'
]).
annotate
(
total
=
Count
(
'confirmation'
))],
for
i
in
Violation
.
objects
.
values
(
'id'
).
filter
(
activationid
=
''
).
exclude
(
state__in
=
[
'closed'
,
'ooscope'
,
'duplicate'
]).
exclude
(
old
=
True
).
annotate
(
total
=
Count
(
'confirmation'
))],
reverse
=
True
)
confirms
=
sorted
([(
i
[
'total'
],
i
[
'country'
])
for
i
in
Violation
.
objects
.
values
(
'country'
).
filter
(
activationid
=
''
).
exclude
(
state__in
=
[
'closed'
,
'ooscope'
,
'duplicate'
]).
annotate
(
total
=
Count
(
'confirmation'
))],
for
i
in
Violation
.
objects
.
values
(
'country'
).
filter
(
activationid
=
''
).
exclude
(
state__in
=
[
'closed'
,
'ooscope'
,
'duplicate'
]).
exclude
(
old
=
True
).
annotate
(
total
=
Count
(
'confirmation'
))],
reverse
=
True
)
operators
=
sorted
([(
i
[
'total'
],
i
[
'operator_ref__name'
])
for
i
in
Violation
.
objects
.
values
(
'operator_ref__name'
).
filter
(
activationid
=
''
).
exclude
(
state__in
=
[
'closed'
,
'ooscope'
,
'duplicate'
]).
annotate
(
total
=
Count
(
'confirmation'
))],
for
i
in
Violation
.
objects
.
values
(
'operator_ref__name'
).
filter
(
activationid
=
''
).
exclude
(
state__in
=
[
'closed'
,
'ooscope'
,
'duplicate'
]).
exclude
(
old
=
True
).
annotate
(
total
=
Count
(
'confirmation'
))],
reverse
=
True
)
context
[
'stats'
]
=
[
(
_
(
'Total confirmed reports'
),
len
([
i
for
i
,
z
in
reports
if
i
>
0
])),
(
_
(
'Countries with some confirmed reports'
),
len
([
i
for
i
,
z
in
confirms
if
i
>
0
])),
(
_
(
'Operators with some confirmed reports'
),
len
([
i
for
i
,
z
in
operators
if
i
>
0
]))]
context
[
'violations'
]
=
[
fc
.
case
for
fc
in
FeaturedCase
.
objects
.
all
()]
context
[
'violations'
]
=
[
fc
.
case
for
fc
in
FeaturedCase
.
objects
.
all
()
if
not
fc
.
case
.
old
][:
3
]
return
context
class
ViolationsList
(
ListView
):
...
...
@@ -218,17 +215,17 @@ class ViolationsList(ListView):
context_object_name
=
'violations'
def
get_queryset
(
self
):
queryset
=
Violation
.
objects
.
filter
(
activationid
=
''
)
queryset
=
Violation
.
objects
.
filter
(
activationid
=
''
)
.
exclude
(
old
=
True
)
if
'operator'
in
self
.
kwargs
:
# If i Have operator I have a country
queryset
=
Violation
.
objects
.
filter
(
activationid
=
''
,
country
=
self
.
kwargs
[
'country'
],
operator_ref__name
=
self
.
kwargs
[
'operator'
])
operator_ref__name
=
self
.
kwargs
[
'operator'
])
.
exclude
(
old
=
True
)
if
'country'
in
self
.
kwargs
:
queryset
=
Violation
.
objects
.
filter
(
activationid
=
''
,
country
=
self
.
kwargs
[
'country'
])
country
=
self
.
kwargs
[
'country'
])
.
exclude
(
old
=
True
)
if
'all'
not
in
self
.
request
.
GET
:
queryset
=
queryset
.
filter
(
activationid
=
''
).
exclude
(
state__in
=
[
'duplicate'
,
'closed'
])
queryset
=
queryset
.
filter
(
activationid
=
''
).
exclude
(
state__in
=
[
'duplicate'
,
'closed'
])
.
exclude
(
old
=
False
)
return
queryset
def
get_context_data
(
self
,
**
kwargs
):
...
...
@@ -238,7 +235,7 @@ class ViolationsList(ListView):
context
[
'country'
]
=
self
.
kwargs
[
'country'
]
else
:
countries
=
sorted
([(
i
[
'total'
],
i
[
'country'
])
for
i
in
Violation
.
objects
.
values
(
'country'
).
filter
(
activationid
=
''
).
exclude
(
state__in
=
[
'duplicate'
,
'closed'
]).
annotate
(
total
=
Count
(
'country'
))],
for
i
in
Violation
.
objects
.
values
(
'country'
).
filter
(
activationid
=
''
).
exclude
(
state__in
=
[
'duplicate'
,
'closed'
]).
exclude
(
old
=
True
).
annotate
(
total
=
Count
(
'country'
))],
reverse
=
True
)
countryweights
=
json
.
dumps
([{
'iso2'
:
y
,
'w'
:
x
}
for
x
,
y
in
countries
])
context
[
'countries'
]
=
countries
...
...
@@ -258,11 +255,25 @@ class ViolationView(DetailView):
return
object
class
LookupView
(
SearchView
):
searchqueryset
=
SearchQuerySet
().
exclude
(
old
=
True
)
form_class
=
SearchViolation
def
get_queryset
(
self
):
return
super
(
LookupView
,
self
).
get_queryset
().
exclude
(
old
=
True
)
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
context
=
super
(
LookupView
,
self
).
get_context_data
(
*
args
,
**
kwargs
)
if
'object_list'
in
context
:
context
[
'object_list'
]
=
[
obj
for
obj
in
context
[
'object_list'
]
if
not
obj
.
object
.
old
]
return
context
class
ViolationSearchView
(
SearchView
):
searchqueryset
=
SearchQuerySet
().
exclude
(
old
=
True
)
form_class
=
SearchViolation
def
get_queryset
(
self
):
return
super
(
ViolationSearchView
,
self
).
get_queryset
().
exclude
(
old
=
True
)
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
context
=
super
(
ViolationSearchView
,
self
).
get_context_data
(
*
args
,
**
kwargs
)
countries
=
sorted
([(
k
,
len
(
list
(
g
)),)
for
k
,
g
in
groupby
(
sorted
([
i
[
'country'
]
for
i
in
self
.
queryset
.
values
(
'country'
)]))])
...
...
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