예제 #1
0
파일: views.py 프로젝트: AlfredWei/weblate
    def repository(self, request, **kwargs):
        obj = self.get_object()

        if hasattr(obj, 'subproject'):
            project = obj.subproject.project
        elif hasattr(obj, 'project'):
            project = obj.project
        else:
            project = obj

        if request.method == 'POST':
            serializer = RepoRequestSerializer(data=request.data)
            serializer.is_valid(raise_exception=True)

            result = self.repository_operation(
                request, obj, project, serializer.validated_data['operation']
            )
            return Response(
                data={
                    'result': result
                }
            )

        if not can_see_repository_status(request.user, project):
            raise PermissionDenied()

        return Response(
            data={
                'needs_commit': obj.repo_needs_commit(),
                'needs_merge': obj.repo_needs_merge(),
                'needs_push': obj.repo_needs_push(),
            }
        )
예제 #2
0
파일: views.py 프로젝트: AlfredWei/weblate
    def repository(self, request, **kwargs):
        obj = self.get_object()

        if hasattr(obj, 'subproject'):
            project = obj.subproject.project
        elif hasattr(obj, 'project'):
            project = obj.project
        else:
            project = obj

        if request.method == 'POST':
            serializer = RepoRequestSerializer(data=request.data)
            serializer.is_valid(raise_exception=True)

            result = self.repository_operation(
                request, obj, project, serializer.validated_data['operation'])
            return Response(data={'result': result})

        if not can_see_repository_status(request.user, project):
            raise PermissionDenied()

        return Response(
            data={
                'needs_commit': obj.repo_needs_commit(),
                'needs_merge': obj.repo_needs_merge(),
                'needs_push': obj.repo_needs_push(),
            })
예제 #3
0
파일: views.py 프로젝트: tsabi/weblate
    def repository(self, request, **kwargs):
        obj = self.get_object()

        if isinstance(obj, Translation):
            project = obj.component.project
        elif isinstance(obj, Component):
            project = obj.project
        else:
            project = obj

        if request.method == "POST":
            serializer = RepoRequestSerializer(data=request.data)
            serializer.is_valid(raise_exception=True)

            data = {
                "result": self.repository_operation(
                    request, obj, project, serializer.validated_data["operation"]
                )
            }

            storage = get_messages(request)
            if storage:
                data["detail"] = "\n".join(m.message for m in storage)

            return Response(data)

        if not request.user.has_perm("meta:vcs.status", project):
            raise PermissionDenied()

        data = {
            "needs_commit": obj.needs_commit(),
            "needs_merge": obj.repo_needs_merge(),
            "needs_push": obj.repo_needs_push(),
        }

        if isinstance(obj, Project):
            data["url"] = reverse(
                "api:project-repository", kwargs={"slug": obj.slug}, request=request
            )
        else:

            if isinstance(obj, Translation):
                component = obj.component
                data["url"] = reverse(
                    "api:translation-repository",
                    kwargs={
                        "component__project__slug": component.project.slug,
                        "component__slug": component.slug,
                        "language__code": obj.language.code,
                    },
                    request=request,
                )
            else:
                component = obj
                data["url"] = reverse(
                    "api:component-repository",
                    kwargs={"project__slug": obj.project.slug, "slug": obj.slug},
                    request=request,
                )

            data["remote_commit"] = component.get_last_remote_commit()
            data["status"] = component.repository.status()
            changes = Change.objects.filter(
                action__in=Change.ACTIONS_REPOSITORY, component=component
            ).order_by("-id")

            if changes.exists() and changes[0].is_merge_failure():
                data["merge_failure"] = changes[0].target
            else:
                data["merge_failure"] = None

        return Response(data)
예제 #4
0
파일: views.py 프로젝트: nijel/weblate
    def repository(self, request, **kwargs):
        obj = self.get_object()

        if isinstance(obj, Translation):
            project = obj.component.project
        elif isinstance(obj, Component):
            project = obj.project
        else:
            project = obj

        if request.method == 'POST':
            serializer = RepoRequestSerializer(data=request.data)
            serializer.is_valid(raise_exception=True)

            data = {
                'result': self.repository_operation(
                    request, obj, project,
                    serializer.validated_data['operation']
                )
            }

            storage = get_messages(request)
            if storage:
                data['detail'] = '\n'.join([m.message for m in storage])

            return Response(data)

        if not request.user.has_perm('meta:vcs.status', project):
            raise PermissionDenied()

        data = {
            'needs_commit': obj.needs_commit(),
            'needs_merge': obj.repo_needs_merge(),
            'needs_push': obj.repo_needs_push(),
        }

        if isinstance(obj, Project):
            data['url'] = reverse(
                'api:project-repository',
                kwargs={'slug': obj.slug},
                request=request
            )
        else:
            data['remote_commit'] = obj.get_last_remote_commit()

            if isinstance(obj, Translation):
                component = obj.component
                data['url'] = reverse(
                    'api:translation-repository',
                    kwargs={
                        'component__project__slug': component.project.slug,
                        'component__slug': component.slug,
                        'language__code': obj.language.code,
                    },
                    request=request
                )
                data['status'] = obj.component.repository.status()
                changes = Change.objects.filter(
                    action__in=Change.ACTIONS_REPOSITORY,
                    component=obj.component,
                )
            else:
                data['url'] = reverse(
                    'api:component-repository',
                    kwargs={
                        'project__slug': obj.project.slug,
                        'slug': obj.slug,
                    },
                    request=request
                )
                data['status'] = obj.repository.status()
                changes = Change.objects.filter(
                    action__in=Change.ACTIONS_REPOSITORY,
                    component=obj,
                )

            if changes.exists() and changes[0].is_merge_failure():
                data['merge_failure'] = changes[0].target
            else:
                data['merge_failure'] = None

        return Response(data)
예제 #5
0
    def repository(self, request, **kwargs):
        obj = self.get_object()

        if isinstance(obj, Translation):
            project = obj.subproject.project
        elif isinstance(obj, SubProject):
            project = obj.project
        else:
            project = obj

        if request.method == 'POST':
            serializer = RepoRequestSerializer(data=request.data)
            serializer.is_valid(raise_exception=True)

            data = {
                'result':
                self.repository_operation(
                    request, obj, project,
                    serializer.validated_data['operation'])
            }

            storage = get_messages(request)
            if storage:
                data['detail'] = '\n'.join([m.message for m in storage])

            return Response(data)

        if not can_see_repository_status(request.user, project):
            raise PermissionDenied()

        data = {
            'needs_commit': obj.repo_needs_commit(),
            'needs_merge': obj.repo_needs_merge(),
            'needs_push': obj.repo_needs_push(),
        }

        if isinstance(obj, Project):
            data['url'] = reverse('api:project-repository',
                                  kwargs={'slug': obj.slug},
                                  request=request)
        else:
            data['remote_commit'] = obj.get_last_remote_commit()

            if isinstance(obj, Translation):
                subproject = obj.subproject
                data['url'] = reverse('api:translation-repository',
                                      kwargs={
                                          'subproject__project__slug':
                                          subproject.project.slug,
                                          'subproject__slug':
                                          subproject.slug,
                                          'language__code':
                                          obj.language.code,
                                      },
                                      request=request)
                data['status'] = obj.subproject.repository.status()
                changes = Change.objects.filter(
                    action__in=Change.ACTIONS_REPOSITORY,
                    subproject=obj.subproject,
                )
            else:
                data['url'] = reverse('api:component-repository',
                                      kwargs={
                                          'project__slug': obj.project.slug,
                                          'slug': obj.slug,
                                      },
                                      request=request)
                data['status'] = obj.repository.status()
                changes = Change.objects.filter(
                    action__in=Change.ACTIONS_REPOSITORY,
                    subproject=obj,
                )

            if changes.exists() and changes[0].is_merge_failure():
                data['merge_failure'] = changes[0].target
            else:
                data['merge_failure'] = None

        return Response(data)