question as csv
This commit is contained in:
@@ -62,13 +62,18 @@ class Quiz(AuthorAware, DateAware, PublishedAware):
|
||||
return self.pdfpath
|
||||
|
||||
def to_csv(self, fh=None):
|
||||
with open(self.csvpath, 'w') as cf:
|
||||
items = self.to_view()['items']
|
||||
keys = items[0].keys()
|
||||
dw = csv.DictWriter(cf, fieldnames=list(keys))
|
||||
dw.writeheader()
|
||||
dw.writerows(items)
|
||||
return self.csvpath
|
||||
if fh:
|
||||
cf = fh
|
||||
else:
|
||||
cf = open(self.csvpath, 'w')
|
||||
items = self.to_view()['items']
|
||||
keys = items[0].keys()
|
||||
dw = csv.DictWriter(cf, fieldnames=list(keys))
|
||||
dw.writeheader()
|
||||
dw.writerows(items)
|
||||
if not fh:
|
||||
cf.close()
|
||||
return cf if fh else self.csvpath
|
||||
|
||||
def to_zip(self, fh=None):
|
||||
with zipfile.ZipFile(self.zippath, 'w') as zf:
|
||||
|
||||
Reference in New Issue
Block a user