Skip to content

Commit

Permalink
Merge pull request #312 from frankrousseau/master
Browse files Browse the repository at this point in the history
Add all output files for projects
  • Loading branch information
EvanBldy authored Feb 12, 2024
2 parents f327cf7 + 924ae6a commit 6bde08d
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 13 deletions.
46 changes: 46 additions & 0 deletions gazu/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,52 @@ def all_output_files_for_asset_instance(
return raw.fetch_all(path, params, client=client)


def all_output_files_for_project(
project,
output_type=None,
task_type=None,
name=None,
representation=None,
file_status=None,
client=default,
):
"""
Args:
entity (str / dict): The entity dict or ID.
output_type (str / dict): The output type dict or ID.
task_type (str / dict): The task type dict or ID.
name (str): The file name
representation (str): The file representation
file_status (str / dict): The file status
Returns:
list:
Output files for a given project (asset or shot), output type,
task_type, name and representation
"""
project = normalize_model_parameter(project)
output_type = normalize_model_parameter(output_type)
task_type = normalize_model_parameter(task_type)
file_status = normalize_model_parameter(file_status)
path = "projects/{project_id}/output-files".format(
project_id=project["id"]
)

params = {}
if output_type:
params["output_type_id"] = output_type["id"]
if task_type:
params["task_type_id"] = task_type["id"]
if representation:
params["representation"] = representation
if name:
params["name"] = name
if file_status:
params["file_status_id"] = file_status["id"]

return raw.fetch_all(path, params, client=client)


@cache
def all_softwares(client=default):
"""
Expand Down
38 changes: 25 additions & 13 deletions gazu/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,39 @@ def get_person_by_email(email, client=default):


@cache
def get_person_by_full_name(full_name, client=default):
def get_person_by_full_name(
full_name,
first_name=None,
last_name=None,
client=default
):
"""
Args:
full_name (str): User's full name
Returns:
dict: Person corresponding to given name.
"""
if " " in full_name:
first_name, last_name = full_name.lower().split(" ")
else:
first_name, last_name = full_name.lower().strip(), ""
for person in all_persons():
is_right_first_name = (
first_name == person["first_name"].lower().strip()
)
is_right_last_name = (
len(last_name) == 0 or last_name == person["last_name"].lower()
if first_name is not None and last_name is not None:
return raw.fetch_first(
"persons",
{"first_name": first_name, "last_name": last_name},
client=client,
)
if is_right_first_name and is_right_last_name:
return person
else:
if " " in full_name:
first_name, last_name = full_name.lower().split(" ")
else:
first_name, last_name = full_name.lower().strip(), ""
for person in all_persons():
is_right_first_name = (
first_name == person["first_name"].lower().strip()
)
is_right_last_name = (
len(last_name) == 0 or last_name == person["last_name"].lower()
)
if is_right_first_name and is_right_last_name:
return person
return None


Expand Down
17 changes: 17 additions & 0 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,23 @@ def test_get_output_files_for_asset_instance(self):
self.assertEqual(output_files[0]["id"], "output-file-01")
self.assertEqual(output_files[0]["name"], "main")

def test_get_output_files_for_project(self):
with requests_mock.mock() as mock:
base_path = "projects/project-01/output-files"
path = gazu.client.url_path_join("data", base_path)
params = {"output_type_id": "output-type-1"}

mock.get(
gazu.client.get_full_url(
gazu.client.build_path_with_params(path, params)
),
text=json.dumps([{"id": "output-file-01", "name": "main"}]),
)
output_files = gazu.files.all_output_files_for_project(
{"id": "project-01"}, output_type={"id": "output-type-1"}
)
self.assertEqual(output_files[0]["name"], "main")

def test_update_modification_date(self):
with requests_mock.mock() as mock:
path = "/actions/working-files/working-file-01/modified"
Expand Down

0 comments on commit 6bde08d

Please sign in to comment.