def _add_lang_to_video(video, props, translated_from=None): if props.get('is_original', False): video.newsubtitlelanguage_set.all().delete() sub_lang = video.subtitle_language(props.get('code', '')) if not video.primary_audio_language_code: video.primary_audio_language_code = props.get('code', '') video.save() if not sub_lang: sub_lang = sub_models.SubtitleLanguage( video=video, subtitles_complete=props.get('is_complete', False), language_code=props.get('code'), is_forked=True, ) sub_lang.save() num_subs = props.get("num_subs", 0) _add_subtitles(sub_lang, num_subs, video, translated_from) for translation_prop in props.get("translations", []): _add_lang_to_video(video, translation_prop, translated_from=sub_lang) sub_lang.save() from videos.tasks import video_changed_tasks video_changed_tasks(sub_lang.video.id) return sub_lang
def _get_language_for_editing(self, request, video_id, language_code, subtitle_language_pk=None, base_language_code=None): """Return the subtitle language to edit or a lock response.""" video = models.Video.objects.get(video_id=video_id) editable = False created = False if subtitle_language_pk is not None: language = new_models.SubtitleLanguage.objects.get( pk=subtitle_language_pk) else: # we can tell which language it is from the language code candidates = video.newsubtitlelanguage_set.filter( language_code=language_code) if not candidates.exists(): # no languages with the language code, we must create one language = new_models.SubtitleLanguage( video=video, language_code=language_code, created=datetime.now()) language.is_forked = not base_language_code and video.newsubtitlelanguage_set.exists( ) language.save() created = True else: for candidate in candidates: if base_language_code == candidate.get_translation_source_language_code( ): # base language matches, break me language = candidate break # if we reached this point, we have no good matches language = candidates[0] editable = language.can_writelock(request.user) if editable: if created: api_language_new.send(language) return language, None else: return None, { "can_edit": False, "locked_by": unicode(language.writelock_owner) }
def test_title_and_description_from_video(self): request = RequestMockup(self.user_0) video = Video.objects.all()[0] title = "a title" description = 'something' video.title = title video.description = description video.save() lang = sub_models.SubtitleLanguage(language_code='en', video=video) lang.save() response = rpc.start_editing( request, video.video_id, 'en', subtitle_language_pk=lang.pk) self.assertEquals(response['subtitles']['title'], title) self.assertEquals(response['subtitles']['description'], description)
def _subtitles_dict(self, video_id): language = subs_models.SubtitleLanguage( language_code='en') return self._make_subtitles_dict([], language, 1, True, False, 1, True, None, "what", "About me", False, False, {})