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
02e5e6b0
Commit
02e5e6b0
authored
Jan 05, 2012
by
stef
Browse files
[enh] added /csv output\nnot linked from anywhere yet
parent
2c86529b
Changes
3
Hide whitespace changes
Inline
Side-by-side
bt/views.py
View file @
02e5e6b0
from
forms
import
AddViolation
,
SearchViolation
from
django.http
import
HttpResponse
,
HttpResponseRedirect
,
Http404
from
django.shortcuts
import
render_to_response
,
get_object_or_404
from
django.template
import
RequestContext
from
django.template
import
RequestContext
,
loader
,
Context
from
django.core.files
import
File
from
django.core.servers.basehttp
import
FileWrapper
from
django.conf
import
settings
...
...
@@ -228,7 +228,7 @@ def filter_violations(request, country, operator=None):
def
list_violations
(
request
):
violations
=
Violation
.
objects
.
filter
(
activationid
=
''
)
countries
=
sorted
([(
i
[
'total'
],
i
[
'country'
])
for
i
in
Violation
.
objects
.
values
(
'country'
).
filter
(
activationid
=
''
).
exclude
(
state
=
[
'duplicate'
,
'ooscope'
]).
annotate
(
total
=
Count
(
'country'
))],
for
i
in
Violation
.
objects
.
values
(
'country'
).
filter
(
activationid
=
''
).
exclude
(
state
=
[
'duplicate'
,
'ooscope'
,
'closed'
]).
annotate
(
total
=
Count
(
'country'
))],
reverse
=
True
)
legend
=
sorted
(
set
([(
w
,
"rgba(255,%d, 00, 0.4)"
%
(
w
*
768
/
(
countries
[
0
][
0
]
+
1
)
%
256
))
for
w
,
c
in
countries
]),
reverse
=
True
)
countrycolors
=
json
.
dumps
(
dict
([(
c
.
lower
(),
"#ff%02x00"
%
(
w
*
768
/
(
countries
[
0
][
0
]
+
1
)
%
256
))
for
w
,
c
in
countries
]))
...
...
@@ -293,3 +293,17 @@ def lookup(request):
res
=
json
.
dumps
(
sorted
([(
x
.
id
,
x
.
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'
res
=
[]
for
v
in
Violation
.
objects
.
filter
(
activationid
=
''
):
res
.
append
((
v
.
state
,
v
.
country
,
v
.
operator
,
v
.
contract
,
v
.
resource
,
v
.
resource_name
,
v
.
type
,
v
.
media
,
v
.
temporary
,
v
.
contractual
,
v
.
contract_excerpt
,
v
.
loophole
,
v
.
editorial
,
v
.
comment_set
.
get
().
comment
))
t
=
loader
.
get_template
(
'csv.tmpl'
)
c
=
Context
({
'data'
:
res
,
})
response
.
write
(
t
.
render
(
c
))
return
response
templates/csv.tmpl
0 → 100644
View file @
02e5e6b0
{% for row in data %}{% for col in row %}"{{ col|addslashes }}"{% if not loop.last %},{% endif %}{% endfor %}
{% endfor %}
urls.py
View file @
02e5e6b0
...
...
@@ -17,6 +17,7 @@ urlpatterns = patterns('',
(
r
'^view/(?P<id>[0-9]*)$'
,
bt
.
view
),
(
r
'^attach/(?P<id>[0-9]*)$'
,
bt
.
get_attach
),
(
r
'^(?P<id>[0-9]*)$'
,
bt
.
view
),
(
r
'^csv$'
,
bt
.
ascsv
),
(
r
'^rss/$'
,
RssSiteNewsFeed
()),
(
r
'^atom/$'
,
AtomSiteNewsFeed
()),
(
r
'^activate/$'
,
bt
.
activate
),
...
...
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