def refresh_shot_casting_stats(shot, priority_map=None): """ For all tasks related to given shot, it computes how many assets are available for this task and saves the result on the task level. """ if priority_map is None: priority_map = _get_task_type_priority_map(shot["project_id"]) casting = get_entity_casting(shot["id"]) tasks = Task.get_all_by(entity_id=shot["id"]) for task in tasks: nb_ready = 0 for asset in casting: if _is_asset_ready(asset, task, priority_map): nb_ready += 1 task.update({"nb_assets_ready": nb_ready}) events.emit( "task:update-casting-stats", { "task_id": str(task.id), "nb_assets_ready": nb_ready }, persist=False, project_id=shot["project_id"], )
def remove_person(person_id, force=True): person = Person.get(person_id) if force: for comment in Comment.get_all_by(person_id=person_id): remove_comment(comment.id) comments = Comment.query.filter( Comment.acknowledgements.contains(person) ) for comment in comments: comment.acknowledgements = [ member for member in comment.acknowledgements if str(member.id) != person_id ] comment.save() ApiEvent.delete_all_by(user_id=person_id) Notification.delete_all_by(person_id=person_id) SearchFilter.delete_all_by(person_id=person_id) DesktopLoginLog.delete_all_by(person_id=person_id) LoginLog.delete_all_by(person_id=person_id) Subscription.delete_all_by(person_id=person_id) TimeSpent.delete_all_by(person_id=person_id) for project in Project.query.filter(Project.team.contains(person)): project.team = [ member for member in project.team if str(member.id) != person_id ] project.save() for task in Task.query.filter(Task.assignees.contains(person)): task.assignees = [ assignee for assignee in task.assignees if str(assignee.id) != person_id ] task.save() for task in Task.get_all_by(assigner_id=person_id): task.update({"assigner_id": None}) for output_file in OutputFile.get_all_by(person_id=person_id): output_file.update({"person_id": None}) for working_file in WorkingFile.get_all_by(person_id=person_id): output_file.update({"person_id": None}) for task in WorkingFile.get_all_by(person_id=person_id): output_file.update({"person_id": None}) try: person.delete() events.emit("person:delete", {"person_id": person.id}) except IntegrityError: raise ModelWithRelationsDeletionException( "Some data are still linked to given person." ) return person.serialize_safe()
def patch_task_data(): """ Patch to run after upgrade from 0.9.8 or lower to 0.9.9 or superior. """ from zou.app.models.task import Task from zou.app.services import projects_service, deletion_service for project in projects_service.open_projects(): print("Cleaning tasks for project %s" % project["name"]) for task in Task.get_all_by(project_id=project["id"]): deletion_service.reset_task_data(task.id) print("Task cleaning done.")
def reset_tasks_data(project_id): for task in Task.get_all_by(project_id=project_id): reset_task_data(str(task.id))