本文整理汇总了Python中shuup.configuration.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.")
)
示例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"
示例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"
示例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")
示例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
示例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"
示例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"
示例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
示例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
示例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
示例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"
示例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"
示例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)
示例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}
)
示例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)