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: rest_framework.renderers.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: rest_framework.renderers.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: rest_framework.renderers.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):

  1. An explicit .template_name set on the response.
  2. An explicit .template_name set on this class.
  3. 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: rest_framework.utils.encoders.JSONEncoder

JSON DecimalEncoder that returns None for decimal nan json values.

default(obj)

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
class onadata.libs.renderers.renderers.DecimalJSONRenderer

Bases: rest_framework.renderers.JSONRenderer

Extends the default json renderer to handle Decimal(‘NaN’) values

encoder_class

alias of DecimalEncoder

class onadata.libs.renderers.renderers.FLOIPRenderer

Bases: rest_framework.renderers.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: rest_framework.renderers.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: onadata.libs.renderers.renderers.XLSRenderer

GoogleSheetsRenderer = Google Sheets excel exports.

format = 'gsheets'
class onadata.libs.renderers.renderers.KMLRenderer

Bases: rest_framework.renderers.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: rest_framework.negotiation.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: rest_framework.renderers.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: rest_framework.renderers.BaseRenderer

OSMExportRenderer - render .osm data as XML.

charset = 'utf-8'
format = 'osm'
media_type = 'text/xml'
class onadata.libs.renderers.renderers.OSMRenderer

Bases: rest_framework.renderers.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: rest_framework.renderers.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: rest_framework.renderers.StaticHTMLRenderer

StaticXMLRenderer - render static XML document.

format = 'xml'
media_type = 'text/xml'
class onadata.libs.renderers.renderers.SurveyRenderer

Bases: rest_framework.renderers.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: rest_framework.renderers.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):

  1. An explicit .template_name set on the response.
  2. An explicit .template_name set on this class.
  3. The return result of calling view.get_template_names().
class onadata.libs.renderers.renderers.XFormListRenderer

Bases: rest_framework.renderers.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: onadata.libs.renderers.renderers.XFormListRenderer

XFormManifestRenderer - render XFormManifest XML.

element_node = 'mediaFile'
root_node = 'manifest'
xmlns = 'http://openrosa.org/xforms/xformsManifest'
class onadata.libs.renderers.renderers.XLSRenderer

Bases: rest_framework.renderers.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)
class onadata.libs.renderers.renderers.XLSXRenderer

Bases: onadata.libs.renderers.renderers.XLSRenderer

XLSRenderer - renders .xlsx spreadsheet documents with
application/vnd.openxmlformats.
format = 'xlsx'
class onadata.libs.renderers.renderers.ZipRenderer

Bases: rest_framework.renderers.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.

Reference: https://en.wikipedia.org/wiki/Pairing_function

Module contents