Skip to content

Commit

Permalink
Merge pull request #190 from masqu3rad3/TIK-150-renamed-tasks-cannot-…
Browse files Browse the repository at this point in the history
…be-reverted-back-to-the-original-name

tasks now have nice names which can be renamed for display purposes. …
  • Loading branch information
masqu3rad3 authored Jan 8, 2025
2 parents b449ee4 + f0a775d commit 5fa1dc7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 34 deletions.
23 changes: 13 additions & 10 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,10 @@ def test_edit_task(self, project_manual_path, tik):
tik.user.set("Generic", password="1234")
assert (
task.edit(
name="Aquaman",
nice_name="Aquaman",
categories=["Model", "Rig", "LookDev", "Animation"],
metadata_overrides={"mode": "shot"},
)
)[0]
== -1
)
assert tik.log.get_last_message() == (
Expand All @@ -471,10 +471,10 @@ def test_edit_task(self, project_manual_path, tik):
)
assert (
task.edit(
name="Wonderboy",
nice_name="Wonderboy",
categories=["Model", "Rig", "LookDev", "Animation"],
metadata_overrides={"mode": "shot"},
)
)[0]
== -1
)
assert tik.log.get_last_message() == (
Expand All @@ -484,24 +484,27 @@ def test_edit_task(self, project_manual_path, tik):

# wrong category type
with pytest.raises(Exception):
task.edit(name="Aquaman", categories="ThisIsWrong", metadata_overrides={"mode": "shot"})
task.edit(nice_name="Aquaman", categories="ThisIsWrong", metadata_overrides={"mode": "shot"})
# category not defined
with pytest.raises(Exception):
assert (
task.edit(
name="Aquaman",
nice_name="Aquaman",
categories=["Model", "Rig", "LookDev", "Animation", "ThisIsWrong"],
metadata_overrides={"mode": "shot"},
)
)[0]
== -1
)

# edit the task
task.edit(
name="Aquaman",
nice_name="Aquaman",
categories=["Model", "Rig", "LookDev", "Animation"],
metadata_overrides={"mode": "shot"},
)

assert list(task.categories.keys()) == ["Model", "Rig", "LookDev", "Animation"]
assert task.name == "Aquaman"
assert task.nice_name == "Aquaman"
assert task.name == "Poseidon"

def test_adding_categories(self, project_manual_path, tik):
self.test_creating_and_adding_new_tasks(project_manual_path, tik)
Expand Down
1 change: 1 addition & 0 deletions tik_manager4/objects/subproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ def add_task(self,
metadata_overrides=metadata_overrides,
)
_task.add_property("name", name)
_task.add_property("nice_name", name)
_task.add_property("creator", self.guard.user)
_task.add_property("task_id", _task_id)
_task.add_property("subproject_id", self.id)
Expand Down
42 changes: 22 additions & 20 deletions tik_manager4/objects/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(
self._parent_sub = parent_sub

self._name = self.get_property("name") or name
self._nice_name = self.get_property("nice_name") or name
self._creator = self.get_property("creator") or self.guard.user
self._works = {}
self._publishes = {}
Expand Down Expand Up @@ -83,6 +84,11 @@ def name(self):
"""Name of the task."""
return self._name

@property
def nice_name(self):
"""Nice name of the task."""
return self._nice_name

@property
def id(self):
"""Unique ID of the task."""
Expand Down Expand Up @@ -180,15 +186,15 @@ def add_category(self, category):
self.apply_settings()
return self._categories[category]

def edit(self, name=None, categories=None, metadata_overrides=None):
def edit(self, nice_name=None, categories=None, metadata_overrides=None):
"""Edit the task.
Edits the given arguments of the task and applies the settings.
If no argument is given, the function does nothing.
This method requires level 2 permissions.
Args:
name (str): New name for the task
nice_name (str): New name for the task
task_type (str): New type for the task
categories (list): New categories for the task
Expand All @@ -197,38 +203,34 @@ def edit(self, name=None, categories=None, metadata_overrides=None):
"""
state = self.check_permissions(level=2)
if state != 1:
return -1
if name and name != self.name:
msg = "User has no permission to edit task."
return -1, msg
if nice_name and nice_name != self.nice_name:
# check the sibling tasks to see if the name is already taken
if name in self.parent_sub.tasks:
LOG.error(
"Task name '{0}' already exists in sub '{1}'.".format(
name, self.parent_sub.name
)
)
return -1
self._name = name
self.edit_property("name", name)
sibling_task_names = [task.nice_name for task in self.parent_sub.tasks.values()]
if nice_name in sibling_task_names:
msg = f"Task name '{nice_name}' already exists in sub '{self.parent_sub.name}'."
LOG.error(msg)
return -1, msg
self._nice_name = nice_name
self.edit_property("nice_name", nice_name)
if categories and categories != list(self.categories.keys()):
# check if the categories are list or tuple
if not isinstance(categories, (list, tuple)):
LOG.error("Categories must be a list or tuple.", proceed=False)
# check if the categories are in the category definitions
for category in categories:
if category not in self.guard.category_definitions.properties.keys():
LOG.error(
"Category '{0}' is not defined in category definitions.".format(
category
),
proceed=False,
)
msg = f"Category '{category}' is not defined in category definitions."
LOG.error(msg)
return -1, msg
self._categories = self.build_categories(categories)
self.edit_property("categories", list(categories))
if metadata_overrides is not None: # explicitly check for None
self._metadata_overrides = metadata_overrides
self.edit_property("metadata_overrides", metadata_overrides)
self.apply_settings()
return 1
return 1, "Success"

def delete_category(self, category):
"""Delete a category from the task.
Expand Down
11 changes: 9 additions & 2 deletions tik_manager4/ui/dialog/task_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,16 @@ def execute(self):
filtered_data.update_overridden_data(self.secondary_data)
filtered_data.update_new_data(self.tertiary_data)
_name = self.primary_data.get_property("name")
self.task_object.edit(
name=_name,
ret, msg = self.task_object.edit(
nice_name=_name,
categories=self.primary_data.get_property("categories"),
metadata_overrides=filtered_data,
)
if ret == -1:
self.feedback.pop_info(
title="Failed to edit task.",
text=msg,
critical=True,
)
return
self.accept()
6 changes: 4 additions & 2 deletions tik_manager4/ui/mcv/task_mcv.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, task_obj):
# self.setForeground(QtGui.QColor(*_color))

# self.setFont(fnt)
self.setText(task_obj.name)
self.setText(task_obj.nice_name or task_obj.name)

self.refresh()

Expand Down Expand Up @@ -331,6 +331,7 @@ def edit_task(self, item):
state = _dialog.exec_()
if state:
# emit clicked signal
self.refresh()
self.item_selected.emit(_dialog.task_object)
else:
pass
Expand Down Expand Up @@ -369,7 +370,8 @@ def delete_task(self, item):
"Non Empty Task",
"The task is not empty.\n\n"
"ALL CATEGORIES WORKS AND PUBLISHES UNDER {} WILL BE REMOVED\n"
"ARE YOU SURE?".format(item.task.name),
# "ARE YOU SURE?".format(item.task.name),
"ARE YOU SURE?".format(item.task.nice_name),
buttons=["ok", "cancel"],
)
if really_sure != "ok":
Expand Down

0 comments on commit 5fa1dc7

Please sign in to comment.