• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python base.http_error函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: obj_create

    def obj_create(self, bundle, request=None, **kwargs):
        """
        Handle POST requests to the resource. If the data validates, create a
        new Review from bundle data.
        """
        form = ReviewForm(bundle.data)

        if not form.is_valid():
            raise self.form_errors(form)

        app = self.get_app(bundle.data["app"])

        # Return 409 if the user has already reviewed this app.
        qs = self._meta.queryset.filter(addon=app, user=request.user)
        if app.is_packaged:
            qs = qs.filter(version_id=bundle.data.get("version", app.current_version.id))
        if qs.exists():
            raise http_error(http.HttpConflict, "You have already reviewed this app.")

        # Return 403 if the user is attempting to review their own app:
        if app.has_author(request.user):
            raise http_error(http.HttpForbidden, "You may not review your own app.")

        # Return 403 if not a free app and the user hasn't purchased it.
        if app.is_premium() and not app.is_purchased(request.amo_user):
            raise http_error(http.HttpForbidden, "You may not review paid apps you haven't purchased.")

        bundle.obj = Review.objects.create(**self._review_data(request, app, form))

        amo.log(amo.LOG.ADD_REVIEW, app, bundle.obj)
        log.debug("[Review:%s] Created by user %s " % (bundle.obj.id, request.user.id))
        record_action("new-review", request, {"app-id": app.id})

        return bundle
开发者ID:pombredanne,项目名称:zamboni,代码行数:34,代码来源:resources.py


示例2: get_and_check_ownership

    def get_and_check_ownership(self, request, allow_anon=False, **kwargs):
        try:
            # Use queryset, not get_object_list to ensure a distinction
            # between a 404 and a 403.
            obj = self._meta.queryset.get(**kwargs)
        except self._meta.object_class.DoesNotExist:
            unavail = self._meta.queryset_base.filter(**kwargs)
            if unavail.exists():
                obj = unavail[0]
                # Owners can see their app no matter what region.
                if AppOwnerAuthorization().is_authorized(request, object=obj):
                    return obj
                data = {}
                for key in ('name', 'support_email', 'support_url'):
                    value = getattr(obj, key)
                    data[key] = unicode(value) if value else ''
                raise http_error(HttpLegallyUnavailable,
                                 'Not available in your region.',
                                 extra_data=data)
            raise http_error(http.HttpNotFound,
                             'No such app.')

        # If it's public, just return it.
        if allow_anon and obj.is_public():
            return obj

        # Now do the final check to see if you are allowed to see it and
        # return a 403 if you can't.
        if not AppOwnerAuthorization().is_authorized(request, object=obj):
            raise http_error(http.HttpForbidden,
                             'You do not own that app.')
        return obj
开发者ID:chusiang,项目名称:zamboni,代码行数:32,代码来源:resources.py


示例3: handle

    def handle(self, bundle, request, **kwargs):
        form = ReceiptForm(bundle.data)

        if not form.is_valid():
            raise self.form_errors(form)

        bundle.obj = form.cleaned_data["app"]
        type_ = install_type(request, bundle.obj)

        if type_ == apps.INSTALL_TYPE_DEVELOPER:
            return self.record(bundle, request, apps.INSTALL_TYPE_DEVELOPER)

        # The app must be public and if its a premium app, you
        # must have purchased it.
        if not bundle.obj.is_public():
            log.info("App not public: %s" % bundle.obj.pk)
            raise http_error(http.HttpForbidden, "App not public.")

        if bundle.obj.is_premium() and not bundle.obj.has_purchased(request.amo_user):
            # Apps that are premium but have no charge will get an
            # automatic purchase record created. This will ensure that
            # the receipt will work into the future if the price changes.
            if bundle.obj.premium and not bundle.obj.premium.price.price:
                log.info("Create purchase record: {0}".format(bundle.obj.pk))
                AddonPurchase.objects.get_or_create(addon=bundle.obj, user=request.amo_user, type=CONTRIB_NO_CHARGE)
            else:
                log.info("App not purchased: %s" % bundle.obj.pk)
                raise http_error(HttpPaymentRequired, "You have not purchased this app.")

        return self.record(bundle, request, type_)
开发者ID:pombredanne,项目名称:zamboni,代码行数:30,代码来源:api.py


示例4: obj_create

    def obj_create(self, bundle, request, **kwargs):
        form = UploadForm(bundle.data)

        if not request.amo_user.read_dev_agreement:
            log.info(u'Attempt to use API without dev agreement: %s'
                     % request.amo_user.pk)
            raise http_error(http.HttpUnauthorized,
                             'Terms of service not accepted.')

        if not form.is_valid():
            raise self.form_errors(form)

        if not (OwnerAuthorization()
                .is_authorized(request, object=form.obj)):
            raise http_error(http.HttpForbidden,
                             'You do not own that app.')

        plats = [Platform.objects.get(id=amo.PLATFORM_ALL.id)]

        # Create app, user and fetch the icon.
        bundle.obj = Addon.from_upload(form.obj, plats,
                                       is_packaged=form.is_packaged)
        AddonUser(addon=bundle.obj, user=request.amo_user).save()

        self._icons_and_images(bundle.obj)
        record_action('app-submitted', request, {'app-id': bundle.obj.pk})

        log.info('App created: %s' % bundle.obj.pk)
        return bundle
开发者ID:chusiang,项目名称:zamboni,代码行数:29,代码来源:resources.py


示例5: get_object_list

 def get_object_list(self, request):
     if not request.amo_user:
         log.info('Anonymous listing not allowed')
         raise http_error(http.HttpForbidden,
                          'Anonymous listing not allowed.')
     return self._meta.queryset.filter(type=amo.ADDON_WEBAPP,
                                       authors=request.amo_user)
开发者ID:chusiang,项目名称:zamboni,代码行数:7,代码来源:resources.py


示例6: dispatch

    def dispatch(self, request_type, request, **kwargs):
        if not waffle.switch_is_active('stats-api'):
            raise http_error(http.HttpNotImplemented,
                             'Stats not enabled for this host.')

        return super(GlobalStatsResource, self).dispatch(request_type, request,
                                                         **kwargs)
开发者ID:markh-bz,项目名称:zamboni,代码行数:7,代码来源:api.py


示例7: obj_create

    def obj_create(self, bundle, request, **kwargs):
        # Ensure that people don't pass strings through.
        args = PreviewArgsForm(request.GET)
        if not args.is_valid():
            raise self.form_errors(args)

        addon = self.get_object_or_404(Addon,
                                       pk=args.cleaned_data['app'],
                                       type=amo.ADDON_WEBAPP)
        if not AppOwnerAuthorization().is_authorized(request, object=addon):
            raise http_error(http.HttpForbidden,
                             'You are not an author of that app.')

        data_form = PreviewJSONForm(bundle.data)
        if not data_form.is_valid():
            raise self.form_errors(data_form)

        form = PreviewForm(data_form.cleaned_data)
        if not form.is_valid():
            raise self.form_errors(form)

        form.save(addon)
        bundle.obj = form.instance
        log.info('Preview created: %s' % bundle.obj.pk)
        return bundle
开发者ID:chenliu0831,项目名称:zamboni,代码行数:25,代码来源:api.py


示例8: obj_update

    def obj_update(self, bundle, request, **kwargs):
        """
        Handle PUT requests to the resource. If authorized and the data
        validates, update the indicated resource with bundle data.
        """
        obj = self.get_by_resource_or_404(request, **kwargs)
        if not OwnerAuthorization().is_authorized(request, object=obj):
            raise http_error(
                http.HttpForbidden,
                'You do not have permission to update this review.')

        form = ReviewForm(bundle.data)
        if not form.is_valid():
            raise self.form_errors(form)

        if 'app' in bundle.data:
            error = ('app', "Cannot update a rating's `app`")
            raise self.non_form_errors([error])

        sup = super(RatingResource, self).obj_update(bundle, request, **kwargs)

        amo.log(amo.LOG.EDIT_REVIEW, bundle.obj.addon, bundle.obj)
        log.debug('[Review:%s] Edited by %s' % (bundle.obj.id, request.user.id))

        return sup
开发者ID:dejan991,项目名称:zamboni,代码行数:25,代码来源:resources.py


示例9: build_filters

    def build_filters(self, filters=None):
        """
        If `addon__exact` is a filter and its value cannot be coerced into an
        int, assume that it's a slug lookup.

        Run the query necessary to determine the app, and substitute the slug
        with the PK in the filter so tastypie will continue doing its thing.
        """
        built = super(RatingResource, self).build_filters(filters)
        if 'addon__exact' in built:
            try:
                int(built['addon__exact'])
            except ValueError:
                app = self.get_app(built['addon__exact'])
                if app:
                    built['addon__exact'] = str(app.pk)

        if built.get('user__exact', None) == 'mine':
            # This is a cheat. Would prefer /mine/ in the URL.
            user = get_user()
            if not user:
                # You must be logged in to use "mine".
                raise http_error(http.HttpUnauthorized, 'You must be logged in to access "mine".')

            built['user__exact'] = user.pk
        return built
开发者ID:dejan991,项目名称:zamboni,代码行数:26,代码来源:resources.py


示例10: obj_create

    def obj_create(self, bundle, request, **kwargs):
        with statsd.timer("auth.browserid.verify"):
            profile, msg = browserid_authenticate(
                request,
                bundle.data["assertion"],
                browserid_audience=bundle.data["audience"],
                is_native=bundle.data.get("is_native", False),
            )
        if profile is None:
            log.info("No profile")
            raise http_error(http.HttpUnauthorized, "No profile.")

        request.user, request.amo_user = profile.user, profile
        request.groups = profile.groups.all()

        # TODO: move this to the signal.
        profile.log_login_attempt(True)
        user_logged_in.send(sender=profile.user.__class__, request=request, user=profile.user)
        bundle.data = {
            "error": None,
            "token": self.get_token(request.user.email),
            "settings": {"display_name": request.amo_user.display_name, "email": request.user.email},
        }
        bundle.data.update(PermissionResource().dehydrate(Bundle(request=request)).data)
        return bundle
开发者ID:l-hedgehog,项目名称:zamboni,代码行数:25,代码来源:api.py


示例11: obj_create

    def obj_create(self, bundle, request, **kwargs):
        with statsd.timer('auth.browserid.verify'):
            profile, msg = browserid_authenticate(
                request, bundle.data['assertion'],
                browserid_audience=bundle.data['audience'],
                is_native=bundle.data.get('is_native', False)
            )
        if profile is None:
            log.info('No profile: %s' % (msg or ''))
            raise http_error(http.HttpUnauthorized,
                             'No profile.')

        request.user, request.amo_user = profile.user, profile
        request.groups = profile.groups.all()

        # TODO: move this to the signal.
        profile.log_login_attempt(True)
        user_logged_in.send(sender=profile.user.__class__, request=request,
                            user=profile.user)
        bundle.data = {
            'error': None,
            'token': self.get_token(request.amo_user.email),
            'settings': {
                'display_name': request.amo_user.display_name,
                'email': request.amo_user.email,
            }
        }
        bundle.data.update(PermissionResource()
                           .dehydrate(Bundle(request=request)).data)
        return bundle
开发者ID:kmaglione,项目名称:zamboni,代码行数:30,代码来源:api.py


示例12: obj_get

    def obj_get(self, request=None, **kwargs):
        obj = super(StatusResource, self).obj_get(request=request, **kwargs)
        if not AppOwnerAuthorization().is_authorized(request, object=obj):
            raise http_error(http.HttpForbidden,
                             'You are not an author of that app.')

        log.info('App status retreived: %s' % obj.pk)
        return obj
开发者ID:chusiang,项目名称:zamboni,代码行数:8,代码来源:api.py


示例13: obj_delete

    def obj_delete(self, request, **kwargs):
        obj = self.get_by_resource_or_404(request, **kwargs)
        if not AppOwnerAuthorization().is_authorized(request,
                                                     object=obj.addon):
            raise http_error(http.HttpForbidden,
                             'You are not an author of that app.')

        log.info('Preview deleted: %s' % obj.pk)
        return super(PreviewResource, self).obj_delete(request, **kwargs)
开发者ID:chenliu0831,项目名称:zamboni,代码行数:9,代码来源:api.py


示例14: obj_get

    def obj_get(self, request=None, **kwargs):
        if kwargs.get("pk") == "mine":
            kwargs["pk"] = request.amo_user.pk

        # TODO: put in acl checks for admins to get other users information.
        obj = super(Mine, self).obj_get(request=request, **kwargs)
        if not OwnerAuthorization().is_authorized(request, object=obj):
            raise http_error(http.HttpForbidden, "You do not have access to that account.")
        return obj
开发者ID:l-hedgehog,项目名称:zamboni,代码行数:9,代码来源:api.py


示例15: obj_update

    def obj_update(self, bundle, request, **kwargs):
        try:
            obj = self.get_object_list(bundle.request).get(**kwargs)
        except Addon.DoesNotExist:
            raise http_error(http.HttpNotFound, 'No such addon.')

        if not AppOwnerAuthorization().is_authorized(request, object=obj):
            raise http_error(http.HttpForbidden,
                             'You are not an author of that app.')

        form = StatusForm(bundle.data, instance=obj)
        if not form.is_valid():
            raise self.form_errors(form)

        form.save()
        log.info('App status updated: %s' % obj.pk)
        bundle.obj = obj
        return bundle
开发者ID:chusiang,项目名称:zamboni,代码行数:18,代码来源:api.py


示例16: obj_get

    def obj_get(self, request, **kw):
        if kw['pk'] != 'site':
            raise http_error(http.HttpNotFound,
                             'No such configuration.')

        return GenericObject({
            # This is the git commit on IT servers.
            'version': getattr(settings, 'BUILD_ID_JS', ''),
            'flags': waffles(request),
            'settings': get_settings(),
        })
开发者ID:chusiang,项目名称:zamboni,代码行数:11,代码来源:resources.py


示例17: obj_delete

    def obj_delete(self, request, **kwargs):
        obj = self.get_by_resource_or_404(request, **kwargs)
        if not (
            AppOwnerAuthorization().is_authorized(request, object=obj.addon)
            or OwnerAuthorization().is_authorized(request, object=obj)
            or PermissionAuthorization("Users", "Edit").is_authorized(request)
            or PermissionAuthorization("Addons", "Edit").is_authorized(request)
        ):
            raise http_error(http.HttpForbidden, "You do not have permission to delete this review.")

        log.info("Rating %s deleted from addon %s" % (obj.pk, obj.addon.pk))
        return super(RatingResource, self).obj_delete(request, **kwargs)
开发者ID:pombredanne,项目名称:zamboni,代码行数:12,代码来源:resources.py


示例18: post_list

 def post_list(self, request, **kwargs):
     data = self.deserialize(request, request.raw_post_data,
                             format='application/json')
     email = data['email']
     try:
         validate_email(email)
     except ValidationError:
         raise http_error(http.HttpBadRequest, 'Invalid email address')
     basket.subscribe(data['email'], 'marketplace',
                      format='H', country=request.REGION.slug,
                      lang=request.LANG, optin='Y',
                      trigger_welcome='Y')
开发者ID:kmaglione,项目名称:zamboni,代码行数:12,代码来源:api.py


示例19: obj_get

    def obj_get(self, request, **kw):
        if kw["pk"] != "site":
            raise http_error(http.HttpNotFound, "No such configuration.")

        return GenericObject(
            {
                # This is the git commit on IT servers.
                "version": getattr(settings, "BUILD_ID_JS", ""),
                "flags": waffles(request),
                "settings": get_settings(),
            }
        )
开发者ID:pythonchelle,项目名称:zamboni,代码行数:12,代码来源:resources.py


示例20: obj_create

    def obj_create(self, bundle, request, **kwargs):
        region = getattr(request, 'REGION', None)

        if region and region.id not in settings.PURCHASE_ENABLED_REGIONS:
            log.info('Region {0} is not in {1}'
                     .format(region.id, settings.PURCHASE_ENABLED_REGIONS))
            if not waffle.flag_is_active(request, 'allow-paid-app-search'):
                log.info('Flag not active')
                raise http_error(http.HttpForbidden,
                                 'Not allowed to purchase for this flag')

        bundle.obj = GenericObject(_prepare_pay(request, bundle.data['app']))
        return bundle
开发者ID:at13,项目名称:zamboni,代码行数:13,代码来源:resources.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python base.list_url函数代码示例发布时间:2022-05-27
下一篇:
Python base.get_url函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap