-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv_parse.py
30 lines (24 loc) · 935 Bytes
/
csv_parse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from scheduler.models import Mission, NextPass
from django.http import HttpResponse
from django.utils.encoding import smart_str
import csv
def export_csv(request):
queryset = NextPass.objects.all().order_by("riseTime")
response = HttpResponse(content_type='text/csv') #should probs be REST response
response['Content-Disposition'] = 'attachment; filename="schedule.csv"'
writer = csv.writer(response, csv.excel)
response.write(u'\ufeff'.encode('utf8')) # To open UTF-8 properly
writer.writerow([
smart_str(u"Name"),
smart_str(u"Rise Time"),
smart_str(u"Set Time"),
smart_str(u"Duration"),
])
for object in queryset:
writer.writerow([
smart_str(object.tle.name),
smart_str(object.riseTime),
smart_str(object.setTime),
smart_str(object.duration),
])
return response