def post_update(self, project_dict): if project_dict["production_type"] == "tvshow": episode = shots_service.get_or_create_first_episode( project_dict["id"]) project_dict["first_episode_id"] = \ fields.serialize_value(episode["id"]) return project_dict
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