Skip to content
GitLab
Menu
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
066d1d85
Commit
066d1d85
authored
Feb 15, 2016
by
Okhin
Browse files
Soem work done on the ListViews #22
parent
33b7d8ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
bt/views.py
View file @
066d1d85
...
...
@@ -221,12 +221,19 @@ class ViolationsList(ListView):
def
get_queryset
(
self
):
queryset
=
Violation
.
objects
.
filter
(
activationid
=
''
)
if
'all'
not
in
self
.
request
.
GET
:
queryset
=
queryset
.
exclude
(
state__in
=
[
'duplicate'
,
'closed'
])
if
'country'
in
self
.
kwargs
:
queryset
=
queryset
.
filter
(
country
=
self
.
kwargs
[
'country'
])
if
'operator'
in
self
.
kwargs
:
queryset
=
queryset
.
filter
(
operator_ref__name
=
self
.
kwargs
[
'operator'
])
# If i Have operator I have a country
queryset
=
Violation
.
objects
.
filter
(
activationid
=
''
,
country
=
self
.
kwargs
[
'country'
],
operator_ref__name
=
self
.
kwargs
[
'operator'
])
elif
'country'
in
self
.
kwargs
:
queryset
=
Violation
.
objects
.
filter
(
activationid
=
''
,
country
=
self
.
kwargs
[
'country'
])
if
not
queryset
.
count
():
queryset
=
queryset
.
filter
(
activationid
=
''
,
operator_ref__name
=
self
.
kwargs
[
'country'
])
if
'all'
not
in
self
.
request
.
GET
:
queryset
=
queryset
.
objects
.
filter
(
activationid
=
''
).
exclude
(
state__in
=
[
'duplicate'
,
'closed'
])
return
queryset
def
get_context_data
(
self
,
**
kwargs
):
...
...
@@ -234,13 +241,13 @@ class ViolationsList(ListView):
if
'country'
in
self
.
kwargs
:
context
[
'country'
]
=
self
.
kwargs
[
'country'
]
countries
=
sorted
([(
i
[
'total'
],
i
[
'country'
])
for
i
in
Violation
.
objects
.
values
(
'country'
).
filter
(
activationid
=
''
).
exclude
(
state__in
=
[
'duplicate'
,
'closed'
]).
annotate
(
total
=
Count
(
'country'
))],
reverse
=
True
)
countryweights
=
json
.
dumps
([{
'iso2'
:
y
,
'w'
:
x
}
for
x
,
y
in
countries
])
context
[
'countries'
]
=
countries
context
[
'countryweights'
]
=
countryweights
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'
))],
reverse
=
True
)
countryweights
=
json
.
dumps
([{
'iso2'
:
y
,
'w'
:
x
}
for
x
,
y
in
countries
])
context
[
'countries'
]
=
countries
context
[
'countryweights'
]
=
countryweights
return
context
class
ViolationView
(
DetailView
):
...
...
nnmon/templates/list.html
View file @
066d1d85
...
...
@@ -122,5 +122,4 @@
{% endfor %}
</tbody>
</table>
</div>
{%endblock%}
Write
Preview
Supports
Markdown
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