Skip to content

rs_server_catalog/timestamps_extension.md

<< Back to index

Contains all functions for timestamps extension management.

set_timestamps_for_creation(item)

This function set the timestamps for an item creation. It will update the 'updated' and 'published' timestamps.

Parameters:

Name Type Description Default
item dict

The item to be created.

required

Returns:

Name Type Description
dict dict

The updated item.

Source code in docs/rs-server/services/catalog/rs_server_catalog/timestamps_extension.py
26
27
28
29
30
31
32
33
34
35
36
37
38
def set_timestamps_for_creation(item: dict) -> dict:
    """This function set the timestamps for an item creation.
    It will update the 'updated' and 'published' timestamps.

    Args:
        item (dict): The item to be created.

    Returns:
        dict: The updated item.
    """
    item = set_updated_timestamp_to_now(item)
    item["properties"]["published"] = item["properties"]["updated"]
    return item

set_timestamps_for_insertion(item)

This function set the timestamps for an item insertion. It will update the 'updated' and 'expires' timestamps.

Parameters:

Name Type Description Default
item dict

The item to be updated.

required

Returns:

Name Type Description
dict dict

The updated item.

Source code in docs/rs-server/services/catalog/rs_server_catalog/timestamps_extension.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def set_timestamps_for_insertion(item: dict) -> dict:
    """This function set the timestamps for an item insertion.
    It will update the 'updated' and 'expires' timestamps.

    Args:
        item (dict): The item to be updated.

    Returns:
        dict: The updated item.
    """
    item = set_updated_timestamp_to_now(item)
    item_owner = item["properties"].get("owner", "*")
    item_collection = item.get("collection", "*").removeprefix(f"{item_owner}_")
    item_eopf_type = item["properties"].get("eopf:type", "*")
    expiration_range = get_expiration_delay_from_config(item_owner, item_collection, item_eopf_type)
    expiration_date = datetime.datetime.now() + datetime.timedelta(days=expiration_range)
    item["properties"].setdefault("expires", expiration_date.strftime(ISO_8601_FORMAT))
    return item

set_timestamps_for_update(item, original_published, original_expires)

This function set the timestamps for an item update. It will update the 'updated' timestamp along with the 'expires' and 'published' ones with the values given.

Parameters:

Name Type Description Default
item dict

The item to be updated.

required
original_published str

Original 'published' timestamp to set.

required
original_expires str

Original 'expires' timestamp to set.

required

Returns:

Name Type Description
dict dict

The updated item.

Source code in docs/rs-server/services/catalog/rs_server_catalog/timestamps_extension.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def set_timestamps_for_update(item: dict, original_published: str, original_expires: str) -> dict:
    """This function set the timestamps for an item update.
    It will update the 'updated' timestamp along with the 'expires' and 'published' ones
    with the values given.

    Args:
        item (dict): The item to be updated.
        original_published (str): Original 'published' timestamp to set.
        original_expires (str): Original 'expires' timestamp to set.

    Returns:
        dict: The updated item.
    """
    item = set_updated_timestamp_to_now(item)
    item["properties"].setdefault("expires", original_expires)
    item["properties"].setdefault("published", original_published)
    return item

set_updated_timestamp_to_now(item)

Updates the 'updated' timestamp of the given item with the current time.

Parameters:

Name Type Description Default
item dict

The item to be updated.

required

Returns:

Name Type Description
dict dict

The updated item.

Source code in docs/rs-server/services/catalog/rs_server_catalog/timestamps_extension.py
80
81
82
83
84
85
86
87
88
89
90
91
def set_updated_timestamp_to_now(item: dict) -> dict:
    """Updates the 'updated' timestamp of the given item with the current time.

    Args:
        item (dict): The item to be updated.

    Returns:
        dict: The updated item.
    """
    current_time = datetime.datetime.now()
    item["properties"]["updated"] = current_time.strftime(ISO_8601_FORMAT)
    return item