3333
3434
3535class ExcelInput (object ):
36- """A generic interface for an excel file to be converted
36+ """A generic interface for an excel file input
3737
3838 The source could be from anywhere, memory or file system
3939 """
@@ -133,6 +133,15 @@ def save_to_database(
133133 auto_commit = True ,
134134 sheet_name = None , name_columns_by_row = 0 , name_rows_by_column = - 1 ,
135135 field_name = None , ** keywords ):
136+ """
137+ Save data from a sheet to database
138+
139+ :param session: a SQLAlchemy session
140+ :param table: a database table
141+ :param initializer: a custom table initialization function if you have one
142+ :param mapdict: the explicit table column names if your excel data do not have the exact column names
143+ :param keywords: additional keywords to :meth:`pyexcel.Sheet.save_to_database`
144+ """
136145 sheet = self .load_single_sheet (
137146 field_name = field_name ,
138147 sheet_name = sheet_name ,
@@ -171,6 +180,16 @@ def save_book_to_database(
171180 session = None , tables = None ,
172181 initializers = None , mapdicts = None , auto_commit = True ,
173182 ** keywords ):
183+ """
184+ Save a book into database
185+
186+ :param session: a SQLAlchemy session
187+ :param tables: a list of database tables
188+ :param initializers: a list of model initialization functions.
189+ :param mapdicts: a list of explicit table column names if your excel data sheets do not have the exact column names
190+ :param keywords: additional keywords to :meth:`pyexcel.Book.save_to_database`
191+
192+ """
174193 book = self .load_book (** keywords )
175194 if book :
176195 book .save_to_database (session ,
@@ -184,9 +203,18 @@ class ExcelInputInMultiDict(ExcelInput):
184203 """ A generic interface for an upload excel file appearing in a dictionary
185204 """
186205 def get_file_tuple (self , field_name ):
206+ """
207+ Abstract method to get the file tuple
208+
209+ It is expected to return file type and a file handle to the
210+ uploaded file
211+ """
187212 raise NotImplementedError ("Please implement this function" )
188213
189214 def load_single_sheet (self , field_name = None , sheet_name = None , ** keywords ):
215+ """
216+ Load the single sheet from named form field
217+ """
190218 file_type , file_handle = self .get_file_tuple (field_name )
191219 if file_type is not None and file_handle is not None :
192220 return pe .get_sheet (file_type = file_type ,
@@ -197,6 +225,9 @@ def load_single_sheet(self, field_name=None, sheet_name=None, **keywords):
197225 return None
198226
199227 def load_book (self , field_name = None , ** keywords ):
228+ """
229+ Load the book from named form field
230+ """
200231 file_type , file_handle = self .get_file_tuple (field_name )
201232 if file_type is not None and file_handle is not None :
202233 return pe .get_book (file_type = file_type ,
@@ -231,6 +262,7 @@ def make_response(pyexcel_instance, file_type, status=200, **keywords):
231262 * 'ods'
232263
233264 :param status: unless a different status is to be returned.
265+ :returns: http response
234266 """
235267 io = pe .get_io (file_type )
236268 pyexcel_instance .save_to_memory (file_type , io , ** keywords )
@@ -243,46 +275,108 @@ def make_response(pyexcel_instance, file_type, status=200, **keywords):
243275def make_response_from_array (array ,
244276 file_type , status = 200 ,
245277 ** keywords ):
278+ """
279+ Make a http response from an array
280+
281+ :param array: a list of lists
282+ :param file_type: same as :meth:`~pyexcel_webio.make_response`
283+ :param status: same as :meth:`~pyexcel_webio.make_response`
284+ :returns: http response
285+ """
246286 return make_response (pe .Sheet (array ),
247287 file_type , status , ** keywords )
248288
249289
250290def make_response_from_dict (adict ,
251291 file_type , status = 200 ,
252292 ** keywords ):
293+ """
294+ Make a http response from a dictionary of lists
295+
296+ :param dict: a dictinary of lists
297+ :param file_type: same as :meth:`~pyexcel_webio.make_response`
298+ :param status: same as :meth:`~pyexcel_webio.make_response`
299+ :returns: http response
300+ """
253301 return make_response (pe .load_from_dict (adict ),
254302 file_type , status , ** keywords )
255303
256304
257305def make_response_from_records (records ,
258306 file_type , status = 200 ,
259307 ** keywords ):
308+ """
309+ Make a http response from a list of dictionaries
310+
311+ :param records: a list of dictionaries
312+ :param file_type: same as :meth:`~pyexcel_webio.make_response`
313+ :param status: same as :meth:`~pyexcel_webio.make_response`
314+ :returns: http response
315+ """
260316 return make_response (pe .load_from_records (records ),
261317 file_type , status , ** keywords )
262318
263319
264320def make_response_from_book_dict (adict ,
265321 file_type , status = 200 ,
266322 ** keywords ):
323+ """
324+ Make a http response from a dictionary of two dimensional
325+ arrays
326+
327+ :param book_dict: a dictionary of two dimensional arrays
328+ :param file_type: same as :meth:`~pyexcel_webio.make_response`
329+ :param status: same as :meth:`~pyexcel_webio.make_response`
330+ :returns: http response
331+ """
267332 return make_response (pe .Book (adict ), file_type , status , ** keywords )
268333
269334
270335def make_response_from_query_sets (query_sets , column_names ,
271336 file_type , status = 200 ,
272337 ** keywords ):
338+ """
339+ Make a http response from a dictionary of two dimensional
340+ arrays
341+
342+ :param query_sets: a query set
343+ :param column_names: a nominated column names. It could not be N
344+ one, otherwise no data is returned.
345+ :param file_type: same as :meth:`~pyexcel_webio.make_response`
346+ :param status: same as :meth:`~pyexcel_webio.make_response`
347+ :returns: a http response
348+ """
273349 sheet = pe .get_sheet (query_sets = query_sets , column_names = column_names )
274350 return make_response (sheet , file_type , status , ** keywords )
275351
276352
277353def make_response_from_a_table (session , table ,
278354 file_type , status = 200 ,
279355 ** keywords ):
356+ """
357+ Make a http response from sqlalchmey table
358+
359+ :param session: SQLAlchemy session
360+ :param table: a SQLAlchemy table
361+ :param file_type: same as :meth:`~pyexcel_webio.make_response`
362+ :param status: same as :meth:`~pyexcel_webio.make_response`
363+ :returns: a http response
364+ """
280365 sheet = pe .get_sheet (session = session , table = table , ** keywords )
281366 return make_response (sheet , file_type , status , ** keywords )
282367
283368
284369def make_response_from_tables (session , tables ,
285370 file_type , status = 200 ,
286371 ** keywords ):
372+ """
373+ Make a http response from sqlalchmy tables
374+
375+ :param session: SQLAlchemy session
376+ :param tables: SQLAlchemy tables
377+ :param file_type: same as :meth:`~pyexcel_webio.make_response`
378+ :param status: same as :meth:`~pyexcel_webio.make_response`
379+ :returns: a http response
380+ """
287381 book = pe .get_book (session = session , tables = tables , ** keywords )
288382 return make_response (book , file_type , status , ** keywords )
0 commit comments