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
a455714d
Commit
a455714d
authored
Mar 07, 2016
by
Okhin
Browse files
CSV exporting of data
parent
42b2939d
Changes
3
Hide whitespace changes
Inline
Side-by-side
bt/views.py
View file @
a455714d
...
...
@@ -295,8 +295,20 @@ def get_attach(request,id):
response
[
'Content-Length'
]
=
f
.
storage
.
size
return
response
class
ViolationCsvList
(
ListView
):
model
=
Violation
template_name
=
'csv.tmpl'
content_type
=
'text/csv'
csv_name
=
'respectmynet.csv'
queryset
=
Violation
.
objects
.
all
().
annotate
(
confirmations
=
Count
(
'confirmation'
)).
order_by
(
'-confirmations'
)
def
render_to_response
(
self
,
context
,
**
kwargs
):
response
=
super
(
ListView
,
self
).
render_to_response
(
context
,
**
kwargs
)
response
[
'Content-Disposition'
]
=
'attachment; filename={0}'
.
format
(
self
.
csv_name
)
return
response
def
ascsv
(
request
):
response
=
HttpResponse
(
mime
type
=
'text/csv'
)
response
=
HttpResponse
(
content_
type
=
'text/csv'
)
response
[
'Content-Disposition'
]
=
'attachment; filename=respectmynet.csv'
res
=
[]
...
...
nnmon/templates/csv.tmpl
View file @
a455714d
{% for row in data %}{% for col in row %}"{{ col|safe|addslashes }}"{% if not loop.last %},{% endif %}{% endfor %}
{% endfor %}
"Confirmations","Country","Operator","Contract","Resource","Resource Name","Type","Media","Temporary","Contractual","Contract Excerpt","Loophole","State","Old","Creation Date"
{% autoescape off %} {% for violation in object_list %} "{{ violation.confirmations }}", "{{ violation.country }}", "{{ violation.operator }}", "{{ violation.contract|addslashes }}", "{{ violation.resource|addslashes }}", "{{ violation.resource_name|striptags|addslashes }}", "{{ violation.type|addslashes }}", "{{ violation.media|addslashes }}", "{{ violation.temporary }}", "{{ violation.contractual }}", "{{ violation.contract_excerpt|striptags|addslashes }}", "{{ violation.loophole }}", "{{ violation.state }}", "{{ violation.old }}", "{{ violation.creation_date|date:"DATE_FORMAT" }}"
{% endfor %} {% endautoescape %}
nnmon/urls.py
View file @
a455714d
...
...
@@ -36,7 +36,7 @@ urlpatterns = patterns('',
name
=
"attach"
),
# different data outputs
url
(
r
'^csv$'
,
view
=
bt
.
ascsv
,
view
=
bt
.
ViolationCsvList
.
as_view
()
,
name
=
"csv_output"
),
url
(
r
'^ods$'
,
view
=
bt
.
asods
,
...
...
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