Skip to content

Commit

Permalink
Update generic to get filename
Browse files Browse the repository at this point in the history
  • Loading branch information
valdergallo committed Jan 20, 2015
1 parent 49270b1 commit 4d494d0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions data_importer/importers/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ def get_source_file_extension(self):
"""
Gets the source file extension. Used to choose the right reader
"""
if isinstance(self.source, str):
filename = self.source
if hasattr(self.source, 'file'):
filename = self.source.file.name # DataImporter.FileHistory instances
elif hasattr(self.source, 'file_upload'):
filename = self.source.file_upload.name # Default Python opened file
elif hasattr(self.source, 'name'):
filename = self.source.name
else:
try:
filename = self.source.file.name # DataImporter.FileHistory instances
except AttributeError:
filename = self.source.name # Default Python opened file
filename = self.source

ext = filename.split('.')[-1]
return ext.lower()

0 comments on commit 4d494d0

Please sign in to comment.