def test_sync_event(self): sync_service.sync_event({ "name": "project:new", "data": { "project_id": self.new_project_id } }) self.assertIsNotNone(Project.get(self.new_project_id)) sync_service.sync_event({ "name": "project:delete", "data": { "project_id": self.new_project_id } }) self.assertIsNone(Project.get(self.new_project_id))
def task_to_review(task_id, person, comment, preview_path=""): task = get_task_raw(task_id) to_review_status = get_to_review_status() task_dict_before = task.serialize() task.update({"task_status_id": to_review_status["id"]}) task.save() project = Project.get(task.project_id) entity = Entity.get(task.entity_id) entity_type = EntityType.get(entity.entity_type_id) task_dict_after = task.serialize() task_dict_after["project"] = project.serialize() task_dict_after["entity"] = entity.serialize() task_dict_after["entity_type"] = entity_type.serialize() task_dict_after["person"] = person task_dict_after["comment"] = comment task_dict_after["preview_path"] = preview_path events.emit("task:to-review", { "task_before": task_dict_before, "task_after": task_dict_after }) return task_dict_after
def test_project(self): project_id = "d98a6269-e566-4e11-b29f-b3faa2039d79" project_name = "Caminandes" Project.create_from_import({ "team": [str(self.person.id)], "id": project_id, "created_at": "2019-06-20T12:28:16", "updated_at": "2019-08-30T12:48:09", "name": project_name, "has_avatar": True, "fps": "25", "production_type": "tvshow", "start_date": "2019-07-01", "end_date": "2021-12-31", "project_status_id": str(self.open_status.id), "type": "Project" }) project = Project.get(project_id) self.assertEqual(project.name, project_name)
def task_to_review(task_id, person, comment, preview_path=""): """ Change the task status to "waiting for approval" if it is not already the case. It emits a *task:to-review* event. Change the real start date time to now. """ task = get_task_raw(task_id) to_review_status = get_to_review_status() task_dict_before = task.serialize() task.update({"task_status_id": to_review_status["id"]}) task.save() project = Project.get(task.project_id) entity = Entity.get(task.entity_id) entity_type = EntityType.get(entity.entity_type_id) task_dict_after = task.serialize() task_dict_after["project"] = project.serialize() task_dict_after["entity"] = entity.serialize() task_dict_after["entity_type"] = entity_type.serialize() task_dict_after["person"] = person task_dict_after["comment"] = comment task_dict_after["preview_path"] = preview_path events.emit("task:to-review", { "task_before": task_dict_before, "task_after": task_dict_after }) return task_dict_after
def to_review_task(task, output_file_dict): to_review_status = get_to_review_status() task_dict_before = task.serialize() task.update({"task_status_id": to_review_status.id}) task.save() project = Project.get(task.project_id) entity = Entity.get(task.entity_id) entity_type = EntityType.get(entity.entity_type_id) person = Person.get(output_file_dict["person_id"]) task_dict_after = task.serialize() task_dict_after["output_file"] = output_file_dict task_dict_after["project"] = project.serialize() task_dict_after["entity"] = entity.serialize() task_dict_after["entity_type"] = entity_type.serialize() task_dict_after["person"] = person.serialize() events.emit("task:to-review", { "task_before": task_dict_before, "task_after": task_dict_after }) return task
def get_full_asset(asset_id): """ Return asset matching given id with additional information (project name, asset type name and tasks). """ asset = get_asset(asset_id) asset_type = get_asset_type(asset["entity_type_id"]) project = Project.get(asset["project_id"]) asset["project_name"] = project.name asset["asset_type_id"] = asset_type["id"] asset["asset_type_name"] = asset_type["name"] tasks = Task.query \ .filter_by(entity_id=asset_id) \ .all() task_dicts = [] for task in tasks: task_dicts.append({ "id": str(task.id), "task_status_id": str(task.task_status_id), "task_type_id": str(task.task_type_id), "assignees": [str(assignee.id) for assignee in task.assignees] }) asset["tasks"] = task_dicts return asset
def get_full_shot(shot_id): shot = get_shot(shot_id) sequence = Entity.get(shot["parent_id"]) project = Project.get(shot["project_id"]) shot["project_name"] = project.name shot["sequence_id"] = str(sequence.id) shot["sequence_name"] = sequence.name if sequence.parent_id is not None: episode = Entity.get(sequence.parent_id) shot["episode_id"] = str(episode.id) shot["episode_name"] = episode.name tasks = Task.query \ .filter_by(entity_id=shot_id) \ .all() task_dicts = [] for task in tasks: task_dicts.append({ "id": str(task.id), "task_status_id": str(task.task_status_id), "task_type_id": str(task.task_type_id), "assignees": [str(assignee.id) for assignee in task.assignees] }) shot["tasks"] = task_dicts return shot
def get_full_asset(asset_id): asset = get_asset(asset_id) asset_type = get_asset_type_raw(asset["entity_type_id"]) project = Project.get(asset["project_id"]) asset["project_name"] = project.name asset["asset_type_id"] = str(asset_type.id) asset["asset_type_name"] = asset_type.name tasks = Task.query \ .filter_by(entity_id=asset_id) \ .all() task_dicts = [] for task in tasks: task_dicts.append({ "id": str(task.id), "task_status_id": str(task.task_status_id), "task_type_id": str(task.task_type_id), "assignees": [str(assignee.id) for assignee in task.assignees] }) asset["tasks"] = task_dicts return asset
def save(self): self.generate_fixture_project_status() project = self.generate_fixture_project() project.name = "new name" project.save() project = Project.get(project.id) self.assertEqual(project.name, "new name")
def test_create_entry(self): events.register("project:new", "handle_event", self) create_func = sync_service.create_entry("projects", "project", Project, "new") create_func({"project_id": self.new_project_id}) self.assertTrue("project_id" in self.last_event_data) self.assertIsNotNone(Project.get(self.last_event_data["project_id"])) self.last_event_data = {} events.unregister_all() events.register("project:update", "handle_event", self) create_func = sync_service.create_entry("projects", "project", Project, "update") create_func({"project_id": self.new_project_id}) self.assertTrue("project_id" in self.last_event_data) project = Project.get(self.last_event_data["project_id"]) self.assertEqual(project.name, "Test Sync Project")
def update(self): self.generate_fixture_project_status() project = self.generate_fixture_project() project.update({ "name": "new name" }) project = Project.get(project.id) self.assertEqual(project.name, "new name")
def test_get_open_projects(self): projects = self.get("data/user/projects/open") self.assertEquals(len(projects), 0) project = Project.get(self.project_id) project.team.append(self.user) project.save() projects = self.get("data/user/projects/open") self.assertEquals(len(projects), 1) project = Project.get(self.project_id) project.team[:] = [] project.save() projects = self.get("data/user/projects/open") self.assertEquals(len(projects), 0)
def get_project_from_preview_file(preview_file_id): """ Get project dict of related preview file. """ preview_file = files_service.get_preview_file_raw(preview_file_id) task = Task.get(preview_file.task_id) project = Project.get(task.project_id) return project.serialize()
def test_delete_project(self): projects = self.get("data/projects") self.assertEqual(len(projects), 3) project = projects[0] self.delete("data/projects/%s" % project["id"], 400) self.generate_fixture_project_closed_status() self.generate_fixture_project_closed() self.delete("data/projects/%s" % self.project_closed.id) self.assertIsNone(Project.get(self.project_closed.id))
def get_project(project_id): try: project = Project.get(project_id) except StatementError: raise ProjectNotFoundException() if project is None: raise ProjectNotFoundException() return project
def get_full_sequence(sequence_id): sequence = get_sequence(sequence_id) project = Project.get(sequence["project_id"]) sequence["project_name"] = project.name if sequence["parent_id"] is not None: episode = Entity.get(sequence["parent_id"]) sequence["episode_id"] = str(episode.id) sequence["episode_name"] = episode.name return sequence
def get_comment_mentions(object_id, text): """ Check for people mention (@full name) in text and returns matching person active records. """ task = tasks_service.get_task_raw(object_id) project = Project.get(task.project_id) mentions = [] for person in project.team: if re.search("@%s( |$)" % person.full_name(), text) is not None: mentions.append(person) return mentions
def test_delete_project(self): self.generate_fixture_asset_type() self.generate_fixture_asset_types() self.generate_assigned_task() self.generate_fixture_episode() self.generate_fixture_sequence() self.generate_fixture_shot() breakdown_service.create_casting_link(self.shot.id, self.asset.id) project_id = str(self.project.id) deletion_service.remove_project(project_id) self.assertIsNone(Project.get(project_id))
def get_project_raw(project_id): """ Get project matching given id, as active record. Raises an exception if project is not found. """ try: project = Project.get(project_id) except StatementError: raise ProjectNotFoundException() if project is None: raise ProjectNotFoundException() return project
def task_to_review(task_id, person, comment, preview_path={}, change_status=True): """ Deprecated Change the task status to "waiting for approval" if it is not already the case. It emits a *task:to-review* event. """ task = get_task_raw(task_id) to_review_status = get_to_review_status() task_dict_before = task.serialize() if change_status: task.update({"task_status_id": to_review_status["id"]}) task.save() clear_task_cache(task_id) project = Project.get(task.project_id) entity = Entity.get(task.entity_id) entity_type = EntityType.get(entity.entity_type_id) task_dict_after = task.serialize() task_dict_after["project"] = project.serialize() task_dict_after["entity"] = entity.serialize() task_dict_after["entity_type"] = entity_type.serialize() task_dict_after["person"] = person task_dict_after["comment"] = comment task_dict_after["preview_path"] = preview_path events.emit( "task:to-review", { "task_id": task_id, "task_shotgun_id": task_dict_before["shotgun_id"], "entity_type_name": entity_type.name, "previous_task_status_id": task_dict_before["task_status_id"], "entity_shotgun_id": entity.shotgun_id, "project_shotgun_id": project.shotgun_id, "person_shotgun_id": person["shotgun_id"], "comment": comment, "preview_path": preview_path, "change_status": change_status, }, ) return task_dict_after
def get_full_asset(asset_id): """ Return asset matching given id with additional information (project name, asset type name and tasks). """ assets = get_assets_and_tasks({"id": asset_id}) if len(assets) > 0: asset = get_asset_with_relations(asset_id) asset_type_id = asset["entity_type_id"] asset_type = get_asset_type(asset_type_id) project = Project.get(asset["project_id"]) asset["project_name"] = project.name asset["asset_type_id"] = asset_type["id"] asset["asset_type_name"] = asset_type["name"] asset.update(assets[0]) return asset else: raise AssetNotFoundException
def test_add_thumbnail(self): project_id = str(self.project.id) path = "/pictures/thumbnails/projects/%s" % project_id file_path_fixture = self.get_fixture_file_path( os.path.join("thumbnails", "th01.png")) self.upload_file(path, file_path_fixture) path = "/pictures/thumbnails/projects/%s.png" % project_id current_path = os.path.dirname(__file__) result_file_path = os.path.join(TEST_FOLDER, "th01.png") result_file_path = os.path.join(current_path, "..", "..", result_file_path) os.mkdir(TEST_FOLDER) self.download_file(path, result_file_path) result_image = Image.open(result_file_path) self.assertEqual(result_image.size, thumbnail.SQUARE_SIZE) project = Project.get(project_id) self.assertTrue(project.has_avatar)
def remove_project(project_id): from zou.app.services import playlists_service tasks = Task.query.filter_by(project_id=project_id) for task in tasks: remove_task(task.id, force=True) query = EntityLink.query.join(Entity, EntityLink.entity_in_id == Entity.id).filter( Entity.project_id == project_id) for link in query: link.delete_no_commit() EntityLink.commit() query = EntityVersion.query.join( Entity, EntityVersion.entity_id == Entity.id).filter( Entity.project_id == project_id) for version in query: version.delete_no_commit() EntityLink.commit() playlists = Playlist.query.filter_by(project_id=project_id) for playlist in playlists: playlists_service.remove_playlist(playlist.id) ApiEvent.delete_all_by(project_id=project_id) Entity.delete_all_by(project_id=project_id) MetadataDescriptor.delete_all_by(project_id=project_id) Milestone.delete_all_by(project_id=project_id) ScheduleItem.delete_all_by(project_id=project_id) SearchFilter.delete_all_by(project_id=project_id) for news in News.query.join(Task).filter_by(project_id=project_id).all(): news.delete_no_commit() News.commit() project = Project.get(project_id) project.delete() events.emit("project:delete", {"project_id": project.id}) return project_id
def get(self, instance_id): try: task = task_info.get_task(instance_id) except TaskNotFoundException: abort(404) result = task.serialize() task_type = TaskType.get(task.task_type_id) result["task_type"] = task_type.serialize() assigner = Person.get(task.assigner_id) result["assigner"] = assigner.serialize() project = Project.get(task.project_id) result["project"] = project.serialize() task_status = TaskStatus.get(task.task_status_id) result["task_status"] = task_status.serialize() entity = Entity.get(task.entity_id) result["entity"] = entity.serialize() assignees = [] for assignee in task.assignees: assignees.append(assignee.serialize()) result["persons"] = assignees return result, 200
def get_full_episode(episode_id): episode = get_episode(episode_id) project = Project.get(episode["project_id"]) episode["project_name"] = project.name return episode
def get_project(entity): return Project.get(entity.project_id)
def assign_user(self, task_id): tasks_service.assign_task(task_id, self.user.id) project = Project.get(self.project_id) project.team.append(self.user) project.save()
def test_get(self): self.generate_fixture_project_status() project_id = self.generate_fixture_project().id project = Project.get(project_id) self.assertEqual(project.id, project_id)
def delete(self): self.generate_fixture_project_status() project = self.generate_fixture_project() project.delete() project = Project.get(project.id) self.assertIsNone(project)
def assign_user(self, task_id): tasks_service.assign_task(task_id, self.user_id) project = Project.get(self.project_id) person = Person.get(self.user_id) project.team.append(person) project.save()