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

Asset task options implementation #556

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions avalon/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def _save_config_1_0(project_name, data):
config["apps"] = data.get("apps", [])
config["tasks"] = data.get("tasks", [])
config["template"].update(data.get("template", {}))
config["assetOptions"] = data.get("assetOptions", [])
config["families"] = data.get("families", [])
config["groups"] = data.get("groups", [])

Expand Down
12 changes: 8 additions & 4 deletions avalon/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,22 +353,26 @@ def insert_many(items, ordered=True):


@auto_reconnect
def find(filter, projection=None, sort=None):
def find(filter, projection=None, sort=None, *args, **kwargs):
return self._database[Session["AVALON_PROJECT"]].find(
filter=filter,
projection=projection,
sort=sort
sort=sort,
*args,
**kwargs
)


@auto_reconnect
def find_one(filter, projection=None, sort=None):
def find_one(filter, projection=None, sort=None, *args, **kwargs):
assert isinstance(filter, dict), "filter must be <dict>"

return self._database[Session["AVALON_PROJECT"]].find_one(
filter=filter,
projection=projection,
sort=sort
sort=sort,
*args,
**kwargs
)


Expand Down
14 changes: 14 additions & 0 deletions avalon/schema/config-1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@
"required": ["name"]
}
},
"assetOptions": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": true,
"properties": {
"name": {"type": "string"},
"label": {"type": "string"},
"help": {"type": "string"},
"onTasks": {"type": "array"}
},
"required": ["name"]
}
},
"families": {
"type": "array",
"items": {
Expand Down
7 changes: 1 addition & 6 deletions avalon/tools/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def iter_model_rows(model,
@contextlib.contextmanager
def preserve_states(tree_view,
column=0,
role=None,
role=QtCore.Qt.DisplayRole,
preserve_expanded=True,
preserve_selection=True,
current_index=True,
Expand All @@ -126,11 +126,6 @@ def preserve_states(tree_view,
Returns:
None
"""
# When `role` is set then override both expanded and selection roles
if role:
expanded_role = role
selection_role = role

model = tree_view.model()
selection_model = tree_view.selectionModel()
flags = selection_model.Select | selection_model.Rows
Expand Down
47 changes: 46 additions & 1 deletion avalon/tools/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import collections

from ..vendor.Qt import QtCore, QtGui
from ..vendor.Qt import Qt, QtCore, QtGui
from ..vendor import qtawesome
from .. import io
from .. import style
Expand Down Expand Up @@ -329,6 +329,9 @@ class AssetModel(TreeModel):
def __init__(self, parent=None):
super(AssetModel, self).__init__(parent=parent)
self.refresh()
# (TODO) A good model should NOT self refresh on init, should let
# the main app make this call, or some where that all signals been
# connected.

def _add_hierarchy(self, assets, parent=None, silos=None):
"""Add the assets that are related to the parent as children items.
Expand Down Expand Up @@ -417,6 +420,23 @@ def refresh(self):

self.endResetModel()

def update_documents(self, indexes):
"""Update items documents by indexes

Collect items' document id from indexes, and query database
for updating item data with `DocumentRole`

"""
doc_ids = dict()
for index in indexes:
doc_id = self.data(index, self.ObjectIdRole)
doc_ids[doc_id] = index

documents = io.find({"_id": {"$in": list(doc_ids.keys())}})
for doc in documents:
index = doc_ids[doc["_id"]]
self.setData(index, doc, role=self.DocumentRole)

def flags(self, index):
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable

Expand Down Expand Up @@ -472,6 +492,31 @@ def data(self, index, role):

return super(AssetModel, self).data(index, role)

def setData(self, index, value, role=QtCore.Qt.EditRole):
"""Change the data on the items.

Returns:
bool: Whether the edit was successful
"""
if not index.isValid():
return False

changed = False

if role == self.DocumentRole:
item = index.internalPointer()
item["_document"] = value
changed = True

if changed:
# passing `list()` for PyQt5 (see PYSIDE-462)
args = () if Qt.IsPySide or Qt.IsPyQt4 else ([role],)
self.dataChanged.emit(index, index, *args)
# must return true if successful
return True
else:
return super(AssetModel, self).setData(index, value, role)


class RecursiveSortFilterProxyModel(QtCore.QSortFilterProxyModel):
"""Filters to the regex if any of the children matches allow parent"""
Expand Down
Loading