• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.SubtitleLanguage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_other_languages_changes

 def test_other_languages_changes(self):
     v = self._new_version()
     l = SubtitleLanguage(video=self.video, language='ru', is_original=False)
     l.save()
     self._new_version(l)
     alarms.check_other_languages_changes(v, ignore_statistic=True)
     self.assertEquals(len(mail.outbox), 1)
开发者ID:MechanisM,项目名称:mirosubs,代码行数:7,代码来源:tests.py


示例2: _find_appropriate_language

 def _find_appropriate_language(self, video, language_code):
     language = video.subtitle_language(language_code)
     if not language:
         language = SubtitleLanguage(
             video=video, is_original=False, is_forked=True)
     language.language = language_code
     language.save()
     return language
开发者ID:crodjer,项目名称:mirosubs,代码行数:8,代码来源:forms.py


示例3: test_update_tvlp_for_sl

 def test_update_tvlp_for_sl(self):
     tv = TeamVideo.objects.get(id=2)
     sl = SubtitleLanguage(
         language='en',
         is_original=True,
         is_forked=False,
         is_complete=True,
         video=tv.video)
     sl.save()
     dl = SubtitleLanguage(
         language='es',
         is_original=False,
         is_forked=False,
         percent_done=40,
         standard_language=sl,
         video=tv.video)
     dl.save()
     tv = TeamVideo.objects.get(id=2)
     tv.update_team_video_language_pairs()
     dl = SubtitleLanguage.objects.get(id=dl.id)
     dl.percent_done = 50
     dl.save()
     tv.update_team_video_language_pairs_for_sl(dl)
     tvlps = self._tvlp_query_set(tv)
     self.assertEquals(len(settings.ALL_LANGUAGES) * 2 - 2, len(tvlps))
     for tvlp in tvlps:
         if tvlp.language_0 == 'en':
             if tvlp.language_1 == 'es':
                 self.assertEquals(50, tvlp.percent_complete)
             else:
                 self.assertEquals(0, tvlp.percent_complete)
         elif tvlp.language_0 == 'es':
             self.assertEquals(0, tvlp.percent_complete)
开发者ID:brettle,项目名称:mirosubs,代码行数:33,代码来源:tests.py


示例4: test_update_lp_for_sl

 def test_update_lp_for_sl(self):
     tv = TeamVideo.objects.get(id=2)
     sl = SubtitleLanguage(
         language='en',
         is_original=True,
         is_forked=False,
         is_complete=True,
         video=tv.video)
     sl.save()
     dl = SubtitleLanguage(
         language='es',
         is_original=False,
         is_forked=False,
         percent_done=40,
         standard_language=sl,
         video=tv.video)
     dl.save()
     tv = TeamVideo.objects.get(id=2)
     dl = SubtitleLanguage.objects.get(id=dl.id)
     dl.percent_done = 50
     dl.save()
     lps = tv.searchable_language_pairs()
     self.assertEquals(len(settings.ALL_LANGUAGES) * 2 - 3, len(lps))
     for lp in lps:
         match = LANGUAGEPAIR_RE.match(lp)
         if match.group(1) == 'en':
             if match.group(2) == 'es':
                 self.assertEquals("M", match.group(3))
             else:
                 self.assertEquals("0", match.group(3))
         elif match.group(1) == 'es':
             self.assertEquals("0", match.group(3))
开发者ID:adncentral,项目名称:unisubs,代码行数:32,代码来源:teams.py


示例5: save_subtitles

    def save_subtitles(self, parser):
        video = self.cleaned_data['video']
        
        key = str(uuid4()).replace('-', '')

        video._make_writelock(self.user, key)
        video.save()

        if not video.has_original_language():
            self._save_original_language(
                video, self.cleaned_data['video_language'])
  
        language = video.subtitle_language(self.cleaned_data['language'])
        
        if not language:
            language = SubtitleLanguage(video=video, is_original=False, is_forked=True)
        
        language.language = self.cleaned_data['language']
        language.save()
        
        try:
            old_version = language.subtitleversion_set.all()[:1].get()    
            version_no = old_version.version_no + 1
        except ObjectDoesNotExist:
            old_version = None
            version_no = 0
        if not self.is_version_same(old_version, parser):
            version = SubtitleVersion(
                language=language, version_no=version_no,
                datetime_started=datetime.now(), user=self.user,
                note=u'Uploaded', is_forked=True, time_change=1, text_change=1)
            version.save()
    
            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.subtitle_order = i+1
                caption.save()

            version.save()
            version.update_percent_done()

            language.update_complete_state()
            language.save()
            if language.is_original:
                video.update_complete_state()

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


示例6: save

    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,代码行数:45,代码来源:forms.py


示例7: test_languages_mark_incomplete

    def test_languages_mark_incomplete(self):
        '''
        Test if already completed subtitles are marked as incomplete on a
        subtitle request
        '''

        langs = self.langs[3:]

        original = self.video.subtitle_language()
        lang = SubtitleLanguage(
            video=self.video,
            language=langs[0],
            is_original=False,
            is_forked=False,
            is_complete=True,
            standard_language=original)
        lang.save()
        self._create_requests(langs)[0]

        lang = SubtitleLanguage.objects.get(pk=lang.pk)
        self.assertEqual(False, lang.is_complete)
开发者ID:adncentral,项目名称:unisubs,代码行数:21,代码来源:tests.py


示例8: test_update_tvlp_no_dependent

 def test_update_tvlp_no_dependent(self):
     tv = TeamVideo.objects.get(id=2)
     tv.update_team_video_language_pairs()
     # this video starts with no languages.
     self.assertEquals(0, self._tvlp_query_set(tv).count())
     sl = SubtitleLanguage(
         language='en',
         is_original=True,
         is_forked=False,
         is_complete=False,
         video=tv.video)
     sl.save()
     tv = TeamVideo.objects.get(id=2)
     tv.update_team_video_language_pairs()
     # the language is not complete, so it's not a good source for translations.
     self.assertEquals(0, self._tvlp_query_set(tv).count())
     sl = tv.video.subtitle_language('en')
     sl.is_complete = True
     sl.save()
     tv = TeamVideo.objects.get(id=2)
     tv.update_team_video_language_pairs()
     # complete, so now every language can be translated from this one.
     tvlps = self._tvlp_query_set(tv)
     self.assertEquals(len(settings.ALL_LANGUAGES) - 1, len(tvlps))
     for tvlp in tvlps:
         self.assertEquals(0, tvlp.percent_complete)
开发者ID:brettle,项目名称:mirosubs,代码行数:26,代码来源:tests.py


示例9: test_update_tvl

 def test_update_tvl(self):
     tv = TeamVideo.objects.get(id=2)
     sl = SubtitleLanguage(
         language='en',
         is_original=True,
         is_forked=False,
         is_complete=False,
         video=tv.video)
     sl.save()
     tmodels.TeamVideoLanguage.update(tv)
     tvls =  tmodels.TeamVideoLanguage.objects.filter(team_video=tv)
     self.assertEquals(len(settings.ALL_LANGUAGES), len(tvls))
     for tvl in tvls:
         self.assertFalse(tvl.is_complete)
         self.assertEquals(0, tvl.percent_done)
     sl = SubtitleLanguage.objects.get(id=sl.id)
     sl.is_complete = True
     sl.save()
     tv = TeamVideo.objects.get(id=2)
     tmodels.TeamVideoLanguage.update(tv)
     tvls =  tmodels.TeamVideoLanguage.objects.filter(team_video=tv)
     self.assertEquals(len(settings.ALL_LANGUAGES), len(tvls))
     for tvl in tvls:
         if tvl.language != 'en':
             self.assertFalse(tvl.is_complete)
         else:
             self.assertTrue(tvl.is_complete)
         self.assertEquals(0, tvl.percent_done)
开发者ID:brettle,项目名称:mirosubs,代码行数:28,代码来源:tests.py


示例10: test_request_language_handler

    def test_request_language_handler(self):
        '''
        Test the signal handler which sets the requesters as language
        followers when a new (requested) language is created.
        '''

        subrequest = self._create_requests(self.langs[2:3])[0]

        # Test if the user automatically starts following
        # a language if there is a pending request
        original = self.video.subtitle_language()
        newlang = SubtitleLanguage(
            video=self.video,
            language=subrequest.language,
            is_original=False,
            is_forked=False,
            standard_language=original)
        newlang.save()

        self.assertEqual(self.user, newlang.followers.all()[0])

        # Test if subtitle request is marked as done
        newlang.is_complete = True
        newlang.save()
        subrequest = SubtitleRequest.objects.get(pk=subrequest.pk)

        self.assertEqual(subrequest.done, True)
开发者ID:adncentral,项目名称:unisubs,代码行数:27,代码来源:tests.py


示例11: test_moderated_subs_reject_one

        def test_moderated_subs_reject_one(self):
            url = reverse("teams:detail", kwargs={"slug": self.team.slug})
            response = self.client.get(url)
            add_moderation(self.video, self.team, self.user)
            self._login(is_moderator=True)
            self.client.get("\en\faq")        
            lang = self.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=self.video, language="pt", title="a")
            lang.save()
            [ self._make_subs(lang, 5) for x in xrange(0, 3)]
            self.assertEquals(self.team.get_pending_moderation().count(), 6)
            versions = self.team.get_pending_moderation()
            version = versions[0]

            url = reverse("moderation:revision-approve", kwargs={
                        "team_id":self.team.id,
                        "version_id":version.pk})
            response = self.client.post(url, {},follow=True)
            self.assertEquals(response.status_code, 200)
            self.assertEquals(self.team.get_pending_moderation().count(), 5)
            version = SubtitleVersion.objects.get(pk=version.pk)
            self.assertEquals(version.moderation_status,APPROVED)
开发者ID:adncentral,项目名称:unisubs,代码行数:24,代码来源:moderation_test.py


示例12: _save_original_language

    def _save_original_language(self, video, video_language):
        original_language = video.subtitle_language()

        if original_language:
            if original_language.language:
                try:
                    language_exists = video.subtitlelanguage_set.exclude(pk=original_language.pk) \
                        .get(language=video_language)
                    original_language.is_original = False
                    original_language.save()
                    language_exists.is_original = True
                    language_exists.save()
                except ObjectDoesNotExist:
                    original_language.language = video_language
                    original_language.save()
            else:
                try:
                    language_exists = video.subtitlelanguage_set.exclude(pk=original_language.pk) \
                        .get(language=video_language)
                    
                    latest_version = original_language.latest_version() 
                    
                    if latest_version:
                        last_no = latest_version.version_no
                    else:
                        last_no = 0
                        
                    for version in language_exists.subtitleversion_set.all():
                        version.language = original_language
                        last_no += 1
                        version.version_no = last_no
                        version.save()

                    language_exists.delete()
                except ObjectDoesNotExist:
                    pass
                
                original_language.language = video_language
                original_language.save()
        else:
            #original_language always exists, but...
            try:
                language_exists = video.subtitlelanguage_set.get(language=video_language)
                language_exists.is_original = True
                language_exists.save()
            except ObjectDoesNotExist:
                original_language = SubtitleLanguage()
                original_language.language = video_language
                original_language.is_original = True
                original_language.video = video
                original_language.save()
开发者ID:rhemmanur,项目名称:mirosubs,代码行数:51,代码来源:forms.py


示例13: forwards

 def forwards(self, orm):
     if db.dry_run:
         return
     
     try:
         from videos.models import Video, SubtitleLanguage
     except ImportError:
         return
     
     try:
         Video.widget_views_counter.r.ping()
     except ConnectionError:
         if settings.DEBUG:
             return
         raise Exception('Redis server is unavailable. You can ignore this migration with: python manage.py migrate videos 0068 --fake, but all statistic data will be lost.')
     
     for obj in orm.Video.objects.all():
         Video.subtitles_fetched_counter(obj.video_id).val = obj.subtitles_fetched_count
         Video.widget_views_counter(obj.video_id).val = obj.widget_views_count
         
     for obj in orm.SubtitleLanguage.objects.all():
         SubtitleLanguage.subtitles_fetched_counter(obj.pk).val = obj.subtitles_fetched_count
开发者ID:MechanisM,项目名称:mirosubs,代码行数:22,代码来源:0068_migrate_counters.py


示例14: test_update_sl

 def test_update_sl(self):
     tv = TeamVideo.objects.get(id=2)
     sublang = SubtitleLanguage(
         language='en',
         is_original=True,
         is_forked=False,
         is_complete=False,
         video=tv.video)
     sublang.save()
     sls = tv.searchable_languages()
     self.assertEquals(len(settings.ALL_LANGUAGES), len(sls))
     sublang = SubtitleLanguage.objects.get(id=sublang.id)
     sublang.is_complete = True
     sublang.save()
     tv = TeamVideo.objects.get(id=2)
     sls =  tv.searchable_languages()
     self.assertEquals(len(settings.ALL_LANGUAGES) - 1, len(sls))
开发者ID:adncentral,项目名称:unisubs,代码行数:17,代码来源:teams.py


示例15: setUp

    def setUp(self):
        self.video = Video.objects.all()[:1].get()
        self.original_language = self.video.subtitle_language()
        latest_version = self.original_language.latest_version()
        
        translation = SubtitleLanguage()
        translation.video = self.video
        translation.language = 'uk'
        translation.is_original = False
        translation.is_forked = False
        translation.save()

        self.translation = translation
        
        v = SubtitleVersion()
        v.language = translation
        v.datetime_started = datetime.now()
        v.save()
        
        self.translation_version = v
        
        for s in latest_version.subtitle_set.all():
            s.duplicate_for(v).save()
开发者ID:MechanisM,项目名称:mirosubs,代码行数:23,代码来源:tests.py


示例16: test_moderated_subs_pending_count

        def test_moderated_subs_pending_count(self):
            add_moderation(self.video, self.team, self.user)
            lang = self.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=self.video, language="pt", title="a")
            lang.save()
            [ self._make_subs(lang, 5) for x in xrange(0, 3)]
            self.assertEquals(self.team.get_pending_moderation().count(), 6)
            # make sure pending count is for only one team
            tv = TeamVideo.objects.exclude(team=self.team).filter(video__moderated_by__isnull=True)[0]
            o, c = TeamMember.objects.get_or_create(user=self.auth_user, team=tv.team)
            o.role=TeamMember.ROLE_MANAGER
            o.save()
            new_team = tv.team
            add_moderation(tv.video, tv.team, self.auth_user)

            lang = SubtitleLanguage(video=tv.video, language="pt", title="a")
            lang.save()
            [ self._make_subs(lang, 5) for x in xrange(0, 3)]
            self.assertEquals(self.team.get_pending_moderation().count(), 6)
            self.assertEquals(tv.team.get_pending_moderation().count(), 3)
开发者ID:adncentral,项目名称:unisubs,代码行数:22,代码来源:moderation_test.py


示例17: test_update_lp_no_dependent

 def test_update_lp_no_dependent(self):
     tv = TeamVideo.objects.get(id=2)
     # this video starts with no languages.
     self.assertEquals(0, len(tv.searchable_language_pairs()))
     sl = SubtitleLanguage(
         language='en',
         is_original=True,
         is_forked=False,
         is_complete=False,
         video=tv.video)
     sl.save()
     tv = TeamVideo.objects.get(id=2)
     self.assertEquals(0, len(tv.searchable_language_pairs()))
     sl = tv.video.subtitle_language('en')
     sl.is_complete = True
     sl.save()
     tv = TeamVideo.objects.get(id=2)
     lps = tv.searchable_language_pairs()
     self.assertEquals(len(settings.ALL_LANGUAGES) - 1, len(lps))
     # we expect each string to end in "_0" to indicate zero completion.
     for lp in lps:
         self.assertEquals("0", LANGUAGEPAIR_RE.match(lp).group(3))
开发者ID:adncentral,项目名称:unisubs,代码行数:22,代码来源:teams.py


示例18: test_moderated_subs_approve_one

        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,代码行数:65,代码来源:moderation_test.py


示例19: test_subtitle_language_save

    def test_subtitle_language_save(self):
        self.assertEqual(self.video.complete_date, None)
        self.assertEqual(self.video.subtitlelanguage_set.count(), 1)

        self.language.is_complete = True
        self.language.save()
        self.video = Video.objects.get(pk=self.video.pk)
        self.assertNotEqual(self.video.complete_date, None)
        
        self.language.is_complete = False
        self.language.save()
        self.video = Video.objects.get(pk=self.video.pk)
        self.assertEqual(self.video.complete_date, None)
        
        #add one more SubtitleLanguage
        l = SubtitleLanguage(video=self.video)
        l.is_original = False
        l.is_complete = True
        l.save()
        self.video = Video.objects.get(pk=self.video.pk)
        self.assertNotEqual(self.video.complete_date, None)
        
        self.language.is_complete = True
        self.language.save()
        self.video = Video.objects.get(pk=self.video.pk)
        self.assertNotEqual(self.video.complete_date, None)

        l.is_complete = False
        l.save()
        self.video = Video.objects.get(pk=self.video.pk)
        self.assertNotEqual(self.video.complete_date, None)
        
        self.language.is_complete = False
        self.language.save()
        self.video = Video.objects.get(pk=self.video.pk)
        self.assertEqual(self.video.complete_date, None)

        self.language.is_complete = True
        self.language.save()
        self.video = Video.objects.get(pk=self.video.pk)
        self.assertNotEqual(self.video.complete_date, None)
                
        l.is_complete = True
        l.save()
        self.video = Video.objects.get(pk=self.video.pk)
        self.assertNotEqual(self.video.complete_date, None)
        
        self.language.delete()
        self.video = Video.objects.get(pk=self.video.pk)
        self.assertNotEqual(self.video.complete_date, None)
        
        l.delete()
        self.video = Video.objects.get(pk=self.video.pk)
        self.assertEqual(self.video.complete_date, None)
开发者ID:axitkhurana,项目名称:mirosubs,代码行数:54,代码来源:tests.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.Video类代码示例发布时间:2022-05-26
下一篇:
Python views.render_to_response_ex函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap