onadata.libs.renderers package¶
Submodules¶
onadata.libs.renderers.renderers module¶
Custom renderers for use with django rest_framework.
- class onadata.libs.renderers.renderers.CSVRenderer¶
Bases:
BaseRenderer
XLSRenderer - renders comma separated files (CSV) with text/csv.
- charset = 'utf-8'¶
- format = 'csv'¶
- media_type = 'text/csv'¶
- class onadata.libs.renderers.renderers.CSVZIPRenderer¶
Bases:
BaseRenderer
CSVZIPRenderer - renders a ZIP file that contains CSV files.
- charset = None¶
- format = 'csvzip'¶
- media_type = 'application/octet-stream'¶
- render(data, accepted_media_type=None, renderer_context=None)¶
- class onadata.libs.renderers.renderers.DebugToolbarRenderer¶
Bases:
TemplateHTMLRenderer
DebugToolbarRenderer - render .debug as HTML.
- charset = 'utf-8'¶
- format = 'debug'¶
- media_type = 'text/html'¶
- render(data, accepted_media_type=None, renderer_context=None)¶
Renders data to HTML, using Django’s standard template rendering.
The template name is determined by (in order of preference):
An explicit .template_name set on the response.
An explicit .template_name set on this class.
The return result of calling view.get_template_names().
- template_name = 'debug.html'¶
- class onadata.libs.renderers.renderers.DecimalEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)¶
Bases:
JSONEncoder
JSON DecimalEncoder that returns None for decimal nan json values.
- default(obj)¶
JSON DecimalEncoder that returns None for decimal nan json values.
- class onadata.libs.renderers.renderers.DecimalJSONRenderer¶
Bases:
JSONRenderer
Extends the default json renderer to handle Decimal(‘NaN’) values
- encoder_class¶
alias of
DecimalEncoder
- class onadata.libs.renderers.renderers.FLOIPRenderer¶
Bases:
JSONRenderer
FLOIP Results data renderer.
- charset = 'utf-8'¶
- format = 'json'¶
- media_type = 'application/vnd.org.flowinterop.results+json'¶
- render(data, accepted_media_type=None, renderer_context=None)¶
Render data into JSON, returning a bytestring.
- class onadata.libs.renderers.renderers.GeoJsonRenderer¶
Bases:
BaseRenderer
GeoJsonRenderer - render .geojson data as json.
- charset = 'utf-8'¶
- format = 'geojson'¶
- media_type = 'application/json'¶
- render(data, accepted_media_type=None, renderer_context=None)¶
- class onadata.libs.renderers.renderers.GoogleSheetsRenderer¶
Bases:
XLSRenderer
GoogleSheetsRenderer = Google Sheets excel exports.
- format = 'gsheets'¶
- class onadata.libs.renderers.renderers.InstanceXMLRenderer¶
Bases:
XMLRenderer
,StreamRendererMixin
InstanceXMLRenderer - Renders Instance XML
- item_tag_name = 'submission-item'¶
- render(data, accepted_media_type=None, renderer_context=None)¶
Renders data into serialized XML.
- root_tag_name = 'submission-batch'¶
- stream_data(data, serializer)¶
Returns a streaming response.
- class onadata.libs.renderers.renderers.KMLRenderer¶
Bases:
BaseRenderer
KMLRenderer - renders KML XML data.
- charset = 'utf-8'¶
- format = 'kml'¶
- media_type = 'application/xml'¶
- render(data, accepted_media_type=None, renderer_context=None)¶
- class onadata.libs.renderers.renderers.MediaFileContentNegotiation¶
Bases:
DefaultContentNegotiation
- MediaFileContentNegotiation - filters renders to only return renders with
matching format.
- filter_renderers(renderers, format)¶
If there is a ‘.json’ style format suffix, filter the renderers so that we only negotiation against those that accept that format. If there is no renderer available, we use MediaFileRenderer.
- class onadata.libs.renderers.renderers.MediaFileRenderer¶
Bases:
BaseRenderer
MediaFileRenderer - render binary media files.
- charset = None¶
- format = None¶
- media_type = '*/*'¶
- render(data, accepted_media_type=None, renderer_context=None)¶
- render_style = 'binary'¶
- class onadata.libs.renderers.renderers.OSMExportRenderer¶
Bases:
BaseRenderer
OSMExportRenderer - render .osm data as XML.
- charset = 'utf-8'¶
- format = 'osm'¶
- media_type = 'text/xml'¶
- class onadata.libs.renderers.renderers.OSMRenderer¶
Bases:
BaseRenderer
OSMRenderer - render .osm data as XML.
- charset = 'utf-8'¶
- format = 'osm'¶
- media_type = 'text/xml'¶
- render(data, accepted_media_type=None, renderer_context=None)¶
- class onadata.libs.renderers.renderers.SAVZIPRenderer¶
Bases:
BaseRenderer
SAVZIPRenderer - renders a ZIP file that contains SPSS SAV files.
- charset = None¶
- format = 'savzip'¶
- media_type = 'application/octet-stream'¶
- render(data, accepted_media_type=None, renderer_context=None)¶
- class onadata.libs.renderers.renderers.StaticXMLRenderer¶
Bases:
StaticHTMLRenderer
StaticXMLRenderer - render static XML document.
- format = 'xml'¶
- media_type = 'text/xml'¶
- class onadata.libs.renderers.renderers.StreamRendererMixin¶
Bases:
object
Mixin class for renderers that support stream responses
- stream_data(data, serializer)¶
Returns a streaming response.
- class onadata.libs.renderers.renderers.SurveyRenderer¶
Bases:
BaseRenderer
SurveyRenderer - renders XML data.
- charset = 'utf-8'¶
- format = 'xml'¶
- media_type = 'application/xml'¶
- render(data, accepted_media_type=None, renderer_context=None)¶
- class onadata.libs.renderers.renderers.TemplateXMLRenderer¶
Bases:
TemplateHTMLRenderer
TemplateXMLRenderer - Render XML template.
- format = 'xml'¶
- media_type = 'text/xml'¶
- render(data, accepted_media_type=None, renderer_context=None)¶
Renders data to HTML, using Django’s standard template rendering.
The template name is determined by (in order of preference):
An explicit .template_name set on the response.
An explicit .template_name set on this class.
The return result of calling view.get_template_names().
- class onadata.libs.renderers.renderers.XFormListRenderer¶
Bases:
BaseRenderer
Renderer which serializes to XML.
- charset = 'utf-8'¶
- element_node = 'xform'¶
- format = 'xml'¶
- media_type = 'text/xml'¶
- render(data, accepted_media_type=None, renderer_context=None)¶
Renders obj into serialized XML.
- root_node = 'xforms'¶
- xmlns = 'http://openrosa.org/xforms/xformsList'¶
- class onadata.libs.renderers.renderers.XFormManifestRenderer¶
Bases:
XFormListRenderer
,StreamRendererMixin
XFormManifestRenderer - render XFormManifest XML.
- element_node = 'mediaFile'¶
- root_node = 'manifest'¶
- xmlns = 'http://openrosa.org/xforms/xformsManifest'¶
- class onadata.libs.renderers.renderers.XLSRenderer¶
Bases:
BaseRenderer
- XLSRenderer - renders .xls spreadsheet documents with
application/vnd.openxmlformats.
- charset = None¶
- format = 'xls'¶
- media_type = 'application/vnd.openxmlformats'¶
- render(data, accepted_media_type=None, renderer_context=None)¶
Encode
data
string to ‘utf-8’.
- class onadata.libs.renderers.renderers.XLSXRenderer¶
Bases:
XLSRenderer
- XLSRenderer - renders .xlsx spreadsheet documents with
application/vnd.openxmlformats.
- format = 'xlsx'¶
- class onadata.libs.renderers.renderers.ZipRenderer¶
Bases:
BaseRenderer
ZipRenderer - render .zip files.
- charset = None¶
- format = 'zip'¶
- media_type = 'application/octet-stream'¶
- render(data, accepted_media_type=None, renderer_context=None)¶
- onadata.libs.renderers.renderers.floip_list(data)¶
Yields FLOIP results data row from list data.
- onadata.libs.renderers.renderers.floip_rows_list(data)¶
Yields a row of FLOIP results data from dict data.
- onadata.libs.renderers.renderers.pairing(val1, val2)¶
Pairing function, encodes two natural numbers into a single natural number.