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

Python configuration.get函数代码示例

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

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



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

示例1: __init__

    def __init__(self, *args, **kwargs):
        from shuup.admin.modules.settings import consts
        from shuup.admin.modules.settings.enums import OrderReferenceNumberMethod
        shop = kwargs.pop("shop")
        kwargs["initial"] = {
            consts.ORDER_REFERENCE_NUMBER_LENGTH_FIELD: configuration.get(
                shop, consts.ORDER_REFERENCE_NUMBER_LENGTH_FIELD, settings.SHUUP_REFERENCE_NUMBER_LENGTH),
            consts.ORDER_REFERENCE_NUMBER_PREFIX_FIELD: configuration.get(
                shop, consts.ORDER_REFERENCE_NUMBER_PREFIX_FIELD, settings.SHUUP_REFERENCE_NUMBER_PREFIX),
        }
        super(ShopOrderConfigurationForm, self).__init__(*args, **kwargs)

        reference_method = configuration.get(
            shop, consts.ORDER_REFERENCE_NUMBER_METHOD_FIELD, settings.SHUUP_REFERENCE_NUMBER_METHOD)

        self.prefix_disabled = (reference_method in
                                [OrderReferenceNumberMethod.UNIQUE.value,
                                 OrderReferenceNumberMethod.SHOP_RUNNING.value])

        self.fields[consts.ORDER_REFERENCE_NUMBER_PREFIX_FIELD].disabled = self.prefix_disabled

        decimal_places = 2  # default
        if shop.currency in babel.core.get_global('currency_fractions'):
            decimal_places = babel.core.get_global('currency_fractions')[shop.currency][0]

        self.fields[ORDER_MIN_TOTAL_CONFIG_KEY] = FormattedDecimalFormField(
            label=_("Order minimum total"),
            decimal_places=decimal_places,
            max_digits=FORMATTED_DECIMAL_FIELD_MAX_DIGITS,
            min_value=0,
            required=False,
            initial=configuration.get(shop, ORDER_MIN_TOTAL_CONFIG_KEY, Decimal(0)),
            help_text=_("The minimum sum that an order needs to reach to be created.")
        )
开发者ID:ruqaiya,项目名称:shuup,代码行数:34,代码来源:shop.py


示例2: test_simple_set_and_get_without_shop

def test_simple_set_and_get_without_shop():
    configuration.set(None, "answer", 42)
    assert configuration.get(None, "answer") == 42

    assert configuration.get(None, "non-existing") is None
    configuration.set(None, "non-existing", "hello")
    assert configuration.get(None, "non-existing") == "hello"
开发者ID:suutari,项目名称:shoop,代码行数:7,代码来源:test_configurations.py


示例3: test_simple_set_and_get_cascading

def test_simple_set_and_get_cascading():
    with override_settings(CACHES={
        'default': {
            'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
            'LOCATION': 'test_simple_set_and_get_cascading',
        }
    }):
        cache.init_cache()
        shop = get_default_shop()
        configuration.set(None, "answer", 42)
        assert configuration.get(None, "answer") == 42
        assert configuration.get(shop, "answer", 42)

        assert configuration.get(None, "non-existing") is None
        assert configuration.get(shop, "non-existing") is None
        configuration.set(shop, "non-existing", "hello")
        assert configuration.get(None, "non-existing") is None
        assert configuration.get(shop, "non-existing") == "hello"

        assert configuration.get(None, "foo") is None
        assert configuration.get(shop, "foo") is None
        configuration.set(None, "foo", "bar")
        configuration.set(shop, "foo", "baz")
        assert configuration.get(None, "foo") == "bar"
        assert configuration.get(shop, "foo") == "baz"
开发者ID:ruqaiya,项目名称:shuup,代码行数:25,代码来源:test_configurations.py


示例4: test_view_default_columns

def test_view_default_columns(rf, admin_user):
    shop = get_default_shop()

    view = ProductListView.as_view()

    request = apply_request_middleware(rf.get("/", {
        "jq": json.dumps({"perPage": 100, "page": 1})
    }), user=admin_user)
    response = view(request)
    assert 200 <= response.status_code < 300

    listview = ProductListView()
    assert listview.settings.default_columns == listview.default_columns

    column_names = [c.id for c in sorted(listview.columns, key=lambda x: x.id)]
    default_column_names = [c.id for c in sorted(listview.default_columns, key=lambda x: x.id)]
    assert column_names == default_column_names
    assert configuration.get(None, "view_configuration_shopproduct_name")  # name is configured
    assert listview.settings.view_configured()
    assert listview.settings.get_settings_key("name") == "view_configuration_shopproduct_name"  # we are attached to product view

    settings_view = ListSettingsView.as_view()
    view_data = {"model": "ShopProduct", "module": "shuup.core.models", "return_url": "shop_product"}
    request = rf.get("/", view_data)
    response = settings_view(request)
    assert 200 <= response.status_code < 300

    # Change configuration by posting form
    request = rf.post("/?" + urlencode(view_data), {"view_configuration_shopproduct_name": False})
    response = settings_view(request)
    assert response.status_code == 302

    assert listview.settings.get_config("name") == configuration.get(None, "view_configuration_shopproduct_name")
    assert not configuration.get(None, "view_configuration_shopproduct_name").get("active")
开发者ID:ruqaiya,项目名称:shuup,代码行数:34,代码来源:test_view_settings.py


示例5: assert_config_value

def assert_config_value(rf, admin_user, form_id, key, value, expected_value, shop=None):
    if not shop:
        shop = get_default_shop()

    request = apply_request_middleware(rf.get("/"), user=admin_user)
    view_func = SystemSettingsView.as_view()
    response = view_func(request)
    assert response.status_code == 200

    form_field = "%s-%s" % (form_id, key)
    data = {form_field: value}
    request = apply_request_middleware(rf.post("/", data=data), user=admin_user)
    response = view_func(request)
    assert response.status_code == 302
    if expected_value == "unset":
        expected_value = value
    assert configuration.get(None, key) == expected_value

    assert len(messages.get_messages(request)) == 1

    # Double save the form and the configuration should still be unchanged
    response = view_func(request)
    assert response.status_code == 302
    assert configuration.get(None, key) == expected_value

    assert len(messages.get_messages(request)) == 2

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


示例6: test_global_configurations

def test_global_configurations():
    with override_settings(CACHES={
        'default': {
            'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
            'LOCATION': 'test_global_configurations',
        }
    }):
        cache.init_cache()
        shop = get_default_shop()
        configuration.set(None, "key1", {"data": "test1"})
        configuration.set(shop, "key2", {"data": "test2"})

        # key1 from shop should come from global configuration
        assert configuration.get(shop, "key1").get("data") == "test1"
        # key2 shouldn't be in global configurations
        assert configuration.get(None, "key2") is None

        # Update global configuration
        configuration.set(None, "key1", {"data": "test_bump"})
        assert configuration.get(shop, "key1").get("data") == "test_bump"

        # Override shop data for global key1
        configuration.set(shop, "key1", "test_data")
        assert configuration.get(shop, "key1") == "test_data"

        # Update shop configuration for global key1
        configuration.set(shop, "key1", "test_data1")
        assert configuration.get(shop, "key1") == "test_data1"
开发者ID:ruqaiya,项目名称:shuup,代码行数:28,代码来源:test_configurations.py


示例7: test_simple_set_and_get_with_shop

def test_simple_set_and_get_with_shop():
    shop = get_default_shop()
    configuration.set(shop, "answer", 42)
    assert configuration.get(shop, "answer") == 42

    assert configuration.get(shop, "non-existing") is None
    configuration.set(shop, "non-existing", "hello")
    assert configuration.get(shop, "non-existing") == "hello"
开发者ID:suutari,项目名称:shoop,代码行数:8,代码来源:test_configurations.py


示例8: test_configuration_gets_saved

def test_configuration_gets_saved():
    configuration.set(None, "x", 1)
    assert configuration.get(None, "x") == 1
    configuration.set(None, "x", 2)
    assert configuration.get(None, "x") == 2
    configuration.set(None, "x", 3)
    assert configuration.get(None, "x") == 3
    conf_item = ConfigurationItem.objects.get(shop=None, key="x")
    assert conf_item.value == 3
开发者ID:suutari,项目名称:shoop,代码行数:9,代码来源:test_configurations.py


示例9: is_valid

    def is_valid(self):
        shipping_required = configuration.get(self.request.shop, SHIPPING_METHOD_REQUIRED_CONFIG_KEY, True)
        payment_required = configuration.get(self.request.shop, PAYMENT_METHOD_REQUIRED_CONFIG_KEY, True)

        if shipping_required and not self.storage.get("shipping_method_id"):
            return False
        if payment_required and not self.storage.get("payment_method_id"):
            return False

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


示例10: get_configuration

def get_configuration(shop=None, category=None, force_category_override=False):
    default_configuration = configuration.get(
        shop, FACETED_DEFAULT_CONF_KEY, settings.SHUUP_FRONT_DEFAULT_SORT_CONFIGURATION)

    category_config = configuration.get(None, _get_category_configuration_key(category))
    # when override_default_configuration is True, we override the default configuration
    if category_config and (category_config.get("override_default_configuration") or force_category_override):
        return category_config

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


示例11: test_configuration_cache

def test_configuration_cache():
    cache.clear()
    shop = get_default_shop()
    configuration.set(None, "key1", "test1")
    configuration.set(shop, "key2", "test2")

    # Shop configurations cache should be bumped
    assert cache.get(configuration._get_cache_key(shop)) is None
    configuration.get(shop, "key1")
    # Now shop configurations and key2 should found from cache
    assert cache.get(configuration._get_cache_key(shop)).get("key2") == "test2"
开发者ID:suutari,项目名称:shoop,代码行数:11,代码来源:test_configurations.py


示例12: test_configuration_update

def test_configuration_update():
    cache.clear()
    shop = get_default_shop()
    configuration.set(shop, "key1", {"data": "test1"})
    configuration.set(shop, "key2", {"data": "test2"})
    configuration.set(shop, "key3", {"data": "test3"})
    assert configuration.get(shop, "key1").get("data") == "test1"
    assert configuration.get(shop, "key3").get("data") == "test3"

    # Update configuration
    configuration.set(shop, "key3", {"data": "test_bump"})
    assert configuration.get(shop, "key3").get("data") == "test_bump"
开发者ID:suutari,项目名称:shoop,代码行数:12,代码来源:test_configurations.py


示例13: get_running_reference_number

def get_running_reference_number(order):
    from shuup import configuration
    from shuup.admin.modules.settings.consts import (ORDER_REFERENCE_NUMBER_PREFIX_FIELD,
                                                     ORDER_REFERENCE_NUMBER_LENGTH_FIELD)
    value = Counter.get_and_increment(CounterType.ORDER_REFERENCE)
    prefix = "%s" % configuration.get(
        order.shop, ORDER_REFERENCE_NUMBER_PREFIX_FIELD, settings.SHUUP_REFERENCE_NUMBER_PREFIX)
    ref_length = configuration.get(
        order.shop, ORDER_REFERENCE_NUMBER_LENGTH_FIELD, settings.SHUUP_REFERENCE_NUMBER_LENGTH)

    padded_value = force_text(value).rjust(ref_length - len(prefix), "0")
    reference_no = "%s%s" % (prefix, padded_value)
    return reference_no + calc_reference_number_checksum(reference_no)
开发者ID:gurch101,项目名称:shuup,代码行数:13,代码来源:_order_utils.py


示例14: get_form_defs

 def get_form_defs(self):
     if not self.object.pk:
         return
     initial = {
         "shipping_method_required": configuration.get(self.object, SHIPPING_METHOD_REQUIRED_CONFIG_KEY, True),
         "payment_method_required": configuration.get(self.object, PAYMENT_METHOD_REQUIRED_CONFIG_KEY, True)
     }
     yield TemplatedFormDef(
         name=self.name,
         form_class=self.form,
         template_name="shuup/front/admin/checkout.jinja",
         required=True,
         kwargs={"initial": initial}
     )
开发者ID:ruqaiya,项目名称:shuup,代码行数:14,代码来源:form_parts.py


示例15: get_unique_reference_number

def get_unique_reference_number(shop, id):
    from shuup import configuration
    from shuup.admin.modules.settings.consts import ORDER_REFERENCE_NUMBER_LENGTH_FIELD
    now = datetime.datetime.now()
    ref_length = configuration.get(shop, ORDER_REFERENCE_NUMBER_LENGTH_FIELD, settings.SHUUP_REFERENCE_NUMBER_LENGTH)
    dt = ("%06s%07d%04d" % (now.strftime("%y%m%d"), now.microsecond, id % 1000)).rjust(ref_length, "0")
    return dt + calc_reference_number_checksum(dt)
开发者ID:gurch101,项目名称:shuup,代码行数:7,代码来源:_order_utils.py


示例16: test_consolidate_objects

def test_consolidate_objects(rf):
    get_default_shop()

    # just visit to make sure GET is ok
    request = apply_request_middleware(rf.get("/"))
    response = APIPermissionView.as_view()(request)
    assert response.status_code == 200

    perm_key = make_permission_config_key(UserViewSet())
    assert configuration.get(None, perm_key) is None

    # now post the form to see what happens
    request = apply_request_middleware(rf.post("/", {perm_key: PermissionLevel.ADMIN}))
    response = APIPermissionView.as_view()(request)
    assert response.status_code == 302      # good
    assert int(configuration.get(None, perm_key)) == PermissionLevel.ADMIN
开发者ID:ruqaiya,项目名称:shuup,代码行数:16,代码来源:test_admin.py


示例17: _handle_xtheme_save

    def _handle_xtheme_save(self):
        svc_pk = config.get(self.shop, CONTENT_FOOTER_KEY)
        svc = SavedViewConfig.objects.filter(pk=svc_pk).first()
        theme = get_current_theme(self.shop)

        if not svc and theme:
            context = {"shop": self.shop}
            rendered_content = template_loader.render_to_string(content_data.FOOTER_TEMPLATE, context).strip()
            layout = Layout(theme, "footer-bottom")
            # adds the footer template
            layout.begin_row()
            layout.begin_column({"md": 12})
            layout.add_plugin(SnippetsPlugin.identifier, {"in_place": rendered_content})

            svc = SavedViewConfig(
                theme_identifier=theme.identifier,
                shop=self.shop,
                view_name=XTHEME_GLOBAL_VIEW_NAME,
                status=SavedViewConfigStatus.CURRENT_DRAFT
            )
            svc.set_layout_data(layout.placeholder_name, layout)
            svc.save()
            svc.publish()

            config.set(self.shop, CONTENT_FOOTER_KEY, svc.pk)
开发者ID:ruqaiya,项目名称:shuup,代码行数:25,代码来源:forms.py


示例18: test_configuration_gets_saved

def test_configuration_gets_saved():
    with override_settings(CACHES={
        'default': {
            'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
            'LOCATION': 'test_configuration_gets_saved',
        }
    }):
        cache.init_cache()
        configuration.set(None, "x", 1)
        assert configuration.get(None, "x") == 1
        configuration.set(None, "x", 2)
        assert configuration.get(None, "x") == 2
        configuration.set(None, "x", 3)
        assert configuration.get(None, "x") == 3
        conf_item = ConfigurationItem.objects.get(shop=None, key="x")
        assert conf_item.value == 3
开发者ID:ruqaiya,项目名称:shuup,代码行数:16,代码来源:test_configurations.py


示例19: save

    def save(self, commit=True):
        company = self.forms['company'].save(commit=False)
        billing_address = self.forms['billing'].save(commit=False)
        person = self.forms['contact_person'].save(commit=False)
        user = self.forms['user_account'].save(commit=False)

        company.default_billing_address = billing_address
        company.default_shipping_address = billing_address

        for field in ['name', 'name_ext', 'email', 'phone']:
            setattr(billing_address, field, getattr(company, field))

        person.user = user

        user.first_name = person.first_name
        user.last_name = person.last_name
        user.email = person.email

        # If company registration requires approval,
        # company and person contacts will be created as inactive
        if configuration.get(None, "company_registration_requires_approval"):
            company.is_active = False
            person.is_active = False

        if commit:
            user.save()
            person.user = user
            person.save()
            billing_address.save()
            company.default_billing_address = billing_address
            company.default_shipping_address = billing_address
            company.save()
            company.members.add(person)

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


示例20: get_validation_errors

    def get_validation_errors(self):
        # check for the minimum sum of order total
        min_total = configuration.get(self.shop, ORDER_MIN_TOTAL_CONFIG_KEY, Decimal(0))
        total = (self.taxful_total_price.value if self.shop.prices_include_tax else self.taxless_total_price.value)
        if total < min_total:
            min_total_price = format_money(self.shop.create_price(min_total))
            yield ValidationError(_("The total should be greater than {} to be ordered.").format(min_total_price),
                                  code="order_total_too_low")

        shipping_method = self.shipping_method
        payment_method = self.payment_method

        if shipping_method:
            for error in shipping_method.get_unavailability_reasons(source=self):
                yield error

        if payment_method:
            for error in payment_method.get_unavailability_reasons(source=self):
                yield error

        for supplier in self._get_suppliers():
            for product, quantity in iteritems(self._get_products_and_quantities(supplier)):
                shop_product = product.get_shop_instance(shop=self.shop)
                if not shop_product:
                    yield ValidationError(
                        _("%s not available in this shop") % product.name,
                        code="product_not_available_in_shop"
                    )
                for error in shop_product.get_orderability_errors(
                        supplier=supplier, quantity=quantity, customer=self.customer):
                    error.message = "%s: %s" % (product.name, error.message)
                    yield error
开发者ID:gurch101,项目名称:shuup,代码行数:32,代码来源:_source.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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