Exemple #1
0
        def test_video_moderator_change_in_form(self):
            add_moderation(self.video, self.team, self.user)
            self.assertTrue(is_moderated(self.video))
            team , created = Team.objects.get_or_create(slug="a", name="a")
            tv, created = TeamVideo.objects.get_or_create(video=self.video, team=team, added_by=self.user)
            form = EditTeamVideoForm(None,  None, instance=tv, user=self.user)
            field = form.fields.get( "is_moderated", False)
            moderating_tv =  TeamVideo.objects.get(team=self.team, video=self.video)

            form = EditTeamVideoForm({"is_moderated":False},  None, instance=moderating_tv, user=self.user)
            field = form.fields.get( "is_moderated", None)
            self.assertTrue(field is not None)
            if form.is_valid():
                form.save()
            self.assertTrue(form.is_valid())
            self.video = Video.objects.get(pk=self.video.pk)
            self.assertFalse(is_moderated(self.video))
Exemple #2
0
    def finished_subtitles(self, request, session_pk, subtitles=None, 
                           new_title=None, completed=None, 
                           forked=False,
                           throw_exception=False):
        session = SubtitlingSession.objects.get(pk=session_pk)
        if not request.user.is_authenticated():
            return { 'response': 'not_logged_in' }
        if not session.language.can_writelock(request):
            return { "response" : "unlockable" }
        if not session.matches_request(request):
            return { "response" : "does not match request" }

        if throw_exception:
            raise Exception('purposeful exception for testing')

        from apps.teams.moderation import is_moderated, user_can_moderate
        
        language = session.language
        new_version = None
        if subtitles is not None and \
                (len(subtitles) > 0 or language.latest_version(public_only=False) is not None):
            new_version = self._create_version_from_session(session, request.user, forked)
            new_version.save()
            self._save_subtitles(
                new_version.subtitle_set, subtitles, new_version.is_forked)

        language.release_writelock()
        if completed is not None:
            language.is_complete = completed
        if new_title is not None:
            language.title = new_title
        language.save()

        if new_version is not None:
            video_changed_tasks.delay(language.video.id, new_version.id)
        else:
            video_changed_tasks.delay(language.video.id)

        # we have a default user message, since the UI lets users save non
        # changed subs, but the backend will realize and will not save that
        # version. In those cases, we want to show the defatul user message.
        user_message = "Thank you for uploading. It will take a minute or so for your subtitles to appear."
        if new_version is not None and new_version.version_no == 0:
            user_message = "Thank you for uploading. It will take a minute or so for your subtitles to appear."
        elif new_version and is_moderated(new_version):
            
            if user_can_moderate(language.video, request.user) is False:
                user_message = """This video is moderated by %s. 

You will not see your subtitles in our widget when you leave this page, they will only appear on our site. We have saved your work for the team moderator to review. After they approve your subtitles, they will show up on our site and in the widget.
""" % (new_version.video.moderated_by.name)
        return {
            'user_message': user_message,
            'response': 'ok' }
Exemple #3
0
    def save_finished(self,
                      user,
                      session,
                      subtitles,
                      new_title=None,
                      completed=None,
                      forked=False):
        from apps.teams.moderation import is_moderated, user_can_moderate

        language = session.language
        new_version = None
        if subtitles is not None and \
                (len(subtitles) > 0 or language.latest_version(public_only=False) is not None):
            new_version = self._create_version_from_session(
                session, user, forked)
            new_version.save()
            self._save_subtitles(new_version.subtitle_set, subtitles,
                                 new_version.is_forked)

        language.release_writelock()
        if completed is not None:
            language.is_complete = completed
        if new_title is not None:
            language.title = new_title
        language.save()

        if new_version is not None:
            video_changed_tasks.delay(language.video.id, new_version.id)
        else:
            video_changed_tasks.delay(language.video.id)

        # we have a default user message, since the UI lets users save non
        # changed subs, but the backend will realize and will not save that
        # version. In those cases, we want to show the defatul user message.
        user_message = "Your changes have been saved. It will take a minute or so for your subtitles to appear."
        if new_version is not None and new_version.version_no == 0:
            user_message = "Your changes have been saved. It will take a minute or so for your subtitles to appear."
        elif new_version and is_moderated(new_version):
            if user_can_moderate(language.video, user) is False:
                user_message = """This video is moderated by %s. 

You will not see your subtitles in our widget when you leave this page, they will only appear on our site. We have saved your work for the team moderator to review. After they approve your subtitles, they will show up on our site and in the widget.
""" % (new_version.video.moderated_by.name)
        return {'user_message': user_message, 'response': 'ok'}
Exemple #4
0
    def save_finished(self, user, session, subtitles, new_title=None, completed=None, forked=False):
        from apps.teams.moderation import is_moderated, user_can_moderate

        language = session.language
        new_version = None
        if subtitles is not None and (len(subtitles) > 0 or language.latest_version(public_only=False) is not None):
            new_version = self._create_version_from_session(session, user, forked)
            new_version.save()
            self._save_subtitles(new_version.subtitle_set, subtitles, new_version.is_forked)

        language.release_writelock()
        if completed is not None:
            language.is_complete = completed
        if new_title is not None:
            language.title = new_title
        language.save()

        if new_version is not None:
            video_changed_tasks.delay(language.video.id, new_version.id)
        else:
            video_changed_tasks.delay(language.video.id)

        # we have a default user message, since the UI lets users save non
        # changed subs, but the backend will realize and will not save that
        # version. In those cases, we want to show the defatul user message.
        user_message = "Your changes have been saved. It will take a minute or so for your subtitles to appear."
        if new_version is not None and new_version.version_no == 0:
            user_message = "Your changes have been saved. It will take a minute or so for your subtitles to appear."
        elif new_version and is_moderated(new_version):
            if user_can_moderate(language.video, user) is False:
                user_message = """This video is moderated by %s. 

You will not see your subtitles in our widget when you leave this page, they will only appear on our site. We have saved your work for the team moderator to review. After they approve your subtitles, they will show up on our site and in the widget.
""" % (
                    new_version.video.moderated_by.name
                )
        return {"user_message": user_message, "response": "ok"}