예제 #1
0
def _add_lang_to_video(video, props, translated_from=None):
    if props.get('is_original', False):
        sl = video.subtitle_language()
        sl and sl.delete()
    sub_lang = SubtitleLanguage(
        video=video,
        is_original=props.get('is_original', False),
        is_complete=props.get('is_complete', False),
        language=props.get('code'),
        has_version=True,
        had_version=True,
        is_forked=True,
    )
    sub_lang.save()
    num_subs = props.get("num_subs", 0)

    if not translated_from:
        _add_subtitles(sub_lang, num_subs)
    else:
        sub_lang.is_original = False
        sub_lang.is_forked = False
        sub_lang.standard_language = translated_from
        sub_lang.save()
        _copy_subtitles(translated_from, sub_lang, num_subs)

    for translation_prop in props.get("translations", []):
        _add_lang_to_video(video, translation_prop, translated_from=sub_lang)

    sub_lang.is_complete = props.get("is_complete", False)
    sub_lang.save()
    from videos.tasks import video_changed_tasks
    video_changed_tasks(sub_lang.video.id)
    return sub_lang
예제 #2
0
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
예제 #3
0
def update_video_public_field(team_id):
    from teams.models import Team

    team = Team.objects.get(pk=team_id)

    for team_video in team.teamvideo_set.all():
        video = team_video.video
        video.is_public = team.is_visible
        video.save()
        video_changed_tasks(video.id)
예제 #4
0
 def save(self,
          skips_timestamp=False,
          updates_metadata=True,
          *args,
          **kwargs):
     if self.created is None:
         self.created = datetime.datetime.now()
     if not self.site_secret_key:
         self.site_secret_key = VideoVisibilityPolicy.objects.gen_secret(
             self)
     if skips_timestamp is False:
         self.modified = datetime.datetime.now()
     super(VideoVisibilityPolicy, self).save(*args, **kwargs)
     if self.is_public != self.video.is_public:
         self.video.is_public = self.is_public
         self.video.save()
     if updates_metadata:
         video_changed_tasks(self.video.pk)
예제 #5
0
    def test_moderated_notifies_only_when_published(self):
        """
        Set up a public team, add new video and new version.
        Notification should be sent.
        Setup  a team with moderated videos
        """
        from teams.moderation_const import WAITING_MODERATION, APPROVED

        def video_with_two_followers():
            v, c = Video.get_or_create_for_url(
                "http://blip.tv/file/get/Miropcf-AboutUniversalSubtitles847.ogv"
            )
            f1 = User.objects.all()[0]
            f2 = User.objects.all()[1]
            f1.notify_by_email = f2.notify_by_email = True
            f1.save()
            f2.save()
            v.followers.add(f1, f2)
            return v

        def new_version(v):

            language, created = SubtitleLanguage.objects.get_or_create(
                video=v, language='en', is_original=True)
            prev = language.version(public_only=False)
            version_no = 0
            if prev:
                version_no = prev.version_no + 1
            sv = SubtitleVersion(language=language,
                                 user=User.objects.all()[2],
                                 version_no=version_no,
                                 datetime_started=datetime.now())
            sv.save()
            s = Subtitle(version=sv,
                         subtitle_text=str(version_no + random.random()),
                         subtitle_order=1,
                         subtitle_id=str(version_no),
                         start_time=random.random())
            s.save()
            return sv

        v = video_with_two_followers()
        mail.outbox = []
        from videos.tasks import video_changed_tasks
        v = video_with_two_followers()
        sv = new_version(v)
        video_changed_tasks(v.pk, sv.pk)
        # notifications are only sent on the second version of a video
        # as optimization
        sv = new_version(v)
        video_changed_tasks(v.pk, sv.pk)
        # video is public , followers should be notified
        self.assertEquals(len(mail.outbox), 2)
        mail.outbox = []
        # add to a moderated video
        team = Team.objects.create(slug='my-team',
                                   name='myteam',
                                   workflow_enabled=True)
        workflow = Workflow(team=team, review_allowed=20, approve_allowed=20)
        workflow.save()

        tv = TeamVideo(team=team, video=v, added_by=User.objects.all()[2])
        tv.save()
        sv = new_version(v)
        # with the widget, this would set up correctly
        sv.moderation_status = WAITING_MODERATION
        sv.save()

        video_changed_tasks(v.pk, sv.pk)
        sv = SubtitleVersion.objects.get(pk=sv.pk)
        self.assertFalse(sv.is_public)
        # approve video
        t = Task(type=40,
                 approved=20,
                 team_video=tv,
                 team=team,
                 language='en',
                 subtitle_version=sv)
        t.save()
        t.complete()
        video_changed_tasks(v.pk, sv.pk)

        self.assertEqual(len(mail.outbox), 2)
예제 #6
0
    def test_moderated_notifies_only_when_published(self):
        # TODO: should this use the new visibility settings instead of the old
        # moderation stuff?
        """
        Set up a public team, add new video and new version.
        Notification should be sent.
        Setup  a team with moderated videos
        """
        from teams.moderation_const import WAITING_MODERATION

        def video_with_two_followers():
            v, c = Video.get_or_create_for_url(
                "http://blip.tv/file/get/Miropcf-AboutUniversalSubtitles847.ogv"
            )
            f1 = User.objects.all()[0]
            f2 = User.objects.all()[1]
            f1.notify_by_email = f2.notify_by_email = True
            f1.save()
            f2.save()
            v.followers.add(f1, f2)
            return v

        def new_version(v):

            subs = [(0, 1000, 'Hello', {}), (2000, 5000, 'world.', {})]
            add_subtitles(v,
                          'en',
                          subs,
                          author=self.author,
                          committer=self.author)
            subs = [(0, 1000, 'Hello', {}), (3000, 5000, 'world.', {})]
            return add_subtitles(v,
                                 'en',
                                 subs,
                                 author=self.author,
                                 committer=self.author)

        v = video_with_two_followers()
        mail.outbox = []
        from videos.tasks import video_changed_tasks
        v = video_with_two_followers()
        sv = new_version(v)
        video_changed_tasks(v.pk, sv.pk)
        # notifications are only sent on the second version of a video
        # as optimization
        sv = new_version(v)
        video_changed_tasks(v.pk, sv.pk)
        # video is public , followers should be notified
        self.assertEquals(len(mail.outbox), 2)
        mail.outbox = []
        # add to a moderated video
        team = Team.objects.create(slug='my-team',
                                   name='myteam',
                                   workflow_enabled=True)
        workflow = Workflow(team=team, review_allowed=20, approve_allowed=20)
        workflow.save()

        tv = TeamVideo(team=team, video=v, added_by=User.objects.all()[2])
        tv.save()
        sv = new_version(v)
        # with the widget, this would set up correctly
        sv.moderation_status = WAITING_MODERATION
        sv.save()

        video_changed_tasks(v.pk, sv.pk)
        sv = sub_models.SubtitleVersion.objects.get(pk=sv.pk)
        self.assertFalse(sv.is_public())
        # no emails should be sent before the video is approved
        self.assertEqual(len(mail.outbox), 0)
        # approve video
        t = Task(type=40,
                 approved=20,
                 team_video=tv,
                 team=team,
                 language='en',
                 new_subtitle_version=sv,
                 assignee=self.author)
        t.save()
        t.complete()
        self.assertTrue(sv.is_public())
        video_changed_tasks(v.pk, sv.pk)
        # Once the video is approved, we should send out the
        # team-task-approved-published.html email and the
        # email_notification_non_editors.html to the author
        self.assertEqual(len(mail.outbox), 2)
예제 #7
0
 def delete(self, updates_metadata=True, *args, **kwargs):
     super(VideoVisibilityPolicy, self).delete(*args, **kwargs)
     if updates_metadata:
         video_changed_tasks(self.video.pk)