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


Python base.http_error函数代码示例

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


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


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