コード例 #1
0
ファイル: entities_service.py プロジェクト: ricekab/zou
def remove_entity_link(link_id):
    try:
        link = EntityLink.get_by(id=link_id)
        link.delete()
        return link.serialize()
    except:
        raise EntityLinkNotFoundException
コード例 #2
0
def create_casting_link(entity_in_id, asset_id, nb_occurences=1, label=""):
    """
    Add a link between given entity and given asset.
    """
    link = EntityLink.get_by(entity_in_id=entity_in_id, entity_out_id=asset_id)
    entity = entities_service.get_entity(entity_in_id)
    project_id = str(entity["project_id"])
    if link is None:
        link = EntityLink.create(
            entity_in_id=entity_in_id,
            entity_out_id=asset_id,
            nb_occurences=nb_occurences,
            label=label,
        )
        events.emit("entity-link:new", {
            "entity_link_id": link.id,
            "entity_in_id": link.entity_in_id,
            "entity_out_id": link.entity_out_id,
            "nb_occurences": nb_occurences
        },
                    project_id=project_id)
    else:
        link.update({"nb_occurences": nb_occurences, "label": label})
        events.emit("entity-link:update", {
            "entity_link_id": link.id,
            "nb_occurences": nb_occurences
        },
                    project_id=project_id)
    return link
コード例 #3
0
def get_entity_link_raw(entity_in_id, entity_out_id):
    """
    Get link matching given entities.
    """
    link = EntityLink.get_by(entity_in_id=entity_in_id,
                             entity_out_id=entity_out_id)
    return link
コード例 #4
0
def get_entity_link(entity_in_id, entity_out_id):
    """
    Get link matching given entities.
    """
    link = EntityLink.get_by(entity_in_id=entity_in_id,
                             entity_out_id=entity_out_id)
    if link:
        return link.serialize()
    else:
        return None
コード例 #5
0
 def test_entity_link(self):
     entity_link_dict = {
         "id": "726f9b44-526f-4fce-a979-6bf8bc8962a4",
         "created_at": "2019-06-28T09:47:42",
         "updated_at": "2019-06-28T09:47:42",
         "entity_in_id": str(self.shot.id),
         "entity_out_id": str(self.asset.id),
         "nb_occurences": 1,
         "label": "animation",
         "type": "EntityLink"
     }
     EntityLink.create_from_import(entity_link_dict)
     entity_link = EntityLink.get_by(id=entity_link_dict["id"])
     self.assertEqual(entity_link_dict["label"], entity_link.label)
コード例 #6
0
def create_casting_link(entity_in_id, asset_id, nb_occurences=1, label=""):
    """
    Add a link between given entity and given asset.
    """
    link = EntityLink.get_by(entity_in_id=entity_in_id, entity_out_id=asset_id)
    if link is None:
        link = EntityLink.create(
            entity_in_id=entity_in_id,
            entity_out_id=asset_id,
            nb_occurences=nb_occurences,
            label=label,
        )
    else:
        link.update({"nb_occurences": nb_occurences, "label": label})
    return link
コード例 #7
0
ファイル: test_import_casting.py プロジェクト: cgwire/zou
    def test_import_casting_twice(self):
        path = "/import/csv/projects/%s/casting" % self.project_id
        self.upload_csv(path, "casting")
        path = "/import/csv/projects/%s/casting" % self.project_id
        self.upload_csv(path, "casting")
        links = EntityLink.query.all()
        self.assertEqual(len(links), 18)
        self.assertEqual(get_shot(self.e01seq01sh01_id)["nb_entities_out"], 2)

        path = "/import/csv/projects/%s/casting" % self.project_id
        self.upload_csv(path, "casting_02")
        links = EntityLink.query.all()
        self.assertEqual(len(links), 18)
        link = EntityLink.get_by(
            entity_in_id=self.e01seq01sh01_id,
            entity_out_id=self.asset_victor_id,
        )
        self.assertEqual(link.label, "fixed")
        self.assertEqual(get_shot(self.e01seq01sh01_id)["nb_entities_out"], 2)
コード例 #8
0
def _create_episode_casting_link(entity, asset_id, nb_occurences=1, label=""):
    """
    When an asset is casted in a shot, the asset is automatically casted in
    the episode.
    """
    if shots_service.is_shot(entity):
        sequence = shots_service.get_sequence(entity["parent_id"])
        if sequence["parent_id"] is not None:
            link = EntityLink.get_by(entity_in_id=sequence["parent_id"],
                                     entity_out_id=asset_id)
            if link is None:
                link = EntityLink.create(
                    entity_in_id=sequence["parent_id"],
                    entity_out_id=asset_id,
                    nb_occurences=1,
                    label=label,
                )
                events.emit(
                    "asset:update",
                    {"asset_id": asset_id},
                    project_id=entity["project_id"],
                )
    return entity