-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better docs and an example for DatetimeCol (#101)
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
from datetime import datetime | ||
|
||
from flask_table import Table, Col, DatetimeCol | ||
|
||
# Run this example with LC_TIME=[other locale] to use a different | ||
# locale's datetime formatting, eg: | ||
# | ||
# LC_TIME=en_US python examples/datetimecol.py | ||
# or | ||
# LC_TIME=en_GB python examples/datetimecol.py | ||
os.environ.setdefault('LC_TIME', 'en_GB') | ||
|
||
|
||
class Item(object): | ||
def __init__(self, name, dt): | ||
self.name = name | ||
self.dt = dt | ||
|
||
|
||
class ItemTable(Table): | ||
name = Col('Name') | ||
dt = DatetimeCol('Datetime') | ||
|
||
|
||
def main(): | ||
items = [ | ||
Item('Name1', datetime.now()), | ||
Item('Name2', datetime(2018, 1, 1, 12, 34, 56)), | ||
] | ||
|
||
table = ItemTable(items) | ||
|
||
# or {{ table }} in jinja | ||
print(table.__html__()) | ||
|
||
if __name__ == '__main__': | ||
main() |