Skip to content

Commit

Permalink
Fix DatetimeCol format option
Browse files Browse the repository at this point in the history
  • Loading branch information
plumdog committed Jul 16, 2016
1 parent 1c01928 commit 7bb216d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions flask_table/columns.py
Expand Up @@ -174,9 +174,9 @@ class DatetimeCol(Col):
output empty.
"""
def __init__(self, name, **kwargs):
def __init__(self, name, datetime_format='short', **kwargs):
super(DatetimeCol, self).__init__(name, **kwargs)
self.datetime_format = kwargs.get('datetime_format', 'short')
self.datetime_format = datetime_format

def td_format(self, content):
if content:
Expand Down
17 changes: 17 additions & 0 deletions tests/__init__.py
Expand Up @@ -606,6 +606,23 @@ def test_one(self):
'datetime_test', 'test_one', items)


class DatetimeTestFormat(TableTest):
def setUp(self):

class MyTable(Table):
datetime = DatetimeCol(
'DateTime Heading',
datetime_format="YYYY-MM-dd hh:mm")
self.table_cls = MyTable

def test_one(self):
items = [
Item(datetime=datetime(2014, 1, 1, 10, 20, 30)),
Item(datetime=None)]
self.assert_html_equivalent_from_file(
'datetime_test_format', 'test_one', items)


class EscapeTest(TableTest):
def setUp(self):

Expand Down
9 changes: 9 additions & 0 deletions tests/html/datetime_test_format/test_one.html
@@ -0,0 +1,9 @@
<table>
<thead>
<tr><th>DateTime Heading</th></tr>
</thead>
<tbody>
<tr><td>2014-01-01 10:20</td></tr>
<tr><td></td></tr>
</tbody>
</table>

0 comments on commit 7bb216d

Please sign in to comment.