当前位置: 首页>>代码示例>>Python>>正文


Python utils.get_object_or_404函数代码示例

本文整理汇总了Python中taiga.base.api.utils.get_object_or_404函数的典型用法代码示例。如果您正苦于以下问题:Python get_object_or_404函数的具体用法?Python get_object_or_404怎么用?Python get_object_or_404使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_object_or_404函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _bulk_update_order

    def _bulk_update_order(self, order_field, request, **kwargs):
        validator = validators.UpdateUserStoriesOrderBulkValidator(data=request.DATA)
        if not validator.is_valid():
            return response.BadRequest(validator.errors)

        data = validator.data
        project = get_object_or_404(Project, pk=data["project_id"])
        status = None
        status_id = data.get("status_id", None)
        if status_id is not None:
            status = get_object_or_404(UserStoryStatus, pk=status_id)

        milestone = None
        milestone_id = data.get("milestone_id", None)
        if milestone_id is not None:
            milestone = get_object_or_404(Milestone, pk=milestone_id)

        self.check_permissions(request, "bulk_update_order", project)
        if project.blocked_code is not None:
            raise exc.Blocked(_("Blocked element"))

        ret = services.update_userstories_order_in_bulk(data["bulk_stories"],
                                                        order_field,
                                                        project,
                                                        status=status,
                                                        milestone=milestone)
        return response.Ok(ret)
开发者ID:tnir,项目名称:taiga-back,代码行数:27,代码来源:api.py

示例2: by_slug

 def by_slug(self, request):
     iframe_slug = request.QUERY_PARAMS.get("slug", None)
     project_slug = request.QUERY_PARAMS.get("pslug", None)
     if iframe_slug and project_slug:
         iframe = get_object_or_404(IframePlugin, slug=iframe_slug,
                                    project__slug=project_slug)
         return self.retrieve(request, pk=iframe.pk)
     if project_slug:  # no iframe slug, return iframes for this project
         project = get_object_or_404(Project, slug=project_slug)
         self.queryset = IframePlugin.objects.filter(
             project__slug=project.slug)
         return self.list(IframePlugin, request)
     raise Http404(self.empty_error)
开发者ID:msiniy,项目名称:taiga-plugin-iframe,代码行数:13,代码来源:api.py

示例3: bulk_update_milestone

    def bulk_update_milestone(self, request, **kwargs):
        validator = validators.UpdateMilestoneBulkValidator(data=request.DATA)
        if not validator.is_valid():
            return response.BadRequest(validator.errors)

        data = validator.data
        project = get_object_or_404(Project, pk=data["project_id"])
        milestone = get_object_or_404(Milestone, pk=data["milestone_id"])

        self.check_permissions(request, "bulk_update_milestone", project)

        ret = services.update_issues_milestone_in_bulk(data["bulk_issues"], milestone)

        return response.Ok(ret)
开发者ID:taigaio,项目名称:taiga-back,代码行数:14,代码来源:api.py

示例4: bulk_update_milestone

    def bulk_update_milestone(self, request, **kwargs):
        serializer = serializers.UpdateMilestoneBulkSerializer(data=request.DATA)
        if not serializer.is_valid():
            return response.BadRequest(serializer.errors)

        data = serializer.data
        project = get_object_or_404(Project, pk=data["project_id"])
        milestone = get_object_or_404(Milestone, pk=data["milestone_id"])

        self.check_permissions(request, "bulk_update_milestone", project)

        services.update_userstories_milestone_in_bulk(data["bulk_stories"], milestone)
        services.snapshot_userstories_in_bulk(data["bulk_stories"], request.user)

        return response.NoContent()
开发者ID:SKOx0,项目名称:taiga-back,代码行数:15,代码来源:api.py

示例5: downvote

    def downvote(self, request, pk=None):
        issue = get_object_or_404(models.Issue, pk=pk)

        self.check_permissions(request, 'downvote', issue)

        votes_service.remove_vote(issue, user=request.user)
        return response.Ok()
开发者ID:lcyhff,项目名称:taiga-back,代码行数:7,代码来源:api.py

示例6: retrieve

    def retrieve(self, request, pk, *args, **kwargs):
        throttle = throttling.ImportDumpModeRateThrottle()

        if not throttle.allow_request(request, self):
            self.throttled(request, throttle.wait())

        project = get_object_or_404(self.get_queryset(), pk=pk)
        self.check_permissions(request, 'export_project', project)

        dump_format = request.QUERY_PARAMS.get("dump_format", "plain")

        if settings.CELERY_ENABLED:
            task = tasks.dump_project.delay(request.user, project, dump_format)
            tasks.delete_project_dump.apply_async((project.pk, project.slug, task.id, dump_format),
                                                  countdown=settings.EXPORTS_TTL)
            return response.Accepted({"export_id": task.id})

        if dump_format == "gzip":
            path = "exports/{}/{}-{}.json.gz".format(project.pk, project.slug, uuid.uuid4().hex)
            storage_path = default_storage.path(path)
            with default_storage.open(storage_path, mode="wb") as outfile:
                services.render_project(project, gzip.GzipFile(fileobj=outfile))
        else:
            path = "exports/{}/{}-{}.json".format(project.pk, project.slug, uuid.uuid4().hex)
            storage_path = default_storage.path(path)
            with default_storage.open(storage_path, mode="wb") as outfile:
                services.render_project(project, outfile)

        response_data = {
            "url": default_storage.url(path)
        }
        return response.Ok(response_data)
开发者ID:GBCarpiArtStudio,项目名称:taiga-back,代码行数:32,代码来源:api.py

示例7: watched

    def watched(self, request, *args, **kwargs):
        for_user = get_object_or_404(models.User, **kwargs)
        from_user = request.user
        self.check_permissions(request, 'watched', for_user)
        filters = {
            "type": request.GET.get("type", None),
            "q": request.GET.get("q", None),
        }

        self.object_list = services.get_watched_list(for_user, from_user, **filters)
        page = self.paginate_queryset(self.object_list)
        elements = page.object_list if page is not None else self.object_list

        extra_args_liked = {
            "user_watching": services.get_watched_content_for_user(request.user),
            "user_likes": services.get_liked_content_for_user(request.user),
        }

        extra_args_voted = {
            "user_watching": services.get_watched_content_for_user(request.user),
            "user_votes": services.get_voted_content_for_user(request.user),
        }

        response_data = []
        for elem in elements:
            if elem["type"] == "project":
                # projects are liked objects
                response_data.append(serializers.LikedObjectSerializer(elem, **extra_args_liked).data )
            else:
                # stories, tasks and issues are voted objects
                response_data.append(serializers.VotedObjectSerializer(elem, **extra_args_voted).data )

        return response.Ok(response_data)
开发者ID:CrypticGator,项目名称:taiga-back,代码行数:33,代码来源:api.py

示例8: favourites

    def favourites(self, request, *args, **kwargs):
        for_user = get_object_or_404(models.User, **kwargs)
        from_user = request.user
        self.check_permissions(request, 'favourites', for_user)
        filters = {
            "type": request.GET.get("type", None),
            "action": request.GET.get("action", None),
            "q": request.GET.get("q", None),
        }

        self.object_list = services.get_favourites_list(for_user, from_user, **filters)
        page = self.paginate_queryset(self.object_list)

        extra_args = {
            "many": True,
            "user_votes": services.get_voted_content_for_user(request.user),
            "user_watching": services.get_watched_content_for_user(request.user),
        }

        if page is not None:
            serializer = serializers.FavouriteSerializer(page.object_list, **extra_args)
        else:
            serializer = serializers.FavouriteSerializer(self.object_list, **extra_args)

        return response.Ok(serializer.data)
开发者ID:laomouzi,项目名称:taiga-back,代码行数:25,代码来源:api.py

示例9: bulk_create

    def bulk_create(self, request, **kwargs):
        validator = validators.CreateRelatedUserStoriesBulkValidator(data=request.DATA)
        if not validator.is_valid():
            return response.BadRequest(validator.errors)

        data = validator.data

        epic = get_object_or_404(models.Epic, id=kwargs["epic"])
        project = Project.objects.get(pk=data.get('project_id'))

        self.check_permissions(request, 'bulk_create', project)
        if project.blocked_code is not None:
            raise exc.Blocked(_("Blocked element"))

        related_userstories = services.create_related_userstories_in_bulk(
            data["bulk_userstories"],
            epic,
            project=project,
            owner=request.user
        )

        for related_userstory in related_userstories:
            self.persist_history_snapshot(obj=related_userstory)
            self.persist_history_snapshot(obj=related_userstory.user_story)

        related_uss_serialized = self.get_serializer_class()(epic.relateduserstory_set.all(), many=True)
        return response.Ok(related_uss_serialized.data)
开发者ID:shreeshreee,项目名称:taiga-back,代码行数:27,代码来源:api.py

示例10: stats

    def stats(self, request, pk=None):
        milestone = get_object_or_404(models.Milestone, pk=pk)

        self.check_permissions(request, "stats", milestone)

        total_points = milestone.total_points
        milestone_stats = {
            'name': milestone.name,
            'estimated_start': milestone.estimated_start,
            'estimated_finish': milestone.estimated_finish,
            'total_points': total_points,
            'completed_points': milestone.closed_points.values(),
            'total_userstories': milestone.user_stories.count(),
            'completed_userstories': len([us for us in milestone.user_stories.all() if us.is_closed]),
            'total_tasks': milestone.tasks.all().count(),
            'completed_tasks': milestone.tasks.all().filter(status__is_closed=True).count(),
            'iocaine_doses': milestone.tasks.filter(is_iocaine=True).count(),
            'days': []
        }
        current_date = milestone.estimated_start
        sumTotalPoints = sum(total_points.values())
        optimal_points = sumTotalPoints
        milestone_days = (milestone.estimated_finish - milestone.estimated_start).days
        optimal_points_per_day = sumTotalPoints / milestone_days if milestone_days else 0
        while current_date <= milestone.estimated_finish:
            milestone_stats['days'].append({
                'day': current_date,
                'name': current_date.day,
                'open_points':  sumTotalPoints - sum(milestone.closed_points_by_date(current_date).values()),
                'optimal_points': optimal_points,
            })
            current_date = current_date + datetime.timedelta(days=1)
            optimal_points -= optimal_points_per_day

        return response.Ok(milestone_stats)
开发者ID:ndjido,项目名称:taiga-back,代码行数:35,代码来源:api.py

示例11: duplicate

    def duplicate(self, request, pk=None):
        project = self.get_object()
        self.check_permissions(request, "duplicate", project)
        if project.blocked_code is not None:
            raise exc.Blocked(_("Blocked element"))

        validator = validators.DuplicateProjectValidator(data=request.DATA)
        if not validator.is_valid():
            return response.BadRequest(validator.errors)

        data = validator.data

        # Validate if the project can be imported
        is_private = data.get('is_private', False)
        total_memberships = len(data.get("users", [])) + 1
        (enough_slots, error_message) = users_services.has_available_slot_for_new_project(
            self.request.user,
            is_private,
            total_memberships
        )
        if not enough_slots:
            raise exc.NotEnoughSlotsForProject(is_private, total_memberships, error_message)

        new_project = services.duplicate_project(
            project=project,
            owner=request.user,
            name=data["name"],
            description=data["description"],
            is_private=data["is_private"],
            users=data["users"]
        )
        new_project = get_object_or_404(self.get_queryset(), id=new_project.id)
        serializer = self.get_serializer(new_project)
        return response.Created(serializer.data)
开发者ID:taigaio,项目名称:taiga-back,代码行数:34,代码来源:api.py

示例12: upvote

    def upvote(self, request, pk=None):
        issue = get_object_or_404(models.Issue, pk=pk)

        self.check_permissions(request, 'upvote', issue)

        votes_service.add_vote(issue, user=request.user)
        return Response(status=status.HTTP_200_OK)
开发者ID:FlorianBezagu,项目名称:taiga-back,代码行数:7,代码来源:api.py

示例13: list

    def list(self, request, *args, **kwargs):
        resource_id = kwargs.get("resource_id", None)
        resource = get_object_or_404(self.resource_model, pk=resource_id)

        self.check_permissions(request, 'list', resource)

        return super().list(request, *args, **kwargs)
开发者ID:heyox,项目名称:taiga-back,代码行数:7,代码来源:mixins.py

示例14: filters_data

    def filters_data(self, request, *args, **kwargs):
        project_id = request.QUERY_PARAMS.get("project", None)
        project = get_object_or_404(Project, id=project_id)

        filter_backends = self.get_filter_backends()
        types_filter_backends = (f for f in filter_backends if f != filters.IssueTypesFilter)
        statuses_filter_backends = (f for f in filter_backends if f != filters.StatusesFilter)
        assigned_to_filter_backends = (f for f in filter_backends if f != filters.AssignedToFilter)
        owners_filter_backends = (f for f in filter_backends if f != filters.OwnersFilter)
        priorities_filter_backends = (f for f in filter_backends if f != filters.PrioritiesFilter)
        severities_filter_backends = (f for f in filter_backends if f != filters.SeveritiesFilter)
        roles_filter_backends = (f for f in filter_backends if f != filters.RoleFilter)

        queryset = self.get_queryset()
        querysets = {
            "types": self.filter_queryset(queryset, filter_backends=types_filter_backends),
            "statuses": self.filter_queryset(queryset, filter_backends=statuses_filter_backends),
            "assigned_to": self.filter_queryset(queryset, filter_backends=assigned_to_filter_backends),
            "owners": self.filter_queryset(queryset, filter_backends=owners_filter_backends),
            "priorities": self.filter_queryset(queryset, filter_backends=priorities_filter_backends),
            "severities": self.filter_queryset(queryset, filter_backends=severities_filter_backends),
            "tags": self.filter_queryset(queryset),
            "roles": self.filter_queryset(queryset, filter_backends=roles_filter_backends),
        }
        return response.Ok(services.get_issues_filters_data(project, querysets))
开发者ID:shreeshreee,项目名称:taiga-back,代码行数:25,代码来源:api.py

示例15: pre_delete

    def pre_delete(self, obj):
        move_to = self.request.QUERY_PARAMS.get('moveTo', None)
        if move_to:
            role_dest = get_object_or_404(self.model, project=obj.project, id=move_to)
            qs = models.Membership.objects.filter(project_id=obj.project.pk, role=obj)
            qs.update(role=role_dest)

        super().pre_delete(obj)
开发者ID:FlorianBezagu,项目名称:taiga-back,代码行数:8,代码来源:api.py


注:本文中的taiga.base.api.utils.get_object_or_404函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。