gaetk2.modelexporter module¶
This module provides functionality to write datastore Models or Queries to the client as XLS or CSV Files. Usage like this in your handler:
exporter = ModelExporter(ic_AuftragsPosition)
filename = '%s-%s.xls' % (compat.xdb_kind(ic_AuftragsPosition), datetime.datetime.now())
handler.response.headers['Content-Type'] = 'application/msexcel'
handler.response.headers['content-disposition'] = \
'attachment; filename=%s' % filename
exporter.to_xls(handler.response)
# or:
# exporter.to_csv(handler.response)
Module contents¶
-
class
gaetk2.modelexporter.
ModelExporter
(model, query=None, uid=u'', only=None, ignore=None, additional_fields=None, maxseconds=40)[source]¶ Bases:
object
Export all entities of a Model as XLS, CSV.
Parameters: - model (ndb.Model) – Model to be exported, required.
- query (ndb.Query or None) – Query to limit the records to be exported.
- uid (str) – Encodes the person doing the Export in the Output.
- only (list(str) or None) – List of Field-/Propertynames to export
- ignore (list(str) or None) – List of Field-/Propertynames not to export
- additional_fields (list(str) or None) – The priority of the message, can be a number 1-5
- maxseconds (int) – Truncate exporting after this many seconds.
Intatiate a
ModelExporter
and callto_xls()
orto_csv()
to get an export of the Entities on Disk.ModelExporter
can also be used to create a automated tabular HTML view like in the admin interfave or in the ListViewer.-
fields
¶ Property with list of files to export.
Can be overwritten. Current implementation is cached.
-
create_header
(output, fixer=<function <lambda>>)[source]¶ Generates one or more header rows in output.
Can be overwritten.
-
create_row
(output, data, fixer=<function <lambda>>)[source]¶ Generates a single output row.
Can be overwritten.
-
create_csvwriter
(fileobj)[source]¶ Generates an outputstream from fileobj.
Can be overwritten to change the
csv.writer
csv.writer options.
-
to_csv
(fileobj)[source]¶ Generate CSV in fileobj.
Overwrite
create_csvwriter()
to change CSV Style.