mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 23:10:17 +00:00
@@ -23,6 +23,7 @@ Output formats supported:
|
||||
- YAML (Sets + Books)
|
||||
- Pandas DataFrames (Sets)
|
||||
- HTML (Sets)
|
||||
- Jira (Sets)
|
||||
- TSV (Sets)
|
||||
- ODS (Sets)
|
||||
- CSV (Sets)
|
||||
|
||||
+7
-1
@@ -632,7 +632,6 @@ class Dataset(object):
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@property
|
||||
def latex():
|
||||
"""A LaTeX booktabs representation of the :class:`Dataset` object. If a
|
||||
@@ -642,6 +641,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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
@@ -316,6 +316,23 @@ class TablibTestCase(unittest.TestCase):
|
||||
|
||||
self.assertEqual(html, d.html)
|
||||
|
||||
def test_jira_export(self):
|
||||
|
||||
expected = """||first_name||last_name||gpa||
|
||||
|John|Adams|90|
|
||||
|George|Washington|67|
|
||||
|Thomas|Jefferson|50|"""
|
||||
self.assertEqual(expected, self.founders.jira)
|
||||
|
||||
def test_jira_export_no_headers(self):
|
||||
self.assertEqual('|a|b|c|', tablib.Dataset(['a', 'b', 'c']).jira)
|
||||
|
||||
def test_jira_export_none_and_empty_values(self):
|
||||
self.assertEqual('| | |c|', tablib.Dataset(['', None, 'c']).jira)
|
||||
|
||||
def test_jira_export_empty_dataset(self):
|
||||
self.assertTrue(tablib.Dataset().jira is not None)
|
||||
|
||||
def test_latex_export(self):
|
||||
"""LaTeX export"""
|
||||
|
||||
@@ -399,6 +416,7 @@ class TablibTestCase(unittest.TestCase):
|
||||
data.xlsx
|
||||
data.ods
|
||||
data.html
|
||||
data.jira
|
||||
data.latex
|
||||
data.df
|
||||
data.rst
|
||||
@@ -421,6 +439,7 @@ class TablibTestCase(unittest.TestCase):
|
||||
data.xlsx
|
||||
data.ods
|
||||
data.html
|
||||
data.jira
|
||||
data.latex
|
||||
data.rst
|
||||
|
||||
|
||||
Reference in New Issue
Block a user