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

Python importing.cached_load函数代码示例

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

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



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

示例1: get_object

    def get_object(self):
        uuid = get_key(self.kwargs.get(self.lookup_field, ""))
        shop = self.request.shop
        loaded_basket = Basket.objects.filter(key=uuid).first()

        # ensure correct owner
        if not self.request.user.is_superuser:
            if not loaded_basket.shop == shop:
                raise exceptions.PermissionDenied("No permission")

            customer_id = (loaded_basket.customer.pk if loaded_basket.customer else None)
            controlled_contact_ids = self._get_controlled_contacts_by_user(self.request.user)
            is_staff = self.is_staff_user(shop, self.request.user)
            if customer_id and customer_id not in controlled_contact_ids and not is_staff:
                raise exceptions.PermissionDenied("No permission")

        # actually load basket
        basket_class = cached_load("SHUUP_BASKET_CLASS_SPEC")
        basket = basket_class(self.request._request, basket_name=uuid)

        try:
            basket._data = basket.storage.load(basket)
        except BasketCompatibilityError as error:
            raise exceptions.ValidationError(str(error))

        # Hack: the storage should do this already
        # set the correct basket customer
        if loaded_basket and loaded_basket.customer:
            basket.customer = loaded_basket.customer

        return basket
开发者ID:suutari-ai,项目名称:shuup,代码行数:31,代码来源:basket.py


示例2: get_object

    def get_object(self):
        basket_class = cached_load("SHUUP_BASKET_CLASS_SPEC")
        shop = self.request.shop
        uuid = get_key(self.kwargs.get(self.lookup_field, ""))
        storage = get_storage()
        if not storage.basket_exists(uuid, shop):
            raise exceptions.NotFound()

        basket = basket_class(self.request._request, basket_name=uuid)
        try:
            basket._data = basket.storage.load(basket)
        except BasketCompatibilityError as error:
            raise exceptions.ValidationError(str(error))

        # ensure correct creator
        if not self.request.user.is_superuser:
            if not basket.shop == shop:
                raise exceptions.PermissionDenied("No permission")

            customer_id = (basket.customer.pk if basket.customer else None)
            controlled_contact_ids = self._get_controlled_contacts_by_user(self.request.user)
            is_staff = self.is_staff_user(shop, self.request.user)
            if customer_id and customer_id not in controlled_contact_ids and not is_staff:
                raise exceptions.PermissionDenied("No permission")

        return basket
开发者ID:ruqaiya,项目名称:shuup,代码行数:26,代码来源:basket.py


示例3: new

    def new(self, request, *args, **kwargs):
        """
        Create a brand new basket object
        """
        serializer = NewBasketSerializer(data=request.data)
        serializer.is_valid(True)
        data = serializer.validated_data

        self.process_request(with_basket=False, shop=data.get("shop"))
        basket_class = cached_load("SHUUP_BASKET_CLASS_SPEC")
        basket = basket_class(request._request)

        if "customer" in data:
            customer = data["customer"]
        else:
            customer = get_company_contact(request.user) or get_person_contact(request.user)

        orderer = data.get("orderer", get_person_contact(request.user))

        # set the request basket to perform the basket command
        self.request.basket = basket
        self._handle_set_customer(
            request=self.request._request,
            basket=basket,
            customer=customer,
            orderer=orderer
        )

        stored_basket = basket.save()
        response_data = {
            "uuid": "%s-%s" % (request.shop.pk, stored_basket.key)
        }
        response_data.update(self.get_serializer(basket).data)
        return Response(data=response_data, status=status.HTTP_201_CREATED)
开发者ID:ruqaiya,项目名称:shuup,代码行数:34,代码来源:basket.py


示例4: _configure_basket

def _configure_basket(request):
    """
    Search for some needed keys in the checkout phases storages
    """

    # (src key, destination key) pair
    search_keys = [
        ('payment_method_id', 'payment_method_id'),
        ('shipping_method_id', 'shipping_method_id'),
        ('shipping', 'shipping_address'),
        ('shipping_extra', 'shipping_address_extra'),
        ('payment', 'payment_address'),
        ('payment_extra', 'payment_address_extra'),
    ]

    for phase in cached_load("SHUUP_CHECKOUT_VIEW_SPEC").phase_specs:
        phase_class = load(phase)

        storage = CheckoutPhaseStorage(request, phase_class.identifier)

        for key, dst_key in search_keys:
            value = storage.get(key)

            # key found, set it to request.basket on dst_key
            if value:
                setattr(request.basket, dst_key, value)
开发者ID:rockho-team,项目名称:shuup-cielo,代码行数:26,代码来源:views.py


示例5: handle_update

def handle_update(request, basket, **kwargs):
    """
    Handle updating a basket, i.e. deleting some lines or updating quantities.

    This dispatches further to whatever is declared by the `SHUUP_BASKET_UPDATE_METHODS_SPEC`
    configuration entry.
    """
    methods = cached_load("SHUUP_BASKET_UPDATE_METHODS_SPEC")(request=request, basket=basket)
    prefix_method_dict = methods.get_prefix_to_method_map()
    basket_changed = False
    # If any POST items match a prefix defined in prefix_method_dict, call the appropriate model method.
    for key, value in six.iteritems(kwargs):
        for prefix, method in six.iteritems(prefix_method_dict):
            if key.startswith(prefix):
                line_id = key[len(prefix):]
                line = basket.find_line_by_line_id(line_id)
                field_changed = method(
                    key=key,
                    value=value,
                    line=line
                )
                basket_changed = (basket_changed or field_changed)
                break

    if basket_changed:  # pragma: no branch
        basket.clean_empty_lines()
        basket.dirty = True
        basket.uncache()
开发者ID:ruqaiya,项目名称:shuup,代码行数:28,代码来源:commands.py


示例6: __init__

 def __init__(self, *args, **kwargs):
     super(CompanyRegistrationForm, self).__init__(*args, **kwargs)
     address_form_cls = cached_load('SHUUP_ADDRESS_MODEL_FORM')
     self.add_form_def('company', CompanyForm)
     self.add_form_def('billing', address_form_cls)
     self.add_form_def('contact_person', ContactPersonForm)
     self.add_form_def('user_account', UserCreationForm)
开发者ID:suutari-ai,项目名称:shuup,代码行数:7,代码来源:forms.py


示例7: get_basket

def get_basket(request, basket_name="basket", basket_class=None):
    """
    Get the basket cached in the request or create and cache a new one.

    The basket_class is used when creating a new basket, i.e. when the
    request doesn't already have a basket cached with the given name.
    If no basket_class is given, will load a class using the
    `~shuup.front.settings.SHUUP_BASKET_CLASS_SPEC` setting.

    :type request: django.http.request.HttpRequest
    :type basket_name: str
    :type basket_class: type|None
    :rtype: shuup.front.basket.objects.BaseBasket
    """
    basket = _get_basket_from_request(request, basket_name)
    if basket:
        return basket

    if basket_class is None:
        basket_class = cached_load("SHUUP_BASKET_CLASS_SPEC")

    basket = basket_class(request, basket_name=basket_name)

    _save_basket_to_request(request, basket_name, basket)

    return basket
开发者ID:ruqaiya,项目名称:shuup,代码行数:26,代码来源:__init__.py


示例8: new

    def new(self, request, *args, **kwargs):
        """
        Create a brand new basket object
        """
        self.process_request(with_basket=False)
        basket_class = cached_load("SHUUP_BASKET_CLASS_SPEC")
        basket = basket_class(request._request)

        customer_id = request.POST.get("customer_id")
        if not customer_id:
            customer_id = request.data.get("customer_id")

        if customer_id:
            is_staff = self.is_staff_user(self.request.shop, self.request.user)
            is_superuser = self.request.user.is_superuser

            if int(customer_id) in self._get_controlled_contacts_by_user(self.request.user) or is_superuser or is_staff:
                basket.customer = Contact.objects.get(pk=int(customer_id))
            else:
                raise exceptions.PermissionDenied("No permission")

        stored_basket = basket.save()
        response_data = {
            "uuid": "%s-%s" % (request.shop.pk, stored_basket.key)
        }
        response_data.update(BasketSerializer(basket, context=self.get_serializer_context()).data)
        return Response(data=response_data, status=status.HTTP_201_CREATED)
开发者ID:suutari-ai,项目名称:shuup,代码行数:27,代码来源:basket.py


示例9: get_form

 def get_form(self, form_class):
     contact = get_person_contact(self.request.user)
     form_group = FormGroup(**self.get_form_kwargs())
     address_form_class = cached_load("SHUUP_ADDRESS_MODEL_FORM")
     form_group.add_form_def("billing", address_form_class, kwargs={"instance": contact.default_billing_address})
     form_group.add_form_def("shipping", address_form_class, kwargs={"instance": contact.default_shipping_address})
     form_group.add_form_def("contact", PersonContactForm, kwargs={"instance": contact})
     return form_group
开发者ID:gurch101,项目名称:shuup,代码行数:8,代码来源:views.py


示例10: get_price_info

    def get_price_info(self, context, product, quantity=1):
        product_id = (product if isinstance(product, six.integer_types) else product.pk)
        shop = context.shop

        # By default let's use supplier passed to context.
        supplier = context.supplier
        if not supplier:
            # Since supplier is optional I am pretty sure
            # there is cases that supplier is not passed to
            # pricing context. This is not a problem. The
            # pricing module which decides to use supplier
            # for product prices mjust need to have some sane
            # fallback.
            supplier_strategy = cached_load("SHUUP_SHOP_PRODUCT_SUPPLIERS_STRATEGY")
            kwargs = {
                "product_id": product_id,
                "shop": context.shop,
                "customer": context.customer,
                "quantity": quantity,
                "basket": context.basket
            }

            # Since this is custom pricing module it
            # requires also custom supplier strategy.
            # Some example is provided in
            # `shuup.testing.supplier_pricing.supplier_strategy:CheapestSupplierPriceSupplierStrategy`
            supplier = supplier_strategy().get_supplier(**kwargs)

        # Like now in customer group pricing let's take default price from shop product
        default_price_values = list(ShopProduct.objects.filter(
            product_id=product_id, shop=shop).values_list("default_price_value", flat=True))
        if len(default_price_values) == 0:  # No shop product
            return PriceInfo(price=shop.create_price(0), base_price=shop.create_price(0), quantity=quantity)
        else:
            default_price = default_price_values[0] or 0

        # Then the actual supplier price in case we have
        # been able to figure out some supplier. I guess
        # it is problem for supplier strategy if it allows
        # supplier to be None in some weird scenarios.
        # Not sure though what would happen in shop product
        # orderability checks and so on.
        price = None
        if supplier:
            result = SupplierPrice.objects.filter(
                shop=shop, product_id=product_id, supplier=supplier
            ).order_by("amount_value")[:1].values_list("amount_value", flat=True)
            if result:
                price = result[0]

            if not price:
                price = default_price

        return PriceInfo(
            price=shop.create_price(price * quantity),
            base_price=shop.create_price(price * quantity),
            quantity=quantity,
        )
开发者ID:ruqaiya,项目名称:shuup,代码行数:58,代码来源:pricing.py


示例11: get_storage

def get_storage():
    """
    Retrieve a basket storage object.

    :return: A basket storage object
    :rtype: BasketStorage
    """
    storage_class = cached_load("SHUUP_BASKET_STORAGE_CLASS_SPEC")
    return storage_class()
开发者ID:gurch101,项目名称:shuup,代码行数:9,代码来源:storage.py


示例12: get_supplier

 def get_supplier(self, customer=None, quantity=None, shipping_address=None):
     supplier_strategy = cached_load("SHUUP_SHOP_PRODUCT_SUPPLIERS_STRATEGY")
     kwargs = {
         "shop_product": self,
         "customer": customer,
         "quantity": quantity,
         "shipping_address": shipping_address
     }
     return supplier_strategy().get_supplier(**kwargs)
开发者ID:ruqaiya,项目名称:shuup,代码行数:9,代码来源:_product_shops.py


示例13: get_context_data

    def get_context_data(self, context):
        context_data = super(ShippingSimulatorPlugin, self).get_context_data(context)
        resolved = resolve(context["request"].path)

        # Only works on ProductDetailView
        if resolved.view_name in ("shuup:product", "shuup:basket"):
            context_data["title"] = self.get_translated_value("title")
            context_data["form"] = cached_load("SHIPPING_SIMULATOR_CLASS_SPEC")().get_form()
            context_data["from_session"] = (resolved.view_name == "shuup:basket")

        return context_data
开发者ID:rockho-team,项目名称:shuup-shipping-simulator,代码行数:11,代码来源:plugins.py


示例14: get_form

 def get_form(self, form_class):
     fg = FormGroup(**self.get_form_kwargs())
     default_address_form_class = cached_load("SHUUP_ADDRESS_MODEL_FORM")
     for kind in self.address_kinds:
         fg.add_form_def(kind, form_class=self.address_form_classes.get(kind, default_address_form_class))
         fg.add_form_def("saved_{}".format(kind),
                         form_class=SavedAddressForm,
                         required=False,
                         kwargs={"kind": kind, "owner": self.basket.customer})
     if self.company_form_class and not self.request.customer:
         fg.add_form_def("company", self.company_form_class, required=False)
     return fg
开发者ID:suutari-ai,项目名称:shuup,代码行数:12,代码来源:addresses.py


示例15: __init__

    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop("request")
        super(CustomerInformationFormGroup, self).__init__(*args, **kwargs)
        contact = get_person_contact(self.request.user)
        address_form_class = cached_load("SHUUP_ADDRESS_MODEL_FORM")

        for form_name in self.address_forms:
            self.add_form_def(form_name, address_form_class, kwargs={
                "instance": getattr(contact, "default_%s_address" % form_name)
            })

        self.add_form_def("contact", PersonContactForm, kwargs={"instance": contact})
开发者ID:ruqaiya,项目名称:shuup,代码行数:12,代码来源:forms.py


示例16: get_basket

def get_basket(request):
    """
    :type request: django.http.request.HttpRequest
    :rtype: shuup.front.basket.objects.BaseBasket
    """
    if not hasattr(request, "basket"):
        basket_class = cached_load("SHUUP_BASKET_CLASS_SPEC")
        # This is a little weird in that this is likely to be called from `BasketMiddleware`,
        # which would do the following assignment anyway. However, in case it's _not_ called
        # from there, for some reason, we want to still be able to cache the basket.
        request.basket = basket_class(request)
    return request.basket
开发者ID:gurch101,项目名称:shuup,代码行数:12,代码来源:__init__.py


示例17: get_form

 def get_form(self, form_class=None):
     order = self.get_object()
     form_group = FormGroup(**self.get_form_kwargs())
     address_form_class = cached_load("SHUUP_ADDRESS_MODEL_FORM")
     form_group.add_form_def(
         "billing_address",
         address_form_class,
         kwargs={"initial": get_data_dict(order.billing_address) if order.billing_address else {}})
     form_group.add_form_def(
         "shipping_address",
         address_form_class,
         kwargs={"initial": get_data_dict(order.shipping_address) if order.shipping_address else {}})
     return form_group
开发者ID:ruqaiya,项目名称:shuup,代码行数:13,代码来源:addresses.py


示例18: _pack_source

    def _pack_source(self, source):
        """
        Empacota itens do pedido
        :rtype: Iterable[shuup_order_packager.package.AbstractPackage|None]
        :return: Lista de pacotes ou None se for impossível empacotar pedido
        """
        packager = cached_load("CORREIOS_PRODUCTS_PACKAGER_CLASS")()
        packager.add_constraint(SimplePackageDimensionConstraint(self.max_width,
                                                                 self.max_length,
                                                                 self.max_height,
                                                                 self.max_edges_sum))

        packager.add_constraint(WeightPackageConstraint(self.max_weight * KG_TO_G))
        return packager.pack_source(source)
开发者ID:rockho-team,项目名称:shuup-correios,代码行数:14,代码来源:models.py


示例19: test_basket_with_custom_shop

def test_basket_with_custom_shop(rf):
    """
    Set a different shop for basket
    """
    with override_settings(**CORE_BASKET_SETTINGS):
        shop1 = factories.get_default_shop()
        shop2 = factories.get_shop(identifier="shop2")
        user = factories.create_random_user()
        request = apply_request_middleware(rf.get("/"), user=user, shop=shop1)
        basket_class = cached_load("SHUUP_BASKET_CLASS_SPEC")
        basket = basket_class(request, "basket", shop=shop2)
        assert basket.shop == shop2

        product_shop2 = factories.create_product("product_shop2", shop2, factories.get_default_supplier(), 10)
        line = basket.add_product(factories.get_default_supplier(), shop2, product_shop2, 1)
        assert line.shop == shop2
开发者ID:ruqaiya,项目名称:shuup,代码行数:16,代码来源:test_basket.py


示例20: get_form_defs

 def get_form_defs(self):
     initial = {}  # TODO: should we do this? model_to_dict(self.object, AddressForm._meta.fields)
     address_form_class = cached_load("SHUUP_ADDRESS_MODEL_FORM")
     yield FormDef(
         name="shipping_address", form_class=address_form_class,
         required=False, kwargs={"instance": self.object.default_shipping_address, "initial": initial}
     )
     yield FormDef(
         name="billing_address", form_class=address_form_class,
         required=False, kwargs={"instance": self.object.default_billing_address, "initial": initial}
     )
     # Using a pseudo formdef to group the two actual formdefs...
     yield TemplatedFormDef(
         name="addresses", form_class=forms.Form,
         required=False, template_name="shuup/admin/contacts/_edit_addresses_form.jinja"
     )
开发者ID:gurch101,项目名称:shuup,代码行数:16,代码来源:form_parts.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python importing.load函数代码示例发布时间:2022-05-27
下一篇:
Python i18n.get_current_babel_locale函数代码示例发布时间: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