Skip to content
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

various improvements : persons / bots #317

Merged
merged 3 commits into from
Mar 5, 2024
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
14 changes: 7 additions & 7 deletions examples/events.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import gazu

gazu.set_host("http://localhost:8080/api")
gazu.set_event_host("http://localhost:8080/")
gazu.log_in("jhon@doe.com", "password")
gazu.set_host("https://your-instance.cg-wire.com/api")
gazu.set_event_host("https://your-instance.cg-wire.com")
gazu.log_in("your@email.com", "yourpassword")


def my_callback(data):
print("Task status changed:")
print(data)
def my_callback(event, data):
print(f"event:{event}")
print(f"data:{data}")


try:
event_client = gazu.events.init()
gazu.events.add_listener(event_client, "task:status-changed", my_callback)
gazu.events.add_listener(event_client, "*", my_callback)
gazu.events.run_client(event_client)
except KeyboardInterrupt:
print("Stop listening.")
Expand Down
2 changes: 1 addition & 1 deletion gazu/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def remove_asset(asset, force=False, client=default):
path = "data/assets/%s" % asset["id"]
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(path, params, client=client)


Expand Down
2 changes: 1 addition & 1 deletion gazu/concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def remove_concept(concept, force=False, client=default):
path = "data/concepts/%s" % concept["id"]
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(path, params, client=client)


Expand Down
2 changes: 1 addition & 1 deletion gazu/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def remove_edit(edit, force=False, client=default):
path = "data/edits/%s" % edit["id"]
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(path, params, client=client)


Expand Down
2 changes: 1 addition & 1 deletion gazu/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def remove_entity(entity, force=False, client=default):
path = "data/entities/%s" % entity["id"]
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(path, params, client=client)


Expand Down
121 changes: 103 additions & 18 deletions gazu/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def get_person(id, relations=False, client=default):
dict: Person corresponding to given id.
"""
params = {"id": id}
if relations:
params["relations"] = "true"
if not relations:
params["relations"] = False

return raw.fetch_first("persons", params=params, client=client)

Expand All @@ -105,7 +105,9 @@ def get_person_by_desktop_login(desktop_login, client=default):
dict: Person corresponding to given desktop computer login.
"""
return raw.fetch_first(
"persons", {"desktop_login": desktop_login}, client=client
"persons",
{"desktop_login": desktop_login, "is_bot": False},
client=client,
)


Expand All @@ -118,7 +120,9 @@ def get_person_by_email(email, client=default):
Returns:
dict: Person corresponding to given email.
"""
return raw.fetch_first("persons", {"email": email}, client=client)
return raw.fetch_first(
"persons", {"email": email, "is_bot": False}, client=client
)


@cache
Expand All @@ -137,16 +141,19 @@ def get_person_by_full_name(
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},
{
"first_name": first_name,
"last_name": last_name,
"is_bot": False,
},
client=client,
)
else:
return raw.fetch_first(
"persons",
{"full_name": full_name},
{"full_name": full_name, "is_bot": False},
client=client,
)
return None


@cache
Expand Down Expand Up @@ -184,33 +191,32 @@ def new_person(
desktop_login="",
departments=[],
password=None,
is_bot=False,
expiration_date=None,
active=True,
contract_type="open-ended",
client=default,
):
"""
Create a new person based on given parameters. His/her password will is
set automatically to default.

Args:
first_name (str):
last_name (str):
email (str):
phone (str):
first_name (str): the first name of the person.
last_name (str): the last name of the person.
email (str): the email of the person.
phone (str): the phone number of the person.
role (str): user, manager, admin (wich match CG artist, Supervisor
and studio manager)
desktop_login (str): The login the users uses to log on its computer.
departments (list): The departments for the person.
password (str): The password for the person.
is_bot (bool): Whether the person is a bot or not.
expiration_date (str): The expiration date for the person.
active (bool): Whether the person is active or not.
Returns:
dict: Created person.
"""
person = get_person_by_email(email, client=client)
if person is None:
person = raw.post(
"data/persons/new",
"data/persons",
{
"first_name": first_name,
"last_name": last_name,
Expand All @@ -220,8 +226,8 @@ def new_person(
"desktop_login": desktop_login,
"departments": normalize_list_of_models_for_links(departments),
"password": password,
"is_bot": is_bot,
"expiration_date": expiration_date,
"active": active,
"contract_type": contract_type,
},
client=client,
)
Expand Down Expand Up @@ -252,6 +258,85 @@ def update_person(person, client=default):
)


def remove_person(person, force=False, client=default):
"""
Remove given person from database.

Args:
person (dict): Person to remove.
"""
person = normalize_model_parameter(person)
path = "data/persons/%s" % person["id"]
params = {}
if force:
params = {"force": True}
return raw.delete(path, params, client=client)


def new_bot(
name,
email,
role="user",
departments=[],
active=True,
expiration_date=None,
client=default,
):
"""
Create a new bot based on given parameters. His access token will be in the
return dict.

Args:
name (str): the name of the bot.
email (str): the email of the bot.
role (str): user, manager, admin (wich match CG artist, Supervisor
and studio manager)
departments (list): The departments for the person.
active (bool): Whether the person is active or not.
expiration_date (str): The expiration date for the bot.
Returns:
dict: Created bot.
"""
bot = raw.post(
"data/persons",
{
"first_name": name,
"last_name": "",
"email": email,
"role": role,
"departments": normalize_list_of_models_for_links(departments),
"active": active,
"expiration_date": expiration_date,
"is_bot": True,
},
client=client,
)
return bot


def update_bot(bot, client=default):
"""
Update a bot.

Args:
bot (dict): The bot dict that needs to be upgraded.

Returns:
dict: The updated bot.
"""
return update_person(bot, client=client)


def remove_bot(bot, force=False, client=default):
"""
Remove given bot from database.

Args:
bot (dict): Bot to remove.
"""
return remove_person(bot, force=force, client=client)


def set_avatar(person, file_path, client=default):
"""
Upload picture and set it as avatar for given person.
Expand Down
2 changes: 1 addition & 1 deletion gazu/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def remove_metadata_descriptor(
metadata_descriptor = normalize_model_parameter(metadata_descriptor_id)
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(
"data/projects/%s/metadata-descriptors/%s"
% (project["id"], metadata_descriptor["id"]),
Expand Down
6 changes: 3 additions & 3 deletions gazu/shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def remove_shot(shot, force=False, client=default):
path = "data/shots/%s" % shot["id"]
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(path, params, client=client)


Expand Down Expand Up @@ -532,7 +532,7 @@ def remove_episode(episode, force=False, client=default):
path = "data/episodes/%s" % episode["id"]
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(path, params=params, client=client)


Expand All @@ -547,7 +547,7 @@ def remove_sequence(sequence, force=False, client=default):
path = "data/sequences/%s" % sequence["id"]
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(path, params=params, client=client)


Expand Down
Loading
Loading