def _save_subtitles(self, version, json_subs, forked): """Create Subtitle objects into the version from the JSON subtitles.""" subtitles = [] for s in json_subs: if not forked: s = Subtitle(subtitle_id=s['subtitle_id'], subtitle_text=s['text']) else: # Normally this is done in Subtitle.save(), but bulk inserting # doesn't call that. start_time = s['start_time'] end_time = s['end_time'] # this will go way in the DRM anyways if not start_time or start_time == -1: start_time = None if not end_time or end_time == -1: end_time = None s = Subtitle(subtitle_id=s['subtitle_id'], subtitle_text=s['text'], start_time=start_time, end_time=end_time, subtitle_order=s['sub_order'], start_of_paragraph=s.get('start_of_paragraph', False)) s.version_id = version.pk subtitles.append(s) # For huge sets of subtitles, adding each one to the DB one at a time # can take longer than the browser timeout. We need to do this in the # background instead. For now. This is all going away once the new # data model refactor lands. I love hacking stuff in on the fly. insert_many(subtitles)