Skip to content

add creation date to fs node info #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions nc_py_api/files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class FsNodeInfo:
is_version: bool
"""Flag indicating if the object is File Version representation"""
_last_modified: datetime.datetime
_creation_date: datetime.datetime
_trashbin: dict

def __init__(self, **kwargs):
Expand All @@ -102,6 +103,10 @@ def __init__(self, **kwargs):
self.last_modified = kwargs.get("last_modified", datetime.datetime(1970, 1, 1))
except (ValueError, TypeError):
self.last_modified = datetime.datetime(1970, 1, 1)
try:
self._creation_date = kwargs.get("creation_date", datetime.datetime(1970, 1, 1))
except (ValueError, TypeError):
self._creation_date = datetime.datetime(1970, 1, 1)
self._trashbin: dict[str, str | int] = {}
for i in ("trashbin_filename", "trashbin_original_location", "trashbin_deletion_time"):
if i in kwargs:
Expand Down Expand Up @@ -142,6 +147,18 @@ def last_modified(self, value: str | datetime.datetime):
else:
self._last_modified = value

@property
def creation_date(self) -> datetime.datetime:
"""Time when the object was created."""
return self._creation_date

@creation_date.setter
def creation_date(self, value: str | datetime.datetime):
if isinstance(value, str):
self._creation_date = email.utils.parsedate_to_datetime(value)
else:
self._creation_date = value

@property
def in_trash(self) -> bool:
"""Returns ``True`` if the object is in trash."""
Expand Down
4 changes: 4 additions & 0 deletions nc_py_api/files/_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
PROPFIND_PROPERTIES = [
"d:resourcetype",
"d:getlastmodified",
"d:creationdate",
"d:getcontentlength",
"d:getcontenttype",
"d:getetag",
Expand Down Expand Up @@ -45,6 +46,7 @@
"name": "d:displayname", # like, eq
"mime": "d:getcontenttype", # like, eq
"last_modified": "d:getlastmodified", # gt, eq, lt
"creation_date": "d:creationdate", # gt, eq, lt
"size": "oc:size", # gt, gte, eq, lt
"favorite": "oc:favorite", # eq
"fileid": "oc:fileid", # eq
Expand Down Expand Up @@ -286,6 +288,8 @@ def _parse_record(full_path: str, prop_stats: list[dict]) -> FsNode: # noqa pyl
fs_node_args["etag"] = prop["d:getetag"]
if "d:getlastmodified" in prop_keys:
fs_node_args["last_modified"] = prop["d:getlastmodified"]
if "d:creationdate" in prop_keys:
fs_node_args["creation_date"] = prop["d:creationdate"]
if "d:getcontenttype" in prop_keys:
fs_node_args["mimetype"] = prop["d:getcontenttype"]
if "oc:permissions" in prop_keys:
Expand Down