Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds survey feedback csv output management command
- Loading branch information
1 parent
9440c80
commit 21e67cb
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import csv | ||
import sys | ||
|
||
from django.core.management.base import BaseCommand | ||
import schools.models as schools_models | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Get a CSV of survey feedback' | ||
|
||
def handle(self, *args, **options): | ||
headers = ['name', 'created_at', 'type', 'feedback'] | ||
writer = csv.DictWriter(sys.stdout, fieldnames=headers) | ||
writer.writeheader() | ||
for profile in schools_models.SchoolProfile.objects.select_related('school').order_by('school__name','-created_at'): | ||
row = { | ||
'name': profile.school.name, | ||
'created_at': profile.created_at, | ||
'type': profile.school.type, | ||
'feedback': profile.survey_feedback, | ||
} | ||
writer.writerow(row) |