diff --git a/openpype/plugins/load/add_site.py b/openpype/plugins/load/add_site.py index 860e0ef15e..f0c9887b66 100644 --- a/openpype/plugins/load/add_site.py +++ b/openpype/plugins/load/add_site.py @@ -40,16 +40,29 @@ class AddSyncSite(load.LoaderPlugin): return self._sync_server def load(self, context, name=None, namespace=None, data=None): + """"Adds site skeleton information on representation_id + + Looks for loaded containers for workfile, adds them site skeleton too + (eg. they should be downloaded too). + Handles hero versions (for representation_id and referenced subsets) + Args: + context (dict): + name (str): + namespace (str): + data (dict): expects {"site_name": SITE_NAME_TO_ADD} + """ # self.log wont propagate print("Adding {} to representation: {}".format( data["site_name"], data["_id"])) - family = context["representation"]["context"]["family"] - project_name = data["project_name"] - repre_id = data["_id"] + project_name = context["project"]["name"] + repre_doc = context["representation"] + family = repre_doc["context"]["family"] + repre_id = [repre_doc["_id"]] site_name = data["site_name"] representation_ids = self._add_hero_representation_ids(project_name, - repre_id) + repre_id, + repre_doc) for repre_id in representation_ids: self.sync_server.add_site(project_name, repre_id, site_name, @@ -79,20 +92,24 @@ class AddSyncSite(load.LoaderPlugin): """No real file loading""" return "" - def _add_hero_representation_ids(self, project_name, repre_id): + def _add_hero_representation_ids(self, project_name, repre_id, + repre_doc=None): """Find hero version if exists for repre_id. Args: project_name (str) repre_id (ObjectId) + repre_doc (dict): repre document for 'repre_id', might be collected + previously Returns: (list): at least [repre_id] if no hero version found """ representation_ids = [repre_id] - repre_doc = get_representation_by_id( - project_name, repre_id, fields=["_id", "parent", "name"] - ) + if not repre_doc: + repre_doc = get_representation_by_id( + project_name, repre_id, fields=["_id", "parent", "name"] + ) version_doc = get_version_by_id(project_name, repre_doc["parent"]) if version_doc["type"] != "hero_version": diff --git a/openpype/tools/loader/widgets.py b/openpype/tools/loader/widgets.py index faef6c8a26..dbf2feb624 100644 --- a/openpype/tools/loader/widgets.py +++ b/openpype/tools/loader/widgets.py @@ -1468,23 +1468,21 @@ class RepresentationWidget(QtWidgets.QWidget): repre_ids = [] data_by_repre_id = {} selected_side = action_representation.get("selected_side") + site_name = "{}_site_name".format(selected_side) is_sync_loader = tools_lib.is_sync_loader(loader) for item in items: - item_id = item.get("_id") - repre_ids.append(item_id) + repre_id = item["_id"] + repre_ids.append(repre_id) if not is_sync_loader: continue - site_name = "{}_site_name".format(selected_side) data_site_name = item.get(site_name) if not data_site_name: continue - data_by_repre_id[item_id] = { - "_id": item_id, - "site_name": data_site_name, - "project_name": self.dbcon.active_project() + data_by_repre_id[repre_id] = { + "site_name": data_site_name } repre_contexts = get_repres_contexts(repre_ids, self.dbcon) @@ -1574,8 +1572,8 @@ def _load_representations_by_loader(loader, repre_contexts, version_name = version_doc.get("name") try: if data_by_repre_id: - _id = repre_context["representation"]["_id"] - data = data_by_repre_id.get(_id) + repre_id = repre_context["representation"]["_id"] + data = data_by_repre_id.get(repre_id) options.update(data) load_with_repre_context( loader,