Skip to content

utils

routes.utils.utils

check_if_job_is_owned_and_exist

check_if_job_is_owned_and_exist(job_id, user)

Function checking if provided task is owned by user managing action

Source code in yaptide/routes/utils/utils.py
 9
10
11
12
13
14
15
16
17
def check_if_job_is_owned_and_exist(job_id: str, user: UserModel) -> tuple[bool, str, int]:
    """Function checking if provided task is owned by user managing action"""
    simulation = fetch_simulation_by_job_id(job_id=job_id)

    if not simulation:
        return False, 'Job with provided ID does not exist', 404
    if simulation.user_id == user.id:
        return True, "", 200
    return False, 'Job with provided ID does not belong to the user', 403

determine_input_type

determine_input_type(payload_dict)

Function returning input type determined from payload

Source code in yaptide/routes/utils/utils.py
20
21
22
23
24
25
26
27
28
29
30
def determine_input_type(payload_dict: dict) -> Optional[str]:
    """Function returning input type determined from payload"""
    if payload_dict["input_type"] == "editor":
        if "input_json" not in payload_dict:
            return None
        return InputType.EDITOR.value
    if payload_dict["input_type"] == "files":
        if "input_files" not in payload_dict:
            return None
        return InputType.FILES.value
    return None

make_input_dict

make_input_dict(payload_dict, input_type)

Function returning input dict

Source code in yaptide/routes/utils/utils.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def make_input_dict(payload_dict: dict, input_type: str) -> dict:
    """Function returning input dict"""
    input_dict = {
        "input_type": input_type,
    }
    if input_type == InputType.EDITOR.value:
        files_dict, number_of_all_primaries = files_dict_with_adjusted_primaries(payload_dict=payload_dict)
        input_dict["input_json"] = payload_dict["input_json"]
    else:
        files_dict, number_of_all_primaries = files_dict_with_adjusted_primaries(payload_dict=payload_dict)
    input_dict["number_of_all_primaries"] = number_of_all_primaries
    input_dict["input_files"] = files_dict

    return input_dict