예제 #1
0
파일: views.py 프로젝트: Harpreetkk/Amara
def rollback(request, version):
    is_writelocked = version.subtitle_language.is_writelocked
    team_video = version.video.get_team_video()
    if team_video and not can_rollback_language(request.user,
                                                version.subtitle_language):
        messages.error(
            request,
            _(u"You don't have permission to rollback "
              "this language"))
    elif is_writelocked:
        messages.error(
            request,
            u'Can not rollback now, because someone is editing subtitles.')
    elif not version.next_version():
        messages.error(request,
                       message=u'Can not rollback to the last version')
    else:
        messages.success(request, message=u'Rollback successful')
        version = rollback_to(version.video,
                              version.subtitle_language.language_code,
                              version_number=version.version_number,
                              rollback_author=request.user)
        video_changed_tasks.delay(version.video.id, version.id)
        return redirect(version.subtitle_language.get_absolute_url() +
                        '#revisions')
    return redirect(version)
예제 #2
0
def diffing(request, first_version, second_pk):
    language = first_version.subtitle_language
    second_version = get_object_or_404(
        SubtitleVersion.objects.extant(),
        pk=second_pk, subtitle_language=language)

    if first_version.video != second_version.video:
        # this is either a bad bug, or someone evil
        raise "Revisions for diff videos"

    if first_version.pk < second_version.pk:
        # this is just stupid Instead of first, second meaning
        # chronological order (first cames before second)
        # it means  the opposite, so make sure the first version
        # has a larger version no than the second
        first_version, second_version = second_version, first_version

    video = first_version.subtitle_language.video
    diff_data = diff_subs(first_version.get_subtitles(), second_version.get_subtitles(), mappings=HTMLGenerator.MAPPINGS)
    team_video = video.get_team_video()
    first_version_previous = first_version.previous_version()
    first_version_next = first_version.next_version()
    second_version_previous = second_version.previous_version()
    second_version_next = second_version.next_version()
    context = {
        'video': video,
        'diff_data': diff_data,
        'language': language,
        'first_version': first_version,
        'second_version': second_version,
        'latest_version': language.get_tip(),
        'first_version_previous': first_version_previous if (first_version_previous != second_version) else None,
        'first_version_next': first_version_next,
        'second_version_previous': second_version_previous,
        'second_version_next': second_version_next if (second_version_next != first_version) else None,
    }
    if team_video and not can_rollback_language(request.user, language):
        context['rollback_allowed'] = False
    else:
        context['rollback_allowed'] = True

    context['width'] = video_size["small"]["width"]
    context['height'] = video_size["small"]["height"]
    context['video_url'] = video.get_video_url()

    return render_to_response('videos/diffing.html', context,
                              context_instance=RequestContext(request))
예제 #3
0
파일: views.py 프로젝트: Harpreetkk/Amara
def diffing(request, first_version, second_pk):
    language = first_version.subtitle_language
    second_version = get_object_or_404(
        sub_models.SubtitleVersion.objects.extant(),
        pk=second_pk,
        subtitle_language=language)

    if first_version.video != second_version.video:
        # this is either a bad bug, or someone evil
        raise "Revisions for diff videos"

    if first_version.pk < second_version.pk:
        # this is just stupid Instead of first, second meaning
        # chronological order (first cames before second)
        # it means  the opposite, so make sure the first version
        # has a larger version no than the second
        first_version, second_version = second_version, first_version

    video = first_version.subtitle_language.video
    diff_data = diff_subs(first_version.get_subtitles(),
                          second_version.get_subtitles())
    team_video = video.get_team_video()

    context = widget.add_onsite_js_files({})
    context['video'] = video
    context['diff_data'] = diff_data
    context['language'] = language
    context['first_version'] = first_version
    context['second_version'] = second_version
    context['latest_version'] = language.get_tip()
    if team_video and not can_rollback_language(request.user, language):
        context['rollback_allowed'] = False
    else:
        context['rollback_allowed'] = True
    context['widget0_params'] = \
        _widget_params(request, video,
                       first_version.version_number)
    context['widget1_params'] = \
        _widget_params(request, video,
                       second_version.version_number)
    return render_to_response('videos/diffing.html',
                              context,
                              context_instance=RequestContext(request))
예제 #4
0
 def calc_rollback_allowed(self, request, version, language):
     if version and version.next_version():
         return (version.video.get_team_video() is None or
                 can_rollback_language(request.user, language))
     else:
         return False