Skip to content

Commit

Permalink
enhancement: sheet could be none and model could be none
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed Jun 8, 2015
1 parent cd6ec48 commit 18a256c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions pyexcel_io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,9 @@ def write(self, sheet_dicts):
keys = sheet_dicts.keys()
for name in keys:
sheet = self.create_sheet(name)
sheet.write_array(sheet_dicts[name])
sheet.close()
if sheet is not None:
sheet.write_array(sheet_dicts[name])
sheet.close()

@abstractmethod
def close(self):
Expand Down
7 changes: 5 additions & 2 deletions pyexcel_io/djangobook.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ def __init__(self, file, models=None, batch_size=None, **keywords):
self.batch_size = batch_size

def create_sheet(self, name):
model_params = self.models[name]
return DjangoModelWriter(model_params, batch_size=self.batch_size)
if name in self.models:
model_params = self.models[name]
return DjangoModelWriter(model_params, batch_size=self.batch_size)
else:
return None

def close(self):
pass

0 comments on commit 18a256c

Please sign in to comment.