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


Python models.SubtitleLanguage类代码示例

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


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


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