Skip to content

action_thumbnail_to_childern

ThumbToChildren

Bases: LocalAction

Source code in client/ayon_ftrack/event_handlers_user/action_thumbnail_to_childern.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class ThumbToChildren(LocalAction):
    identifier = "ayon.thumb.to.children"
    label = "Thumbnail"
    variant = " to Children"
    icon = get_ftrack_icon_url("Thumbnail.svg")

    def discover(self, session, entities, event):
        """Show only on project."""
        if entities and entities[0].entity_type != "Project":
            return True
        return False

    def launch(self, session, entities, event):
        user_id = event["source"]["user"]["id"]
        user = session.query(f"User where id is {user_id}").one()

        job = session.create("Job", {
            "user": user,
            "status": "running",
            "data": json.dumps({
                "description": "Push thumbnails to children"
            })
        })
        session.commit()
        try:
            for entity in entities:
                thumbnail_id = entity["thumbnail_id"]
                if thumbnail_id:
                    for child in entity["children"]:
                        child["thumbnail_id"] = thumbnail_id

            # inform the user that the job is done
            job["status"] = "done"
        except Exception as exc:
            session.rollback()
            # fail the job if something goes wrong
            job["status"] = "failed"
            raise exc
        finally:
            session.commit()

        return {
            "success": True,
            "message": "Created job for updating thumbnails!"
        }

discover(session, entities, event)

Show only on project.

Source code in client/ayon_ftrack/event_handlers_user/action_thumbnail_to_childern.py
12
13
14
15
16
def discover(self, session, entities, event):
    """Show only on project."""
    if entities and entities[0].entity_type != "Project":
        return True
    return False