summaryrefslogtreecommitdiff
path: root/tablib
diff options
context:
space:
mode:
authorKenneth Reitz <me@kennethreitz.com>2010-11-04 04:26:03 -0400
committerKenneth Reitz <me@kennethreitz.com>2010-11-04 04:26:03 -0400
commit778ad0265e8421afc2df849dfd1449131cfa8487 (patch)
tree1c2146856a8dfe57398b2684c97ac529fc210967 /tablib
parente3dedb8887944919f7383d6ddac4ea79f05e8c58 (diff)
downloadtablib-778ad0265e8421afc2df849dfd1449131cfa8487.tar.gz
Added new required headers for adding columns.
Diffstat (limited to 'tablib')
-rw-r--r--tablib/core.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/tablib/core.py b/tablib/core.py
index df5aade..be04a0e 100644
--- a/tablib/core.py
+++ b/tablib/core.py
@@ -417,7 +417,7 @@ class Dataset(object):
"""
- def append(self, row=None, col=None, tags=list()):
+ def append(self, row=None, col=None, header=None, tags=list()):
"""Adds a row or column to the :class:`Dataset`.
Rows and Columns appended must be the correct size (height or width).
@@ -444,7 +444,7 @@ class Dataset(object):
if row is not None:
self.insert(self.height, row=row, tags=tags)
elif col is not None:
- self.insert(self.width, col=col)
+ self.insert(self.width, col=col, header=header)
def insert_separator(self, index, text='-'):
"""Adds a separator to :class:`Dataset` at given index."""
@@ -465,7 +465,7 @@ class Dataset(object):
self.insert_separator(index, text)
- def insert(self, index, row=None, col=None, tags=list()):
+ def insert(self, index, row=None, col=None, header=None, tags=list()):
"""Inserts a row or column to the :class:`Dataset` at the given index.
Rows and columns inserted must be the correct size (height or width).
@@ -492,8 +492,9 @@ class Dataset(object):
if self.headers:
# pop the first item off, add to headers
- self.headers.insert(index, col[0])
- col = col[1:]
+ if not header:
+ raise HeadersNeeded()
+ self.headers.insert(header)
if self.height and self.width:
@@ -610,6 +611,8 @@ class InvalidDatasetType(Exception):
class InvalidDimensions(Exception):
"Invalid size"
-
+class HeadersNeeded(Exception):
+ "Header parameter must be given when appending a column in this Dataset."
+
class UnsupportedFormat(NotImplementedError):
"Format is not supported"