Skip to content

Commit 0f8566c

Browse files
authored
add creation date to fs node info (#335)
Changes proposed in this pull request: *Added creation date for the fs node info *Edit default request to also get creation date
1 parent d467620 commit 0f8566c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

nc_py_api/files/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class FsNodeInfo:
8686
is_version: bool
8787
"""Flag indicating if the object is File Version representation"""
8888
_last_modified: datetime.datetime
89+
_creation_date: datetime.datetime
8990
_trashbin: dict
9091

9192
def __init__(self, **kwargs):
@@ -102,6 +103,10 @@ def __init__(self, **kwargs):
102103
self.last_modified = kwargs.get("last_modified", datetime.datetime(1970, 1, 1))
103104
except (ValueError, TypeError):
104105
self.last_modified = datetime.datetime(1970, 1, 1)
106+
try:
107+
self._creation_date = kwargs.get("creation_date", datetime.datetime(1970, 1, 1))
108+
except (ValueError, TypeError):
109+
self._creation_date = datetime.datetime(1970, 1, 1)
105110
self._trashbin: dict[str, str | int] = {}
106111
for i in ("trashbin_filename", "trashbin_original_location", "trashbin_deletion_time"):
107112
if i in kwargs:
@@ -142,6 +147,18 @@ def last_modified(self, value: str | datetime.datetime):
142147
else:
143148
self._last_modified = value
144149

150+
@property
151+
def creation_date(self) -> datetime.datetime:
152+
"""Time when the object was created."""
153+
return self._creation_date
154+
155+
@creation_date.setter
156+
def creation_date(self, value: str | datetime.datetime):
157+
if isinstance(value, str):
158+
self._creation_date = email.utils.parsedate_to_datetime(value)
159+
else:
160+
self._creation_date = value
161+
145162
@property
146163
def in_trash(self) -> bool:
147164
"""Returns ``True`` if the object is in trash."""

nc_py_api/files/_files.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
PROPFIND_PROPERTIES = [
1717
"d:resourcetype",
1818
"d:getlastmodified",
19+
"d:creationdate",
1920
"d:getcontentlength",
2021
"d:getcontenttype",
2122
"d:getetag",
@@ -45,6 +46,7 @@
4546
"name": "d:displayname", # like, eq
4647
"mime": "d:getcontenttype", # like, eq
4748
"last_modified": "d:getlastmodified", # gt, eq, lt
49+
"creation_date": "d:creationdate", # gt, eq, lt
4850
"size": "oc:size", # gt, gte, eq, lt
4951
"favorite": "oc:favorite", # eq
5052
"fileid": "oc:fileid", # eq
@@ -286,6 +288,8 @@ def _parse_record(full_path: str, prop_stats: list[dict]) -> FsNode: # noqa pyl
286288
fs_node_args["etag"] = prop["d:getetag"]
287289
if "d:getlastmodified" in prop_keys:
288290
fs_node_args["last_modified"] = prop["d:getlastmodified"]
291+
if "d:creationdate" in prop_keys:
292+
fs_node_args["creation_date"] = prop["d:creationdate"]
289293
if "d:getcontenttype" in prop_keys:
290294
fs_node_args["mimetype"] = prop["d:getcontenttype"]
291295
if "oc:permissions" in prop_keys:

0 commit comments

Comments
 (0)