当前位置: 首页>>代码示例>>Python>>正文


Python SubtitleLanguage.latest_version方法代码示例

本文整理汇总了Python中videos.models.SubtitleLanguage.latest_version方法的典型用法代码示例。如果您正苦于以下问题:Python SubtitleLanguage.latest_version方法的具体用法?Python SubtitleLanguage.latest_version怎么用?Python SubtitleLanguage.latest_version使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在videos.models.SubtitleLanguage的用法示例。


在下文中一共展示了SubtitleLanguage.latest_version方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save

# 需要导入模块: from videos.models import SubtitleLanguage [as 别名]
# 或者: from videos.models.SubtitleLanguage import latest_version [as 别名]
    def save(self):
        subtitles = self.cleaned_data["subtitles"]
        video = self.cleaned_data["video"]

        key = str(uuid4()).replace("-", "")
        video._make_writelock(self.user, key)
        video.save()

        language = video.subtitle_language()

        if not language:
            language = SubtitleLanguage(video=video, is_original=True, is_complete=True)
            language.save()

        latest_captions = language.latest_version()
        if latest_captions is None:
            version_no = 0
        else:
            version_no = latest_captions.version_no + 1

        version = SubtitleVersion(
            language=language, version_no=version_no, datetime_started=datetime.now(), user=self.user, note=u"Uploaded"
        )
        version.save()

        text = subtitles.read()
        parser = self._get_parser(subtitles.name)(force_unicode(text, chardet.detect(text)["encoding"]))
        ids = []

        for i, item in enumerate(parser):
            id = int(random.random() * 10e12)
            while id in ids:
                id = int(random.random() * 10e12)
            ids.append(id)
            caption = Subtitle(**item)
            caption.version = version
            caption.subtitle_id = str(id)
            caption.sub_order = i + 1
            caption.save()

        version.finished = True
        version.save()

        video.release_writelock()
        video.save()
开发者ID:annasob,项目名称:mirosubs,代码行数:47,代码来源:forms.py

示例2: test_moderated_subs_approve_one

# 需要导入模块: from videos.models import SubtitleLanguage [as 别名]
# 或者: from videos.models.SubtitleLanguage import latest_version [as 别名]
        def test_moderated_subs_approve_one(self):
            video = Video.objects.get(pk=4)
            tv = TeamVideo(video=video, team=self.team,added_by=self.user)
            tv.save()
            url = reverse("teams:detail", kwargs={"slug": self.team.slug})
            response = self.client.get(url)
            add_moderation(video, self.team, self.user)
            self._login(is_moderator=True)
            self.client.get("\en\faq")        
            lang = video.subtitle_language()
            [ self._make_subs(lang, 5) for x in xrange(0, 3)]
            self.assertEquals(self.team.get_pending_moderation().count(), 3)

            lang = SubtitleLanguage(video=video, language="pt", title="a", standard_language=lang)
            lang.save()
            [ self._make_subs(lang, 5) for x in xrange(0, 3)]
            # we can see the unmoderated sub on the website,
            response = self.client.get(reverse("videos:translation_history", kwargs={
                    'video_id':video.video_id,
                    'lang':lang.language,
                    'lang_id':lang.id
            }))
            versions =  SubtitleVersion.objects.filter(language=lang)
            latest_version =  lang.latest_version(public_only=False) #lang.subtitleversion_set.all()[0]

            subs = response.context['last_version'].subtitle_set.all()
            self.assertEquals(latest_version, response.context['last_version'])
            self.assertTrue(subs[0].subtitle_text.startswith("vno:2 Sub 0 "))
            self.assertTrue(len(subs))
            self.assertEquals(self.team.get_pending_moderation().count(), 6)
            versions = self.team.get_pending_moderation()
            version = versions[0]
            # after moderation it should not be visible on the widget
            subs = self._call_rpc_method("fetch_subtitles", lang.video.video_id, lang.pk)
            self.assertFalse(subs)


            url = reverse("moderation:revision-approve", kwargs={
                        "team_id":self.team.id,
                        "version_id":version.pk} )
            response = self.client.post(url, {},follow=True,  HTTP_X_REQUESTED_WITH='XMLHttpRequest')
            self.assertEquals(response.status_code, 200)

            data  =  json.loads(response.content)
            self.assertTrue(data["success"])


            self.team = refresh_obj(self.team)
            self.assertEquals(self.team.get_pending_moderation().count(), 5)
            version = SubtitleVersion.objects.get(pk=version.pk)
            self.assertEquals(version.moderation_status,APPROVED)

            response = self.client.get(reverse("videos:translation_history", kwargs={
                    'video_id':video.video_id,
                    'lang':lang.language,
                    'lang_id':lang.id
            }))
            sub_1 = response.context['last_version'].subtitle_set.all()
            self.assertTrue(len(sub_1))
            widget_res = self._call_rpc_method("fetch_subtitles", version.video.video_id, version.language.pk)
            self.assertTrue(widget_res)
            self.assertTrue(widget_res["subtitles"])

            sub = widget_res["subtitles"][0]
            self.assertTrue(sub["text"].startswith("vno:2 Sub 0 "))
开发者ID:adncentral,项目名称:unisubs,代码行数:67,代码来源:moderation_test.py


注:本文中的videos.models.SubtitleLanguage.latest_version方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。