event_transaction_utils.py 1.16 KB
Newer Older
1 2 3 4
"""
Helper functions to access and update the id and type
used in event tracking.
"""
5 6
from uuid import UUID, uuid4

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
from request_cache import get_cache


def get_event_transaction_id():
    """
    Retrieves the current event transaction id from the request
    cache.
    """
    return get_cache('event_transaction').get('id', None)


def get_event_transaction_type():
    """
    Retrieves the current event transaction type from the request
    cache.
    """
    return get_cache('event_transaction').get('type', None)


def create_new_event_transaction_id():
    """
    Sets the event transaction id to a newly-
    generated UUID.
    """
    new_id = uuid4()
    get_cache('event_transaction')['id'] = new_id
    return new_id


def set_event_transaction_id(new_id):
    """
    Sets the event transaction id to a UUID object
    generated from new_id.
    new_id must be a parsable string version
    of a UUID.
    """
    get_cache('event_transaction')['id'] = UUID(new_id)


def set_event_transaction_type(action_type):
    """
    Takes a string and stores it in the request cache
    as the user action type.
    """
    get_cache('event_transaction')['type'] = action_type