Ejemplo n.º 1
0
    def get_queryset(self):
        """Get export tasks for this user."""
        repo_slug = self.kwargs['repo_slug']
        export_tasks = [
            task for task in get_tasks(self.request.session).values()
            if task['task_type'] == EXPORT_TASK_TYPE and
            task['task_info']['repo_slug'] == repo_slug
        ]

        task_results = [create_task_result_dict(task) for task in export_tasks]

        return [
            {
                "id": result['id'],
                "status": result['status'],
                "url": result['result']['url'],
                "collision": result['result']['collision']
            } for result in task_results
        ]
Ejemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        """
        Create a new export task for this user.

        Note that this also cancels and clears any old tasks for the user,
        so there should be only one task in the list at any time.

        The export list will be left alone. Once the list is exported
        the client may DELETE the export list as a separate REST call.
        """
        repo_slug = self.kwargs['repo_slug']
        export_tasks = [
            task for task in get_tasks(self.request.session).values()
            if task['task_type'] == EXPORT_TASK_TYPE and
            task['task_info']['repo_slug'] == repo_slug
        ]

        # Cancel any old tasks.
        for task in export_tasks:
            remove_task(self.request.session, task['id'])

        try:
            ids = self.request.data['ids']
        except KeyError:
            raise ValidationError("Missing ids")

        task = create_task(
            self.request.session,
            self.request.user.id,
            EXPORT_TASK_TYPE,
            {
                'repo_slug': repo_slug,
                'ids': ids
            }
        )

        return Response(
            {"id": task['id']},
            status=status.HTTP_201_CREATED
        )
Ejemplo n.º 3
0
    def get_queryset(self):
        """Get tasks for this user."""
        tasks = get_tasks(self.request.session)

        return [create_task_result_dict(task) for task in tasks.values()]