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
35c12500
Commit
35c12500
authored
Feb 15, 2016
by
Okhin
Browse files
Fixing the per country and operator listings #22
parent
65fc14c8
Changes
2
Hide whitespace changes
Inline
Side-by-side
bt/views.py
View file @
35c12500
...
...
@@ -144,7 +144,11 @@ def sendverifymail(service,to,body):
class
JSONMixin
(
object
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
return
HttpResponse
(
serializers
.
serialize
(
'json'
,
self
.
get_queryset
()))
qs
=
self
.
get_queryset
()
if
qs
.
count
():
return
HttpResponse
(
json
.
dumps
(
sorted
([(
x
.
object
.
id
,
x
.
object
.
resource_name
)
for
x
in
qs
])))
else
:
return
HttpResponse
(
''
)
class
AddForm
(
FormView
):
model
=
Violation
...
...
@@ -215,7 +219,6 @@ class AddForm(FormView):
return
context
class
ViolationsList
(
ListView
):
queryset
=
Violation
.
objects
.
filter
(
activationid
=
''
)
template_name
=
'list.html'
context_object_name
=
'violations'
...
...
@@ -226,12 +229,9 @@ class ViolationsList(ListView):
queryset
=
Violation
.
objects
.
filter
(
activationid
=
''
,
country
=
self
.
kwargs
[
'country'
],
operator_ref__name
=
self
.
kwargs
[
'operator'
])
el
if
'country'
in
self
.
kwargs
:
if
'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
.
filter
(
activationid
=
''
).
exclude
(
state__in
=
[
'duplicate'
,
'closed'
])
return
queryset
...
...
@@ -262,6 +262,10 @@ class ViolationView(DetailView):
raise
Http404
return
object
class
LookupView
(
JSONMixin
,
SearchView
):
queryset
=
Violation
.
objects
.
filter
(
activationid
=
''
)
form_class
=
SearchViolation
def
get_attach
(
request
,
id
):
f
=
get_object_or_404
(
Attachment
,
pk
=
id
)
wrapper
=
FileWrapper
(
f
.
storage
)
...
...
@@ -270,19 +274,6 @@ def get_attach(request,id):
response
[
'Content-Length'
]
=
f
.
storage
.
size
return
response
class
LookupView
(
JSONMixin
,
SearchView
):
model
=
Violation
form_class
=
SearchViolation
#def lookup(request):
# if request.method == 'GET':
# form = SearchViolation(request.GET)
# if form.is_valid():
# v=form.search()
# res=json.dumps(sorted([(x.object.id,x.object.resource_name) for x in v],reverse=True))
# return HttpResponse(res)
# return HttpResponse('')
def
ascsv
(
request
):
response
=
HttpResponse
(
mimetype
=
'text/csv'
)
response
[
'Content-Disposition'
]
=
'attachment; filename=respectmynet.csv'
...
...
nnmon/urls.py
View file @
35c12500
...
...
@@ -19,9 +19,12 @@ urlpatterns = patterns('',
url
(
r
'^list/$'
,
view
=
bt
.
ViolationsList
.
as_view
(),
name
=
"list_violations"
),
url
(
r
'^list/(?P<country>
[^/]*)(/(?P<operator>[^/]*))?
/$'
,
url
(
r
'^list/(?P<country>
\w+)
/$'
,
view
=
bt
.
ViolationsList
.
as_view
(),
name
=
"filter"
),
name
=
"filter_country"
),
url
(
r
'^list/(?P<country>\w+)/(?P<operator>\w+)/$'
,
view
=
bt
.
ViolationsList
.
as_view
(),
name
=
"filter_operator"
),
# violation cannonical url and redirections
url
(
r
'^(?P<id>[0-9]*)$'
,
RedirectView
.
as_view
(
url
=
'/view/%(id)s'
)),
...
...
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