def get_temporal_type_ids(): shot_type = shots_service.get_shot_type() if shot_type is None: cache.cache.delete_memoized(shots_service.get_shot_type) shot_type = shots_service.get_shot_type() scene_type = shots_service.get_scene_type() if scene_type is None: cache.cache.delete_memoized(shots_service.get_scene_type) scene_type = shots_service.get_scene_type() sequence_type = shots_service.get_sequence_type() if sequence_type is None: cache.cache.delete_memoized(shots_service.get_sequence_type) sequence_type = shots_service.get_sequence_type() episode_type = shots_service.get_episode_type() if episode_type is None: cache.cache.delete_memoized(shots_service.get_episode_type) episode_type = shots_service.get_episode_type() ids_to_exclude = [shot_type["id"], sequence_type["id"], episode_type["id"]] if scene_type is not None: ids_to_exclude.append(scene_type["id"]) return ids_to_exclude
def init_data(): projects_service.get_open_status() projects_service.get_closed_status() print("Project status initialized.") assets_service.get_or_create_type("Characters") assets_service.get_or_create_type("Props") assets_service.get_or_create_type("Environment") assets_service.get_or_create_type("FX") assets_service.get_or_create_type("Camera") print("Asset types initialized.") shots_service.get_episode_type() shots_service.get_sequence_type() shots_service.get_shot_type() print("Shot types initialized.") modeling = tasks_service.get_or_create_department("Modeling") animation = tasks_service.get_or_create_department("Animation") fx = tasks_service.get_or_create_department("FX") compositing = tasks_service.get_or_create_department("Compositing") concept = tasks_service.get_or_create_department("Concept") layout = tasks_service.get_or_create_department("Layout") tasks_service.get_or_create_task_type(concept, "Concept", "#8D6E63", 1) tasks_service.get_or_create_task_type(modeling, "Texture", "#64B5F6", 2) tasks_service.get_or_create_task_type(modeling, "Modeling", "#78909C", 3) tasks_service.get_or_create_task_type(animation, "Setup", "#9CCC65", 4) tasks_service.get_or_create_task_type(concept, "Storyboard", "#43A047", 1, True) tasks_service.get_or_create_task_type(layout, "Layout", "#7CB342", 2, True) tasks_service.get_or_create_task_type(animation, "Animation", "#009688", 3, True) tasks_service.get_or_create_task_type(compositing, "Lighting", "#F9A825", 4, True) tasks_service.get_or_create_task_type(fx, "FX", "#26C6DA", 5, True) tasks_service.get_or_create_task_type(compositing, "Render", "#F06292", 6, True) tasks_service.get_or_create_task_type(compositing, "Compositing", "#ff5252", 7, True) print("Task types initialized.") tasks_service.get_or_create_status("Todo", "todo", "#f5f5f5") tasks_service.get_or_create_status("Work In Progress", "wip", "#3273dc") tasks_service.get_or_create_status("Waiting For Approval", "wfa", "#ab26ff", is_reviewable=True) tasks_service.get_or_create_status("Retake", "retake", "#ff3860", is_reviewable=True) tasks_service.get_or_create_status("Done", "done", "#22d160", is_done=True) print("Task status initialized.")
def guess_shot(project, episode_name, sequence_name, shot_name): episode_id = None if len(episode_name) > 0: episode = Entity.get_by( name=episode_name, entity_type_id=shots_service.get_episode_type()["id"], project_id=project["id"], ) if episode is not None: episode_id = episode.id sequence_id = None if len(sequence_name) > 0: sequence = Entity.get_by( name=sequence_name, entity_type_id=shots_service.get_sequence_type()["id"], parent_id=episode_id, project_id=project["id"], ) if sequence is not None: sequence_id = sequence.id else: sequence_id = None if len(shot_name) > 0: shot = Entity.get_by( name=shot_name, entity_type_id=shots_service.get_shot_type()["id"], parent_id=sequence_id, project_id=project["id"], ) else: raise WrongPathFormatException("Shot name was not found in given path") return shot
def extract_data(self, sg_shot): (frame_in, frame_out) = self.extract_frame_range(sg_shot) custom_fields = self.extract_custom_data(sg_shot) project_id = self.get_project(sg_shot, self.project_map) sequence_id = self.get_sequence(sg_shot) scene_id = self.get_scene(sg_shot) assets = self.extract_assets(sg_shot) shot_type = shots_service.get_shot_type() data = { "name": sg_shot["code"], "shotgun_id": sg_shot["id"], "project_id": project_id, "entity_type_id": shot_type["id"], "parent_id": sequence_id, "source_id": scene_id, "entities_out": assets } data_field_content = { "frame_in": frame_in, "frame_out": frame_out, } custom_fields.update(data_field_content) data["data"] = custom_fields return data
def get_project_episodes(project_id): """ Return all episodes for given project and for which current user has a task assigned to a shot. """ shot_type = shots_service.get_shot_type() sequence_type = shots_service.get_sequence_type() episode_type = shots_service.get_episode_type() Shot = aliased(Entity, name="shot") Sequence = aliased(Entity, name="sequence") query = ( Entity.query.join(Sequence, Sequence.parent_id == Entity.id) .join(Shot, Shot.parent_id == Sequence.id) .join(Task, Task.entity_id == Shot.id) .join(Project, Project.id == Entity.project_id) .join(ProjectStatus) .filter(Shot.entity_type_id == shot_type["id"]) .filter(Sequence.entity_type_id == sequence_type["id"]) .filter(Entity.entity_type_id == episode_type["id"]) .filter(Project.id == project_id) .filter(build_assignee_filter()) .filter(build_open_project_filter()) ) return Entity.serialize_list(query.all(), obj_type="Episode")
def get_sequence_shots(sequence_id): shot_type = shots_service.get_shot_type() query = Entity.query \ .join(Task, Project, ProjectStatus, EntityType) \ .filter(Entity.entity_type_id == shot_type["id"]) \ .filter(Entity.parent_id == sequence_id) \ .filter(assignee_filter()) \ .filter(open_project_filter()) return Entity.serialize_list(query.all(), obj_type="Shot")
def get_assets(criterions={}): shot_type = shots_service.get_shot_type() scene_type = shots_service.get_scene_type() sequence_type = shots_service.get_sequence_type() episode_type = shots_service.get_episode_type() query = Entity.query.filter_by(**criterions) result = query.filter(~Entity.entity_type_id.in_([ shot_type["id"], scene_type["id"], sequence_type["id"], episode_type["id"] ])).all() return EntityType.serialize_list(result, obj_type="Asset")
def get_shots_for_sequence(sequence_id): """ Get all shots for given sequence and for which the user has a task assigned. """ shot_type = shots_service.get_shot_type() query = (Entity.query.join( Task, Project, ProjectStatus, EntityType).filter(Entity.entity_type_id == shot_type["id"]).filter( Entity.parent_id == sequence_id).filter( build_assignee_filter()).filter(build_open_project_filter())) return Entity.serialize_list(query.all(), obj_type="Shot")
def is_asset_type(asset_type): shot_type = shots_service.get_shot_type() sequence_type = shots_service.get_sequence_type() scene_type = shots_service.get_scene_type() episode_type = shots_service.get_episode_type() return str(asset_type.id) not in [ shot_type["id"], sequence_type["id"], scene_type["id"], episode_type["id"], ]
def is_asset(entity): shot_type = shots_service.get_shot_type() sequence_type = shots_service.get_sequence_type() scene_type = shots_service.get_scene_type() episode_type = shots_service.get_episode_type() return str(entity.entity_type_id) not in [ shot_type["id"], scene_type["id"], sequence_type["id"], episode_type["id"], ]
def update_metadata_descriptor(metadata_descriptor_id, changes): """ Update metadata descriptor information for given id. """ descriptor = get_metadata_descriptor_raw(metadata_descriptor_id) if "name" in changes and len(changes["name"]) > 0: changes["field_name"] = slugify.slugify(changes["name"]) if descriptor.field_name != changes["field_name"]: query = Entity.query.filter( Entity.project_id == descriptor.project_id) if descriptor.entity_type == "Shot": shot_type = shots_service.get_shot_type() query = query.filter(Entity.entity_type_id == shot_type["id"]) elif descriptor.entity_type == "Asset": query = query.filter(assets_service.build_asset_type_filter()) elif descriptor.entity_type == "Edit": edit_type = edits_service.get_edit_type() query = query.filter(Entity.entity_type_id == edit_type["id"]) entities = query.all() for entity in entities: metadata = fields.serialize_value(entity.data) or {} value = metadata.pop(descriptor.field_name, None) if value is not None: metadata[changes["field_name"]] = value entity.update_no_commit({"data": metadata}) Entity.commit() if "departments" in changes: if not changes["departments"]: changes["departments"] = [] try: departments_objects = [ Department.get(department_id) for department_id in changes["departments"] if department_id is not None ] except StatementError: raise DepartmentNotFoundException() changes["departments"] = departments_objects descriptor.update(changes) events.emit( "metadata-descriptor:update", {"metadata_descriptor_id": str(descriptor.id)}, project_id=descriptor.project_id, ) clear_project_cache(str(descriptor.project_id)) return descriptor.serialize()
def build_entity_type_asset_type_filter(): """ Generate a query filter to filter entity types that are asset types (it means not shot, not sequence, not episode and not scene) """ shot_type = shots_service.get_shot_type() scene_type = shots_service.get_scene_type() sequence_type = shots_service.get_sequence_type() episode_type = shots_service.get_episode_type() return ~EntityType.id.in_([ shot_type["id"], scene_type["id"], sequence_type["id"], episode_type["id"] ])
def get_asset_types(criterions={}): shot_type = shots_service.get_shot_type() sequence_type = shots_service.get_sequence_type() episode_type = shots_service.get_episode_type() scene_type = shots_service.get_scene_type() asset_type_filter = ~EntityType.id.in_([ shot_type["id"], sequence_type["id"], episode_type["id"], scene_type["id"], ]) query = EntityType.query \ .filter_by(**criterions) \ .filter(asset_type_filter) return EntityType.serialize_list(query.all(), obj_type="AssetType")
def is_asset_type(entity_type): """ Returns true if given entity type is an asset, not a shot. """ shot_type = shots_service.get_shot_type() sequence_type = shots_service.get_sequence_type() scene_type = shots_service.get_scene_type() episode_type = shots_service.get_episode_type() return str(entity_type.id) not in [ shot_type["id"], sequence_type["id"], scene_type["id"], episode_type["id"], ]
def build_main_pack_results(self, project_id): results = [] ParentAsset = aliased(Entity, name="parent_asset") ParentAssetType = aliased(EntityType, name="parent_asset_type") Asset = aliased(Entity, name="asset") AssetType = aliased(EntityType, name="asset_type") shot_type = shots_service.get_shot_type() episode_type = shots_service.get_episode_type() query = (EntityLink.query.join( ParentAsset, EntityLink.entity_in_id == ParentAsset.id).join( ParentAssetType, ParentAsset.entity_type_id == ParentAssetType.id, ).join(Asset, EntityLink.entity_out_id == Asset.id).join( AssetType, Asset.entity_type_id == AssetType.id).filter( ParentAsset.project_id == project_id).filter( ParentAsset.source_id == None).filter( ParentAssetType.id != shot_type["id"]).filter( ParentAssetType.id != episode_type["id"])) query = query.add_columns( ParentAssetType.name, ParentAsset.name, AssetType.name, Asset.name, ).order_by( ParentAssetType.name, ParentAsset.name, AssetType.name, Asset.name, ) for ( entity_link, parent_asset_type_name, parent_name, asset_type_name, asset_name, ) in query.all(): results.append(( "MP", "", parent_asset_type_name, parent_name, asset_type_name, asset_name, entity_link.nb_occurences, entity_link.label, )) return results
def is_asset_dict(entity): """ Returns true if given entity is an asset, not a shot. It supposes that the entity is represented as a dict. """ shot_type = shots_service.get_shot_type() sequence_type = shots_service.get_sequence_type() scene_type = shots_service.get_scene_type() episode_type = shots_service.get_episode_type() return entity["entity_type_id"] not in [ shot_type["id"], scene_type["id"], sequence_type["id"], episode_type["id"], ]
def import_row(self, row, project_id): episode_name = row["Episode"] sequence_name = row["Sequence"] shot_name = row["Name"] description = row["Description"] frame_in = row["Frame In"] frame_out = row["Frame Out"] episode_key = "%s-%s" % (project_id, episode_name) if episode_key not in self.episodes: self.episodes[episode_key] = \ shots_service.get_or_create_episode(project_id, episode_name) sequence_key = "%s-%s-%s" % (project_id, episode_name, sequence_name) if sequence_key not in self.sequences: episode = self.episodes[episode_key] self.sequences[sequence_key] = \ shots_service.get_or_create_sequence( project_id, episode["id"], sequence_name ) sequence_id = self.get_id_from_cache(self.sequences, sequence_key) shot_type = shots_service.get_shot_type() try: entity = Entity.create( name=shot_name, description=description, project_id=project_id, parent_id=sequence_id, entity_type_id=shot_type["id"], data={ "frame_in": frame_in, "frame_out": frame_out } ) except IntegrityError: entity = Entity.get_by( name=shot_name, project_id=project_id, parent_id=sequence_id, entity_type_id=shot_type["id"] ) return entity.serialize()
def run_import(self, file_path, project_id): result = [] self.check_permissions() self.prepare_import() xml_file = etree.parse(file_path) root = xml_file.getroot() episode = shots_service.get_or_create_first_episode(project_id) shot_type = shots_service.get_shot_type() clips = root.iter('clipitem') for clip in clips: sequence_name = clip.find('name').text.split('_')[0] shot_name = clip.find('name').text.split('_')[1] start = clip.find('start').text end = clip.find('end').text if start == '-1': if clip.getprevious().tag == 'transitionitem': start = clip.getprevious().find('start').text if end == '-1': if clip.getnext().tag == 'transitionitem': end = clip.getnext().find('end').text duration = int(end) - int(start) self.sequences[sequence_name] = shots_service.get_or_create_sequence(project_id, episode['id'], sequence_name) sequence_id = self.get_id_from_cache(self.sequences, sequence_name) try: entity = Entity.create( name=shot_name, project_id=project_id, parent_id=sequence_id, entity_type_id=shot_type["id"], nb_frames=str(duration) ) except IntegrityError: entity = Entity.get_by( name=shot_name, project_id=project_id, parent_id=sequence_id, entity_type_id=shot_type["id"] ) result.append(entity.serialize()) return result
def get_project_sequences(project_id): shot_type = shots_service.get_shot_type() sequence_type = shots_service.get_sequence_type() Shot = aliased(Entity, name='shot') query = Entity.query \ .join(Shot, Shot.parent_id == Entity.id) \ .join(Task, Task.entity_id == Shot.id) \ .join(EntityType, EntityType.id == Entity.entity_type_id) \ .join(Project, Project.id == Entity.project_id) \ .join(ProjectStatus) \ .filter(Shot.entity_type_id == shot_type["id"]) \ .filter(Entity.entity_type_id == sequence_type["id"]) \ .filter(Project.id == project_id) \ .filter(assignee_filter()) \ .filter(open_project_filter()) return Entity.serialize_list(query.all(), obj_type="Sequence")
def import_entry(self, data): shot = Entity.get_by( shotgun_id=data["shotgun_id"], entity_type_id=shots_service.get_shot_type()["id"]) if shot is None: shot = Entity(**data) shot.save() current_app.logger.info("Shot created: %s" % shot) else: if shot.data is None: shot.data = {} shot.update(data) shot.data.update(data["data"]) shot.save() current_app.logger.info("Shot updated: %s" % shot) return shot
def get_sequences_for_project(project_id): """ Return all sequences for given project and for which current user has a task assigned to a shot. """ shot_type = shots_service.get_shot_type() sequence_type = shots_service.get_sequence_type() Shot = aliased(Entity, name='shot') query = Entity.query \ .join(Shot, Shot.parent_id == Entity.id) \ .join(Task, Task.entity_id == Shot.id) \ .join(EntityType, EntityType.id == Entity.entity_type_id) \ .join(Project, Project.id == Entity.project_id) \ .join(ProjectStatus) \ .filter(Shot.entity_type_id == shot_type["id"]) \ .filter(Entity.entity_type_id == sequence_type["id"]) \ .filter(Project.id == project_id) \ .filter(build_assignee_filter()) \ .filter(build_open_project_filter()) return Entity.serialize_list(query.all(), obj_type="Sequence")
def all_assets(criterions={}): shot_type = shots_service.get_shot_type() scene_type = shots_service.get_scene_type() sequence_type = shots_service.get_sequence_type() episode_type = shots_service.get_episode_type() query = Entity.query.filter_by(**criterions) query = query.filter(~Entity.entity_type_id.in_([ shot_type["id"], scene_type["id"], sequence_type["id"], episode_type["id"] ])) query = query.join(Project) query = query.join(EntityType) query = query.add_columns(Project.name) query = query.add_columns(EntityType.name) data = query.all() assets = [] for (asset_model, project_name, asset_type_name) in data: asset = asset_model.serialize(obj_type="Asset") asset["project_name"] = project_name asset["asset_type_name"] = asset_type_name assets.append(asset) return assets
def test_get_shot_type(self): shot_type = shots_service.get_shot_type() self.assertEqual(shot_type["name"], "Shot")
def prepare_import(self): self.scene_type = shots_service.get_shot_type() self.project_map = Project.get_id_map(field="name")
def import_row(self, row, project_id): if self.is_tv_show: episode_name = row["Episode"] sequence_name = row["Sequence"] shot_name = row["Name"] description = row["Description"] nb_frames = row.get("Nb Frames", None) or row.get("Frames", None) data = { "frame_in": row.get("Frame In", None) or row.get("In", None), "frame_out": row.get("Frame Out", None) or row.get("Out", None), "fps": row.get("FPS", None), } for name, field_name in self.descriptor_fields.items(): if name in row: data[field_name] = row[name] if self.is_tv_show: episode_key = "%s-%s" % (project_id, episode_name) if episode_key not in self.episodes: self.episodes[ episode_key] = shots_service.get_or_create_episode( project_id, episode_name) sequence_key = "%s-%s-%s" % ( project_id, episode_name, sequence_name, ) else: sequence_key = "%s-%s" % (project_id, sequence_name) if sequence_key not in self.sequences: if self.is_tv_show: episode = self.episodes[episode_key] self.sequences[ sequence_key] = shots_service.get_or_create_sequence( project_id, episode["id"], sequence_name) else: self.sequences[ sequence_key] = shots_service.get_or_create_sequence( project_id, None, sequence_name) sequence_id = self.get_id_from_cache(self.sequences, sequence_key) shot_type = shots_service.get_shot_type() entity = Entity.get_by( name=shot_name, project_id=project_id, parent_id=sequence_id, entity_type_id=shot_type["id"], ) if entity is None: try: if nb_frames is None or len(nb_frames) == 0: entity = Entity.create( name=shot_name, description=description, project_id=project_id, parent_id=sequence_id, entity_type_id=shot_type["id"], data=data, ) else: entity = Entity.create( name=shot_name, description=description, project_id=project_id, parent_id=sequence_id, entity_type_id=shot_type["id"], nb_frames=nb_frames, data=data, ) except IntegrityError: current_app.logger.error("Row import failed", exc_info=1) elif self.is_update: entity.update({ "description": description, "nb_frames": nb_frames, "data": data }) return entity.serialize()
def import_row(self, row, project_id): if self.is_tv_show: episode_name = row["Episode"] sequence_name = row["Sequence"] shot_name = row["Name"] description = row.get("Description", "") nb_frames = row.get("Nb Frames", None) or row.get("Frames", None) data = { "frame_in": row.get("Frame In", None) or row.get("In", None), "frame_out": row.get("Frame Out", None) or row.get("Out", None), "fps": row.get("FPS", None), } if self.is_tv_show: episode_key = "%s-%s" % (project_id, episode_name) if episode_key not in self.episodes: self.episodes[ episode_key ] = shots_service.get_or_create_episode( project_id, episode_name ) sequence_key = "%s-%s-%s" % ( project_id, episode_name, sequence_name, ) else: sequence_key = "%s-%s" % (project_id, sequence_name) if sequence_key not in self.sequences: if self.is_tv_show: episode = self.episodes[episode_key] self.sequences[ sequence_key ] = shots_service.get_or_create_sequence( project_id, episode["id"], sequence_name ) else: self.sequences[ sequence_key ] = shots_service.get_or_create_sequence( project_id, None, sequence_name ) sequence_id = self.get_id_from_cache(self.sequences, sequence_key) shot_type = shots_service.get_shot_type() entity = Entity.get_by( name=shot_name, project_id=project_id, parent_id=sequence_id, entity_type_id=shot_type["id"], ) for name, field_name in self.descriptor_fields.items(): if name in row: data[field_name] = row[name] elif entity is not None and \ entity.data is not None and \ field_name in entity.data: data[field_name] = entity.data[field_name] if entity is None: if nb_frames is None or len(nb_frames) == 0: entity = Entity.create( name=shot_name, description=description, project_id=project_id, parent_id=sequence_id, entity_type_id=shot_type["id"], data=data, ) else: entity = Entity.create( name=shot_name, description=description, project_id=project_id, parent_id=sequence_id, entity_type_id=shot_type["id"], nb_frames=nb_frames, data=data, ) events.emit( "shot:new", {"shot_id": str(entity.id)}, project_id=project_id ) elif self.is_update: entity.update({ "description": description, "nb_frames": nb_frames, "data": data }) events.emit( "shot:update", {"shot_id": str(entity.id)}, project_id=project_id ) return entity.serialize()
def init_data(): """ Put the minimum required data into the database to start with it. """ projects_service.get_open_status() projects_service.get_closed_status() print("Project status initialized.") assets_service.get_or_create_asset_type("Characters") assets_service.get_or_create_asset_type("Props") assets_service.get_or_create_asset_type("Environment") assets_service.get_or_create_asset_type("FX") print("Asset types initialized.") shots_service.get_episode_type() shots_service.get_sequence_type() shots_service.get_shot_type() print("Shot types initialized.") modeling = tasks_service.get_or_create_department("Modeling") animation = tasks_service.get_or_create_department("Animation") fx = tasks_service.get_or_create_department("FX") compositing = tasks_service.get_or_create_department("Compositing") concept = tasks_service.get_or_create_department("Concept") layout = tasks_service.get_or_create_department("Layout") tasks_service.get_or_create_task_type(concept, "Concept", "#8D6E63", 1) tasks_service.get_or_create_task_type(modeling, "Modeling", "#78909C", 2) tasks_service.get_or_create_task_type(modeling, "Shading", "#64B5F6", 3) tasks_service.get_or_create_task_type(animation, "Rigging", "#9CCC65", 4) tasks_service.get_or_create_task_type( concept, "Storyboard", "#43A047", priority=1, for_shots=True, for_entity="Shot", ) tasks_service.get_or_create_task_type( layout, "Layout", "#7CB342", priority=2, for_shots=True, for_entity="Shot", ) tasks_service.get_or_create_task_type( animation, "Animation", "#009688", priority=3, for_shots=True, for_entity="Shot", ) tasks_service.get_or_create_task_type( compositing, "Lighting", "#F9A825", priority=4, for_shots=True, for_entity="Shot", ) tasks_service.get_or_create_task_type(fx, "FX", "#26C6DA", priority=5, for_shots=True, for_entity="Shot") tasks_service.get_or_create_task_type( compositing, "Rendering", "#F06292", priority=6, for_shots=True, for_entity="Shot", ) tasks_service.get_or_create_task_type( compositing, "Compositing", "#ff5252", priority=7, for_shots=True, for_entity="Shot", ) print("Task types initialized.") tasks_service.get_or_create_status("Todo", "todo", "#f5f5f5") tasks_service.get_or_create_status("Work In Progress", "wip", "#3273dc") tasks_service.get_or_create_status("Waiting For Approval", "wfa", "#ab26ff") tasks_service.get_or_create_status("Retake", "retake", "#ff3860", is_retake=True) tasks_service.get_or_create_status("Done", "done", "#22d160", is_done=True) print("Task status initialized.")
def import_row(self, row, project_id): if self.is_tv_show: episode_name = row["Episode"] sequence_name = row["Sequence"] shot_name = row["Name"] if self.is_tv_show: episode_key = "%s-%s" % (project_id, episode_name) if episode_key not in self.episodes: self.episodes[ episode_key ] = shots_service.get_or_create_episode( project_id, episode_name ) sequence_key = "%s-%s-%s" % ( project_id, episode_name, sequence_name, ) else: sequence_key = "%s-%s" % (project_id, sequence_name) if sequence_key not in self.sequences: if self.is_tv_show: episode = self.episodes[episode_key] self.sequences[ sequence_key ] = shots_service.get_or_create_sequence( project_id, episode["id"], sequence_name ) else: self.sequences[ sequence_key ] = shots_service.get_or_create_sequence( project_id, None, sequence_name ) sequence_id = self.get_id_from_cache(self.sequences, sequence_key) shot_type = shots_service.get_shot_type() shot_values = { "name": shot_name, "project_id": project_id, "parent_id": sequence_id, "entity_type_id": shot_type["id"], } entity = Entity.get_by(**shot_values) shot_new_values = {} description = row.get("Description", None) if description is not None: shot_new_values["description"] = description nb_frames = row.get("Nb Frames", None) or row.get("Frames", None) if nb_frames is not None: shot_new_values["nb_frames"] = nb_frames if entity is None or not entity.data: shot_new_values["data"] = {} else: shot_new_values["data"] = entity.data.copy() frame_in = row.get("Frame In", None) or row.get("In", None) if frame_in is not None: shot_new_values["data"]["frame_in"] = frame_in frame_out = row.get("Frame Out", None) or row.get("Out", None) if frame_out is not None: shot_new_values["data"]["frame_out"] = frame_out fps = row.get("FPS", None) if fps is not None: shot_new_values["data"]["fps"] = fps for name, field_name in self.descriptor_fields.items(): if name in row: shot_new_values["data"][field_name] = row[name] tasks_update = self.get_tasks_update(row) if entity is None: entity = Entity.create(**{**shot_values, **shot_new_values}) events.emit( "shot:new", {"shot_id": str(entity.id)}, project_id=project_id ) self.create_and_update_tasks( tasks_update, entity, shot_creation=True ) elif self.is_update: entity.update(shot_new_values) events.emit( "shot:update", {"shot_id": str(entity.id)}, project_id=project_id, ) self.create_and_update_tasks( tasks_update, entity, shot_creation=False ) return entity.serialize()
def __init__(self): ImportRemoveShotgunBaseResource.__init__( self, Entity, entity_type_id=shots_service.get_shot_type()["id"])
def all_assets_and_tasks(criterions={}, page=1): shot_type = shots_service.get_shot_type() sequence_type = shots_service.get_sequence_type() episode_type = shots_service.get_episode_type() scene_type = shots_service.get_scene_type() asset_map = {} task_map = {} query = Entity.query \ .join(EntityType) \ .outerjoin(Task) \ .outerjoin(assignees_table) \ .add_columns( EntityType.name, Task.id, Task.task_type_id, Task.task_status_id, assignees_table.columns.person ) \ .order_by( EntityType.name, Entity.name ) \ .filter( ~Entity.entity_type_id.in_([ shot_type["id"], scene_type["id"], sequence_type["id"], episode_type["id"] ]) ) if "project_id" in criterions: query = query.filter(Entity.project_id == criterions["project_id"]) for (asset, entity_type_name, task_id, task_type_id, task_status_id, person_id) in query.all(): if asset.id not in asset_map: asset_map[asset.id] = { "id": str(asset.id), "name": asset.name, "preview_file_id": str(asset.preview_file_id or ""), "description": asset.description, "asset_type_name": entity_type_name, "asset_type_id": str(asset.entity_type_id), "canceled": asset.canceled, "data": fields.serialize_value(asset.data), "tasks": [] } if task_id is not None: if task_id not in task_map: task_dict = { "id": str(task_id), "entity_id": str(asset.id), "task_status_id": str(task_status_id), "task_type_id": str(task_type_id), "assignees": [] } task_map[task_id] = task_dict asset_dict = asset_map[asset.id] asset_dict["tasks"].append(task_dict) if person_id: task_map[task_id]["assignees"].append(str(person_id)) return list(asset_map.values())