Mercurial > hg > Feedworm
annotate backend/couchdb/ListDateTimeField.py @ 248:f08fa6dcb86f
remove unused import
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Thu, 09 Jun 2016 05:09:06 +0200 |
parents | e34c53a3e407 |
children |
rev | line source |
---|---|
217
bb3c851b18b1
add source file endcoding header
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
170
diff
changeset
|
1 # -*- coding: utf-8 -*- |
170
f0afcd1c5656
implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff
changeset
|
2 from couchdb.mapping import Field |
f0afcd1c5656
implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff
changeset
|
3 from datetime import datetime |
f0afcd1c5656
implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff
changeset
|
4 |
f0afcd1c5656
implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff
changeset
|
5 class ListDateTimeField(Field): |
f0afcd1c5656
implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff
changeset
|
6 def _to_python(self, value): |
f0afcd1c5656
implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff
changeset
|
7 if isinstance(value, list): |
f0afcd1c5656
implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff
changeset
|
8 return datetime(*value) |
f0afcd1c5656
implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff
changeset
|
9 return value |
f0afcd1c5656
implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff
changeset
|
10 |
f0afcd1c5656
implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff
changeset
|
11 def _to_json(self, value): |
f0afcd1c5656
implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff
changeset
|
12 if isinstance(value, datetime): |
233
e34c53a3e407
fixes from eric's style check
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
217
diff
changeset
|
13 return [value.year, value.month, value.day, value.hour, value.minute, value.second] |
170
f0afcd1c5656
implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff
changeset
|
14 return value |