-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_to_CSV.py
26 lines (23 loc) · 970 Bytes
/
export_to_CSV.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
import csv
from django.core.management.base import BaseCommmand
from django.http import HttpResponse
from django.db import models
import datetime
class Exportcommand(BaseCommand):
help = "Allows for the exporting of event/task data in CSV format"
def __init__(self)
def task_export
from django.models import task
csv_met = {
'file': '/tmp/{event}-export'datetime.datetime.now() ,
'class': task,
'attributes': ('summary', 'description','time_estimate_minutes'}
self._format_csv(csv_met)
def _format_csv(self, csv_met):
f = open(csv_met['file'], 'w')
writer = csv.writer(f,
writer.writerow(csv_met['Task Name', 'Task Description', 'Time Estimate'])
for obj in csv_met['class'].objects.all():
row = getattr(obj,field) for field in csv_met['attributes']
writer.writerow(row)
f.close