1515else :
1616 from io import BytesIO
1717
18-
18+
1919FILE_TYPE_MIME_TABLE = {
2020 "csv" : "text/csv" ,
2121 "tsv" : "text/tab-separated-values" ,
@@ -35,7 +35,7 @@ class ExcelInput(object):
3535 """
3636 def load_single_sheet (self , sheet_name = None , ** keywords ):
3737 """Abstract method
38-
38+
3939 :param form_field_name: the file field name in the html form for file upload
4040 :param sheet_name: For an excel book, there could be multiple sheets. If it is left
4141 unspecified, the sheet at index 0 is loaded. For 'csv', 'tsv' file,
@@ -158,6 +158,33 @@ def save_book_to_database(self, session=None, tables=None, initializers=None, ma
158158 book .save_to_database (session , tables , initializers = initializers , mapdicts = mapdicts )
159159
160160
161+
162+ class ExcelInputInMultiDict (ExcelInput ):
163+ """ A generic interface for an upload excel file appearing in a dictionary
164+ """
165+ def get_file_tuple (self , field_name ):
166+ raise NotImplementedError ("Please implement this function" )
167+
168+ def load_single_sheet (self , field_name = None , sheet_name = None , ** keywords ):
169+ file_type , file_handle = self .get_file_tuple (field_name )
170+ if file_type is not None and file_handle is not None :
171+ return pe .get_sheet (file_type = file_type ,
172+ file_content = file_handle .read (),
173+ sheet_name = sheet_name ,
174+ ** keywords )
175+ else :
176+ return None
177+
178+ def load_book (self , field_name = None , ** keywords ):
179+ file_type , file_handle = self .get_file_tuple (field_name )
180+ if file_type is not None and file_handle is not None :
181+ return pe .get_book (file_type = file_type ,
182+ file_content = file_handle .read (),
183+ ** keywords )
184+ else :
185+ return None
186+
187+
161188def dummy_func (content , content_type = None , status = 200 ):
162189 return None
163190
@@ -216,4 +243,4 @@ def make_response_from_a_table(session, table, file_type, status=200, **keywords
216243
217244def make_response_from_tables (session , tables , file_type , status = 200 , ** keywords ):
218245 book = pe .get_book (session = session , tables = tables , ** keywords )
219- return make_response (book , file_type , status , ** keywords )
246+ return make_response (book , file_type , status , ** keywords )
0 commit comments