Beispiel #1
0
    def file(self, request, **kwargs):
        obj = self.get_object()
        if request.method == 'GET':
            fmt = self.format_kwarg or request.query_params.get('format')
            return download_translation_file(obj, fmt)

        if (not request.user.has_perm('upload.perform', obj) or
                obj.component.locked):
            raise PermissionDenied()

        if 'file' not in request.data:
            raise ParseError('Missing file parameter')

        serializer = UploadRequestSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        if (serializer.validated_data['overwrite'] and
                not request.user.has_perm('upload.overwrite', obj)):
            raise PermissionDenied()

        not_found, skipped, accepted, total = obj.merge_upload(
            request,
            serializer.validated_data['file'],
            serializer.validated_data['overwrite'],
        )

        return Response(data={
            'not_found': not_found,
            'skipped': skipped,
            'accepted': accepted,
            'total': total,
            # Compatibility with older less detailed API
            'result': accepted > 0,
            'count': total,
        })
Beispiel #2
0
    def file(self, request, **kwargs):
        obj = self.get_object()
        if request.method == 'GET':
            fmt = self.format_kwarg or request.query_params.get('format')
            return download_translation_file(obj, fmt)

        if (not can_upload_translation(request.user, obj)
                or obj.is_locked(request.user)):
            raise PermissionDenied()

        if 'file' not in request.data:
            raise ParseError('Missing file parameter')

        not_found, skipped, accepted, total = obj.merge_upload(
            request, request.data['file'], False)

        return Response(
            data={
                'not_found': not_found,
                'skipped': skipped,
                'accepted': accepted,
                'total': total,
                # Compatibility with older less detailed API
                'result': accepted > 0,
                'count': total,
            })
Beispiel #3
0
def download_language_pack(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)

    if not obj.supports_language_pack():
        raise Http404('Language pack download not supported')

    return download_translation_file(
        obj, obj.subproject.file_format_cls.language_pack)
Beispiel #4
0
def download_language_pack(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)

    if not obj.supports_language_pack():
        raise Http404('Language pack download not supported')

    return download_translation_file(
        obj,
        obj.subproject.file_format_cls.language_pack
    )
Beispiel #5
0
def download_translation_format(request, project, component, lang, fmt):
    obj = get_translation(request, project, component, lang)

    form = SearchForm(request.GET)
    if form.is_valid():
        units = obj.unit_set.search(
            form.cleaned_data,
            translation=obj,
        )
    else:
        units = obj.unit_set.all()

    return download_translation_file(obj, fmt, units)
Beispiel #6
0
def download_translation_format(request, project, component, lang, fmt):
    obj = get_translation(request, project, component, lang)

    form = SearchForm(request.GET)
    if form.is_valid():
        units = obj.unit_set.search(
            form.cleaned_data,
            translation=obj,
        )
    else:
        units = obj.unit_set.all()

    return download_translation_file(obj, fmt, units)
Beispiel #7
0
    def file(self, request, **kwargs):
        obj = self.get_object()
        if request.method == 'GET':
            fmt = self.format_kwarg or request.query_params.get('format')
            return download_translation_file(obj, fmt)

        if (not can_upload_translation(request.user, obj)
                or obj.is_locked(request.user)):
            raise PermissionDenied()

        ret, count = obj.merge_upload(request, request.data['file'], False)

        return Response(data={'result': ret, 'count': count})
Beispiel #8
0
def download_translation_format(request, project, component, lang):
    obj = get_translation(request, project, component, lang)

    form = DownloadForm(request.GET)
    if not form.is_valid():
        show_form_errors(request, form)
        return redirect(obj)

    units = obj.unit_set.search(
        form.cleaned_data,
        translation=obj,
    )

    return download_translation_file(obj, form.cleaned_data['format'], units)
Beispiel #9
0
def download_translation_format(request, project, component, lang):
    obj = get_translation(request, project, component, lang)

    form = DownloadForm(request.GET)
    if not form.is_valid():
        show_form_errors(request, form)
        return redirect(obj)

    units = obj.unit_set.search(
        form.cleaned_data,
        translation=obj,
    )

    return download_translation_file(obj, form.cleaned_data['format'], units)
Beispiel #10
0
    def file(self, request, **kwargs):
        obj = self.get_object()
        if request.method == 'GET':
            fmt = self.format_kwarg or request.query_params.get('format')
            return download_translation_file(obj, fmt)

        if (not can_upload_translation(request.user, obj) or
                obj.is_locked(request.user)):
            raise PermissionDenied()

        ret, count = obj.merge_upload(
            request,
            request.data['file'],
            False
        )

        return Response(data={'result': ret, 'count': count})
Beispiel #11
0
def download_translation(request, project, component, lang):
    obj = get_translation(request, project, component, lang)

    kwargs = {}

    if 'format' in request.GET or 'type' in request.GET:
        form = DownloadForm(request.GET)
        if not form.is_valid():
            show_form_errors(request, form)
            return redirect(obj)

        kwargs['units'] = obj.unit_set.search(
            form.cleaned_data,
            translation=obj,
        )
        kwargs['fmt'] = form.cleaned_data['format']

    return download_translation_file(obj, **kwargs)
Beispiel #12
0
    def file(self, request, **kwargs):
        obj = self.get_object()
        if request.method == 'GET':
            fmt = self.format_kwarg or request.query_params.get('format')
            return download_translation_file(obj, fmt)

        if (not request.user.has_perm('upload.perform', obj)
                or obj.component.locked):
            raise PermissionDenied()

        if 'file' not in request.data:
            raise ParseError('Missing file parameter')

        serializer = UploadRequestSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        if (serializer.validated_data['overwrite']
                and not request.user.has_perm('upload.overwrite', obj)):
            raise PermissionDenied()

        can_author = request.user.has_perm('upload.authorship', obj)

        not_found, skipped, accepted, total = obj.merge_upload(
            request,
            serializer.validated_data['file'],
            serializer.validated_data['overwrite'],
            serializer.validated_data['email'] if can_author else None,
            serializer.validated_data['author'] if can_author else None,
        )

        return Response(
            data={
                'not_found': not_found,
                'skipped': skipped,
                'accepted': accepted,
                'total': total,
                # Compatibility with older less detailed API
                'result': accepted > 0,
                'count': total,
            })
Beispiel #13
0
    def file(self, request, **kwargs):
        obj = self.get_object()
        project = obj.subproject.project
        if request.method == 'GET':
            fmt = self.format_kwarg or request.query_params.get('format')
            return download_translation_file(obj, fmt)

        if (not can_upload_translation(request.user, obj)
                or obj.subproject.locked):
            raise PermissionDenied()

        if 'file' not in request.data:
            raise ParseError('Missing file parameter')

        serializer = UploadRequestSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        if (serializer.validated_data['overwrite']
                and not can_overwrite_translation(request.user, project)):
            raise PermissionDenied()

        not_found, skipped, accepted, total = obj.merge_upload(
            request,
            request.data['file'],
            serializer.validated_data['overwrite'],
        )

        return Response(
            data={
                'not_found': not_found,
                'skipped': skipped,
                'accepted': accepted,
                'total': total,
                # Compatibility with older less detailed API
                'result': accepted > 0,
                'count': total,
            })
Beispiel #14
0
def download_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)

    return download_translation_file(obj)
Beispiel #15
0
def download_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)

    return download_translation_file(obj)