summaryrefslogtreecommitdiff
path: root/tablib
diff options
context:
space:
mode:
authorMathias Loesch <m.loesch@celonis.com>2019-01-23 14:18:01 +0100
committerMathias Loesch <m.loesch83@gmail.com>2019-01-23 22:34:45 +0100
commit102073c426d7a76384e75379abbf1a3b0ed78662 (patch)
treec119317596a4037e43764ccfeab059bfe91dffb9 /tablib
parent5a359ba4def1611b34df003bec58439a125d4e56 (diff)
downloadtablib-102073c426d7a76384e75379abbf1a3b0ed78662.tar.gz
Add Jira table export
Diffstat (limited to 'tablib')
-rw-r--r--tablib/core.py8
-rw-r--r--tablib/formats/__init__.py3
-rw-r--r--tablib/formats/_jira.py39
3 files changed, 48 insertions, 2 deletions
diff --git a/tablib/core.py b/tablib/core.py
index 8c49f2e..3dc23ea 100644
--- a/tablib/core.py
+++ b/tablib/core.py
@@ -631,7 +631,6 @@ class Dataset(object):
"""
pass
-
@property
def latex():
"""A LaTeX booktabs representation of the :class:`Dataset` object. If a
@@ -641,6 +640,13 @@ class Dataset(object):
"""
pass
+ @property
+ def jira():
+ """A Jira table representation of the :class:`Dataset` object.
+
+ .. note:: This method can be used for export only.
+ """
+ pass
# ----
# Rows
diff --git a/tablib/formats/__init__.py b/tablib/formats/__init__.py
index 3eb747e..418e607 100644
--- a/tablib/formats/__init__.py
+++ b/tablib/formats/__init__.py
@@ -15,5 +15,6 @@ from . import _dbf as dbf
from . import _latex as latex
from . import _df as df
from . import _rst as rst
+from . import _jira as jira
-available = (json, xls, yaml, csv, dbf, tsv, html, latex, xlsx, ods, df, rst)
+available = (json, xls, yaml, csv, dbf, tsv, html, jira, latex, xlsx, ods, df, rst)
diff --git a/tablib/formats/_jira.py b/tablib/formats/_jira.py
new file mode 100644
index 0000000..55fce52
--- /dev/null
+++ b/tablib/formats/_jira.py
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+
+"""Tablib - Jira table export support.
+
+ Generates a Jira table from the dataset.
+"""
+from tablib.compat import unicode
+
+title = 'jira'
+
+
+def export_set(dataset):
+ """Formats the dataset according to the Jira table syntax:
+
+ ||heading 1||heading 2||heading 3||
+ |col A1|col A2|col A3|
+ |col B1|col B2|col B3|
+
+ :param dataset: dataset to serialize
+ :type dataset: tablib.core.Dataset
+ """
+
+ header = _get_header(dataset.headers) if dataset.headers else ''
+ body = _get_body(dataset)
+ return '%s\n%s' % (header, body) if header else body
+
+
+def _get_body(dataset):
+ return '\n'.join([_serialize_row(row) for row in dataset])
+
+
+def _get_header(headers):
+ return _serialize_row(headers, delimiter='||')
+
+
+def _serialize_row(row, delimiter='|'):
+ return '%s%s%s' % (delimiter,
+ delimiter.join([unicode(item) if item else ' ' for item in row]),
+ delimiter)