Beispiel #1
0
def upload(request):
    """Upload translated resource."""
    try:
        slug = request.POST['slug']
        code = request.POST['code']
        part = request.POST['part']
    except MultiValueDictKeyError:
        raise Http404

    locale = get_object_or_404(Locale, code=code)
    if not request.user.has_perm('base.can_translate_locale', locale):
        return HttpResponseForbidden("Forbidden: You don't have permission to upload files")

    form = forms.UploadFileForm(request.POST, request.FILES)

    if form.is_valid():
        f = request.FILES['uploadfile']
        utils.handle_upload_content(slug, code, part, f, request.user)
        messages.success(request, 'Translations updated from uploaded file.')
    else:
        for field, errors in form.errors.items():
            for error in errors:
                messages.error(request, error)

    return translate(request, code, slug, part)
Beispiel #2
0
def translate(request, locale, slug, part):
    """Translate view."""
    locale = get_object_or_404(Locale, code__iexact=locale)
    project = get_object_or_404(Project.objects.available(), slug=slug)

    if locale not in project.locales.all():
        raise Http404

    projects = (
        Project.objects.available()
        .prefetch_related('subpage_set')
        .order_by('name')
    )

    paths = [part] if part != 'all-resources' else None
    authors = Translation.authors(locale, project, paths).serialize()

    return render(request, 'translate.html', {
        'download_form': forms.DownloadFileForm(),
        'upload_form': forms.UploadFileForm(),
        'locale': locale,
        'locales': Locale.objects.available(),
        'part': part,
        'project': project,
        'projects': projects,
        'authors': authors,
    })
Beispiel #3
0
def upload(request):
    """Upload translated resource."""
    try:
        slug = request.POST["slug"]
        code = request.POST["code"]
        part = request.POST["part"]
    except MultiValueDictKeyError:
        raise Http404

    locale = get_object_or_404(Locale, code=code)
    project = get_object_or_404(Project.objects.visible_for(request.user), slug=slug)

    if not request.user.can_translate(
        project=project, locale=locale
    ) or utils.readonly_exists(project, locale):
        return HttpResponseForbidden("You don't have permission to upload files.")

    form = forms.UploadFileForm(request.POST, request.FILES)

    if form.is_valid():
        f = request.FILES["uploadfile"]
        utils.handle_upload_content(slug, code, part, f, request.user)
        messages.success(request, "Translations updated from uploaded file.")
    else:
        for field, errors in form.errors.items():
            for error in errors:
                messages.error(request, error)

    response = HttpResponse(content="", status=303)
    response["Location"] = reverse(
        "pontoon.translate", kwargs={"locale": code, "project": slug, "resource": part},
    )
    return response
Beispiel #4
0
def translate(request, locale, slug, part):
    """Translate view."""
    locale = get_object_or_404(Locale, code__iexact=locale)
    project = get_object_or_404(Project.objects.distinct(),
                                slug=slug,
                                disabled=False,
                                resources__isnull=False)

    projects = (Project.objects.filter(
        disabled=False, pk__in=Resource.objects.values(
            'project')).prefetch_related('subpage_set').order_by("name"))

    return render(
        request, 'translate.html', {
            'accept_language':
            utils.get_project_locale_from_request(request, Locale.objects),
            'download_form':
            forms.DownloadFileForm(),
            'upload_form':
            forms.UploadFileForm(),
            'locale':
            locale,
            'locales':
            Locale.objects.all(),
            'part':
            part,
            'project':
            project,
            'projects':
            projects,
        })
Beispiel #5
0
def translate(request, locale, slug, part):
    """Translate view."""
    locale = get_object_or_404(Locale, code=locale)

    projects = (
        Project.objects.available()
        .prefetch_related('subpage_set', 'tag_set')
        .order_by('name')
    )

    if slug.lower() == 'all-projects':
        project = Project(name='All Projects', slug=slug.lower())

    else:
        project = get_object_or_404(Project.objects.available(), slug=slug)
        if locale not in project.locales.all():
            raise Http404
    return render(request, 'translate.html', {
        'download_form': forms.DownloadFileForm(),
        'upload_form': forms.UploadFileForm(),
        'locale': locale,
        'locale_projects': locale.available_projects_list(),
        'locales': Locale.objects.available(),
        'part': part,
        'project': project,
        'projects': projects,
    })
Beispiel #6
0
def translate(request, locale, slug, part):
    """Translate view."""
    locale = get_object_or_404(Locale, code=locale)

    projects = (
        Project.objects.available()
        .prefetch_related('subpage_set', 'tag_set')
        .order_by('name')
    )

    if slug.lower() == 'all-projects':
        project = Project(name='All Projects', slug=slug.lower())

    else:
        project = get_object_or_404(Project.objects.available(), slug=slug)
        if locale not in project.locales.all():
            raise Http404

    return render(request, 'translate.html', {
        'download_form': forms.DownloadFileForm(),
        'upload_form': forms.UploadFileForm(),
        'locale': locale,
        'locale_projects': locale.available_projects_list(),
        'locales': Locale.objects.available(),
        'part': part,
        'project': project,
        'projects': projects,
        'is_google_translate_supported': bool(settings.GOOGLE_TRANSLATE_API_KEY),
        'is_microsoft_translator_supported': bool(settings.MICROSOFT_TRANSLATOR_API_KEY),
    })
Beispiel #7
0
def translate(request, locale, slug, part):
    """Translate view."""
    # Redirect the user to the Translate.Next app if needed.
    # To be removed as part of bug 1527853.
    user = request.user
    if (waffle.switch_is_active('translate_next') and user.is_authenticated
            and user.profile.use_translate_next):
        url = reverse('pontoon.translate.next',
                      kwargs={
                          'project': slug,
                          'locale': locale,
                          'resource': part,
                      })
        query = request.GET.urlencode()
        if query:
            url += '?' + query

        return redirect(url)

    locale = get_object_or_404(Locale, code=locale)

    projects = (Project.objects.available().prefetch_related(
        'subpage_set', 'tag_set').order_by('name'))

    if slug.lower() == 'all-projects':
        project = Project(name='All Projects', slug=slug.lower())

    else:
        project = get_object_or_404(Project.objects.available(), slug=slug)
        if locale not in project.locales.all():
            raise Http404

    return render(
        request, 'translate.html', {
            'download_form':
            forms.DownloadFileForm(),
            'upload_form':
            forms.UploadFileForm(),
            'locale':
            locale,
            'locale_projects':
            locale.available_projects_list(),
            'locales':
            Locale.objects.available(),
            'part':
            part,
            'project':
            project,
            'projects':
            projects,
            'is_google_translate_supported':
            bool(settings.GOOGLE_TRANSLATE_API_KEY),
            'is_microsoft_translator_supported':
            bool(settings.MICROSOFT_TRANSLATOR_API_KEY),
        })
Beispiel #8
0
def translate(request, locale, slug, part):
    """Translate view."""
    locale = get_object_or_404(Locale, code__iexact=locale)
    project = get_object_or_404(Project.objects.available(), slug=slug)

    projects = (
        Project.objects.available()
        .prefetch_related('subpage_set')
        .order_by("name")
    )

    return render(request, 'translate.html', {
        'download_form': forms.DownloadFileForm(),
        'upload_form': forms.UploadFileForm(),
        'locale': locale,
        'locales': Locale.objects.available(),
        'part': part,
        'project': project,
        'projects': projects,
    })
Beispiel #9
0
def upload(request):
    """Upload translated resource."""
    try:
        slug = request.POST['slug']
        code = request.POST['code']
        part = request.POST['part']
    except MultiValueDictKeyError:
        raise Http404

    locale = get_object_or_404(Locale, code=code)
    project = get_object_or_404(Project, slug=slug)

    if (not request.user.can_translate(project=project, locale=locale)
            or utils.readonly_exists(project, locale)):
        return HttpResponseForbidden(
            "You don't have permission to upload files.")

    form = forms.UploadFileForm(request.POST, request.FILES)

    if form.is_valid():
        f = request.FILES['uploadfile']
        utils.handle_upload_content(slug, code, part, f, request.user)
        messages.success(request, 'Translations updated from uploaded file.')
    else:
        for field, errors in form.errors.items():
            for error in errors:
                messages.error(request, error)

    response = HttpResponse(content='', status=303)
    response['Location'] = reverse(
        'pontoon.translate',
        kwargs={
            'locale': code,
            'project': slug,
            'resource': part,
        },
    )
    return response