Remus Avram

Members
  • Content Count

    486
  • Joined

  • Last visited

  • Days Won

    12

Posts posted by Remus Avram


  1. Thanks @Mattias Lagergren for you answer.

    But is it possible to manually re-register all the plugins from a folder?

    For example i am updating the code of a plugin. In this way the plugin will not be registered again and the new code will not be in use.

    On the Ftrack server side we are checking every X minutes if there is new code pushed, and if it is, then it is re-launching the actions.

    Is it possible to do something similar for the Ftrack-Connect?


  2. If I create a new version and then I query the asset again, then the new version is not included in the asset['versions'].

    Example:

    asset = session.query("Asset where versions.task.id is '{0}'".format(task['id'])).one()
    print len(asset['version'])
    
    session.create('AssetVersion',
                   {'asset': asset,
                    'task': task,
                    'version': 13,
                    'status': status,
                    }
                   )
    session.commit()
    
    asset = session.query("Asset where versions.task.id is '{0}'".format(task['id'])).one()
    print len(asset['version'])
    
    -------
    Returns
    2
    2

     


  3. Hi all,

    I have a shot queried from DB via ftrack_api. I update a custom attribute of the respective shot. Then, in the same session, I query the shot again.

    The custom attribute of the respective shot is not updated even after I queried the shot again.

    Please find below an example:

        def test_query_custom_attributes(self):
    
            def update_custom_attribute(test_asset):
                new_session = ftrack_api.Session()
                same_test_asset = new_session.query("AssetBuild where id is '{0}'".format(test_asset["id"])).one()
                same_test_asset['custom_attributes']['delivery_name'] = "unittest"
                new_session.commit()
    
            test_asset = self._session.query("AssetBuild").first()
            delivery_name = test_asset['custom_attributes']['delivery_name']
    
            update_custom_attribute(test_asset)
    
            test_asset = self._session.query("AssetBuild where id is '{0}'".format(test_asset["id"])).one()
            new_delivery_name = test_asset['custom_attributes']['delivery_name']
    
            self.assertNotEqual(delivery_name, new_delivery_name)
    
            self._session.cache.clear()
            test_asset = self._session.query("AssetBuild where id is '{0}'".format(test_asset["id"])).one()
            new_delivery_name = test_asset['custom_attributes']['delivery_name']
            self.assertNotEqual(delivery_name, new_delivery_name)

    Clearing the cache and fetching the shot again from the database works.


  4. No, It doesn't. 

    Instead clearing the cache and querying the data again works.

    > print len(user['user_security_roles'])
    2
    > del user['user_security_roles']
    > user = get_ftrack_user(username="unittest_artist")
    > print len(user['user_security_roles'])
    2
    > session.cache.clear()
    > user = get_ftrack_user(username="unittest_artist")
    > print len(user['user_security_roles'])
    1

     


  5. As a workaround we run a script every X minutes which adds the uses added only to the groups to the project, too.

    """
    @package bin.check_projects_members
    @brief Check if the members of the projects have been added to the project.
    @details If the user has been added to the project group, but not to the project,
             then we need to add him/her to the project
    
    @author remusav
    """
    import logging
    import ftrack_session_manager
    
    
    log = logging.module_logger(__name__)
    session = ftrack_session_manager.main_session
    
    
    def get_grouped_users(project):
        """
        @param project: Ftrack Project
        @return list() of all grouped users from the project
        """
        grouped_users = []
        for allocation in project['allocations']:
            user_or_group = allocation['resource']
            if user_or_group.entity_type == "Group":
                for membership in user_or_group['memberships']:
                    grouped_users.append(membership['user'])
        return grouped_users
    
    
    def get_project_users(project):
        """
        @param project: Ftrack Project
        @return list() of all users added to the project
        """
        users = []
        for allocation in project['allocations']:
            user_or_group = allocation['resource']
            if user_or_group.entity_type == "User":
                users.append(user_or_group)
        return users
    
    
    def add_user_to_project(user, project):
        """
        Add the user to the Ftrack project
        @param user: Ftrack user
        @param project: Ftrack project
        """
        try:
            session.create("Appointment",
                           {"context": project,
                            "resource": user,
                            "type": "allocation"
                            })
            session.commit()
            log.info("user '{0}' added to project '{1}'".format(user['username'], project['name']))
        except Exception, e:
            session.rollback()
            log.error("user '{0}' couldn't be added to project '{1}'".format(user['username'], project['name']))
            log.error(e)
    
    
    def main():
        """
        Main function.
        """
        projects = session.query("Project where status is 'active'").all()
        for project in projects:
            grouped_users = get_grouped_users(project=project)
            project_users = get_project_users(project=project)
            users_not_assigned_to_project = set(grouped_users) - set(project_users)
    
            for user in users_not_assigned_to_project:
                add_user_to_project(user, project)
    
    
    if __name__ == '__main__':
        main()

     


  6. Hi all,

    is it possible to send custom notifications via ftrack_api?

    We are automating a lot with actions. But this creates also a lot of confusion. We need to communicate better to the users. We are using the pop up messages, but these are displayed only for 5 seconds. Sometimes the user is missing them, sometimes the message is going away before he/she finishes reading it.

    Sending notifications to the user will help a lot in understanding what is happening.


  7. Hi all,

    how can I assign a user to a project via ftrack_api?

    I tried with:

            session.create("Appointment",
                           {"context": project,
                            "resource": user,
                            "type": "assignment"
                            })
            session.commit()

    but I get the following error:

    Server reported error: ValidationError(Appointment of type "assignment" cannot be created for "user" and "show")

     

    But if I get an existing appointment of a project and inspect the data:

    (Pdb) for k in allocation.keys():print k, ': ', allocation[k]
    resource :  <User(55095a4c-4839-11e6-a626-005056a745dd)>
    resource_id :  55095a4c-4839-11e6-a626-005056a745dd
    context_id :  28d104b6-8be5-11e7-a763-005056a745de
    context :  <Project(28d104b6-8be5-11e7-a763-005056a745de)>
    type :  allocation
    id :  0b60299c-a469-11e7-aa6e-005056a745de

    the context is a project and the resource is a user.