Commit a455714d authored by Okhin's avatar Okhin
Browse files

CSV exporting of data

parent 42b2939d
......@@ -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(mimetype='text/csv')
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename=respectmynet.csv'
res=[]
......
{% 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 %}
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment